Commit 8e7d76e1 authored by LAVENIER's avatar LAVENIER
Browse files

[fix] Fix release scripts (add artifacts upload to github)

parent c38bd4a5
...@@ -8,31 +8,23 @@ if [[ "_" == "_${PROJECT_DIR}" ]]; then ...@@ -8,31 +8,23 @@ if [[ "_" == "_${PROJECT_DIR}" ]]; then
fi; fi;
cd ${PROJECT_DIR} cd ${PROJECT_DIR}
### Control that the script is run on `dev` branch
branch=`git rev-parse --abbrev-ref HEAD`
if [[ ! "$branch" = "release/$version" ]];
then
echo ">> This script must be run under a release branch (release/$version)"
exit 1
fi
### Variables ### Variables
task=$1 task=$1
version=$2 release_description=$2
release_description=$3
PROJECT_NAME=sumaris-pod PROJECT_NAME=sumaris-pod
REPO="sumaris-net/sumaris-pod" REPO="sumaris-net/sumaris-pod"
REPO_API_URL=https://api.github.com/repos/$REPO REPO_API_URL=https://api.github.com/repos/$REPO
REPO_PUBLIC_URL=https://github.com/$REPO REPO_PUBLIC_URL=https://github.com/$REPO
### Get version to release ### Get version to release
current=`grep -m1 -P "\<version>[0-9A−Z.]+(-\w*)?</version>" pom.xml | grep -oP "\d+.\d+.\d+(-\w*)?"` version=`grep -m1 -P "\<version>[0-9A−Z.]+(-\w*)?</version>" pom.xml | grep -oP "\d+.\d+.\d+(-\w*)?"`
if [[ "_$current" == "_" ]]; then if [[ "_$version" == "_" ]]; then
echo "ERROR: Unable to read 'version' in the file 'pom.xml'." echo "ERROR: Unable to read 'version' in the file 'pom.xml'."
echo " - Make sure the file 'pom.xml' exists and is readable." echo " - Make sure the file 'pom.xml' exists and is readable."
exit 1 exit 1
fi fi
echo "Current version: $current" echo "Project version (pom.xml): $version"
### get auth token ### get auth token
if [[ "_${GITHUB_TOKEN}" == "_" ]]; then if [[ "_${GITHUB_TOKEN}" == "_" ]]; then
...@@ -51,7 +43,7 @@ fi ...@@ -51,7 +43,7 @@ fi
case "$task" in case "$task" in
del) del)
result=`curl -i "$REPO_API_URL/releases/tags/$current"` result=`curl -i "$REPO_API_URL/releases/tags/$version"`
release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "$REPO_API_URL/releases/\d+"` release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "$REPO_API_URL/releases/\d+"`
if [[ $release_url != "" ]]; then if [[ $release_url != "" ]]; then
echo "Deleting existing release..." echo "Deleting existing release..."
...@@ -61,6 +53,15 @@ case "$task" in ...@@ -61,6 +53,15 @@ case "$task" in
pre|rel) pre|rel)
### Control that the script is run on `dev` branch
branch=`git rev-parse --abbrev-ref HEAD`
echo "GIT branch: $branch"
if [[ ! "$branch" = "release/$version" ]];
then
echo ">> This script must be run under a release branch (release/$version)"
exit 1
fi
if [[ $1 = "pre" ]]; then if [[ $1 = "pre" ]]; then
prerelease="true" prerelease="true"
else else
...@@ -69,10 +70,10 @@ case "$task" in ...@@ -69,10 +70,10 @@ case "$task" in
description=`echo $release_description` description=`echo $release_description`
if [[ "_$description" = "_" ]]; then if [[ "_$description" = "_" ]]; then
description="Release $current" description="Release $version"
fi fi
result=`curl -s -H ''"$GITHUT_AUTH"'' "$REPO_API_URL/releases/tags/$current"` result=`curl -s -H ''"$GITHUT_AUTH"'' "$REPO_API_URL/releases/tags/$version"`
release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+/releases/\d+"` release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+/releases/\d+"`
if [[ "_$release_url" != "_" ]]; then if [[ "_$release_url" != "_" ]]; then
echo "Deleting existing release... $release_url" echo "Deleting existing release... $release_url"
...@@ -87,9 +88,9 @@ case "$task" in ...@@ -87,9 +88,9 @@ case "$task" in
fi fi
echo "Creating new release..." echo "Creating new release..."
echo " - tag: $current" echo " - tag: $version"
echo " - description: $description" echo " - description: $description"
result=`curl -H ''"$GITHUT_AUTH"'' -s $REPO_API_URL/releases -d '{"tag_name": "'"$current"'","target_commitish": "master","name": "'"$current"'","body": "'"$description"'","draft": false,"prerelease": '"$prerelease"'}'` result=`curl -H ''"$GITHUT_AUTH"'' -s $REPO_API_URL/releases -d '{"tag_name": "'"$version"'","target_commitish": "master","name": "'"$version"'","body": "'"$description"'","draft": false,"prerelease": '"$prerelease"'}'`
upload_url=`echo "$result" | grep -P "\"upload_url\": \"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+"` upload_url=`echo "$result" | grep -P "\"upload_url\": \"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+"`
if [[ "_$upload_url" = "_" ]]; then if [[ "_$upload_url" = "_" ]]; then
...@@ -102,12 +103,12 @@ case "$task" in ...@@ -102,12 +103,12 @@ case "$task" in
### Sending files ### Sending files
echo "Uploading files to $upload_url ..." echo "Uploading files to $upload_url ..."
WAR_FILE="${PROJECT_DIR}/sumaris-server/target/sumaris-server-$current.war" WAR_FILE="${PROJECT_DIR}/sumaris-server/target/sumaris-server-$version.war"
if [[ ! -f "${WAR_FILE}" ]]; then if [[ ! -f "${WAR_FILE}" ]]; then
echo "ERROR: Missing WAR artifact: ${WAR_FILE}. Skipping upload" echo "ERROR: Missing WAR artifact: ${WAR_FILE}. Skipping upload"
missing_file=true missing_file=true
else else
artifact_name="sumaris-pod-$current.war" artifact_name="sumaris-pod-$version.war"
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${WAR_FILE}" "${upload_url}?name=${artifact_name}") result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${WAR_FILE}" "${upload_url}?name=${artifact_name}")
browser_download_url=`echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+"` browser_download_url=`echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+"`
SHA256=$(sha256sum "${WAR_FILE}" | sed 's/ /\n/gi' | head -n 1) SHA256=$(sha256sum "${WAR_FILE}" | sed 's/ /\n/gi' | head -n 1)
...@@ -117,12 +118,12 @@ case "$task" in ...@@ -117,12 +118,12 @@ case "$task" in
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: text/plain' -T "${WAR_FILE}.sha256" "${upload_url}?name=${artifact_name}.sha256") result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: text/plain' -T "${WAR_FILE}.sha256" "${upload_url}?name=${artifact_name}.sha256")
fi fi
ZIP_FILE="${PROJECT_DIR}/sumaris-server/target/sumaris-server-$current-standalone.zip" ZIP_FILE="${PROJECT_DIR}/sumaris-server/target/sumaris-server-$version-standalone.zip"
if [[ ! -f "${ZIP_FILE}" ]]; then if [[ ! -f "${ZIP_FILE}" ]]; then
echo "ERROR: Missing ZIP artifact: ${ZIP_FILE}. Skipping upload" echo "ERROR: Missing ZIP artifact: ${ZIP_FILE}. Skipping upload"
missing_file=true missing_file=true
else else
artifact_name="sumaris-pod-$current.zip" artifact_name="sumaris-pod-$version.zip"
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${ZIP_FILE}" "${upload_url}?name=${ZIP_FILENAME}") result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${ZIP_FILE}" "${upload_url}?name=${ZIP_FILENAME}")
browser_download_url=`echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+"` browser_download_url=`echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+"`
SHA256=$(sha256sum "${ZIP_FILE}" | sed 's/ /\n/gi' | head -n 1) SHA256=$(sha256sum "${ZIP_FILE}" | sed 's/ /\n/gi' | head -n 1)
...@@ -132,12 +133,12 @@ case "$task" in ...@@ -132,12 +133,12 @@ case "$task" in
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: text/plain' -T "${ZIP_FILE}.sha256" "${upload_url}?name=${artifact_name}.sha256") result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: text/plain' -T "${ZIP_FILE}.sha256" "${upload_url}?name=${artifact_name}.sha256")
fi fi
DB_FILE="${PROJECT_DIR}/sumaris-core/target/sumaris-db-$current.zip" DB_FILE="${PROJECT_DIR}/sumaris-core/target/sumaris-db-$version.zip"
if [[ ! -f "${DB_FILE}" ]]; then if [[ ! -f "${DB_FILE}" ]]; then
echo "ERROR: Missing DB ZIP artifact: ${DB_FILE}. Skipping uppload" echo "ERROR: Missing DB ZIP artifact: ${DB_FILE}. Skipping uppload"
missing_file=true missing_file=true
else else
artifact_name="sumaris-db-$current.zip" artifact_name="sumaris-db-$version.zip"
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${DB_FILE}" "${upload_url}?name=${artifact_name}") result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${DB_FILE}" "${upload_url}?name=${artifact_name}")
browser_download_url=`echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+"` browser_download_url=`echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+"`
SHA256=$(sha256sum "${DB_FILE}" | sed 's/ /\n/gi' | head -n 1) SHA256=$(sha256sum "${DB_FILE}" | sed 's/ /\n/gi' | head -n 1)
...@@ -150,13 +151,13 @@ case "$task" in ...@@ -150,13 +151,13 @@ case "$task" in
if [[ ${missing_file} == true ]]; then if [[ ${missing_file} == true ]]; then
echo "-----------------------------------------" echo "-----------------------------------------"
echo "ERROR: missing some artifacts (see logs)" echo "ERROR: missing some artifacts (see logs)"
echo " -> Release url: ${REPO_PUBLIC_URL}/releases/tag/${current}" echo " -> Release url: ${REPO_PUBLIC_URL}/releases/tag/${version}"
# Continue if error # Continue if error
exit 1 exit 1
else else
echo "-----------------------------------------" echo "-----------------------------------------"
echo "Successfully uploading files !" echo "Successfully uploading files !"
echo " -> Release url: ${REPO_PUBLIC_URL}/releases/tag/${current}" echo " -> Release url: ${REPO_PUBLIC_URL}/releases/tag/${version}"
exit 0 exit 0
fi fi
......
...@@ -33,7 +33,7 @@ if [[ ! $task =~ ^(pre|rel)$ || ! $version =~ ^[0-9]+.[0-9]+.[0-9]+(-(alpha|beta ...@@ -33,7 +33,7 @@ if [[ ! $task =~ ^(pre|rel)$ || ! $version =~ ^[0-9]+.[0-9]+.[0-9]+(-(alpha|beta
exit 1 exit 1
fi fi
echo "---- Starting release $version ($task)"... echo "---- Creating release $version ($task)"...
echo "" echo ""
# Removing existing release branche # Removing existing release branche
...@@ -79,6 +79,17 @@ git branch -d "release/$version" ...@@ -79,6 +79,17 @@ git branch -d "release/$version"
echo "---- Push changes to upstream [OK]" echo "---- Push changes to upstream [OK]"
echo "" echo ""
# Uploading artifacts to Github
echo "---- Uploading artifacts to Github..."
# Pause (wait propagation to from gitlab to github)
echo " Waiting 40s, for propagation to github..." && sleep 40s
. ${PROJECT_DIR}/src/scripts/release-to-github.sh $task ''"$release_description"''
[[ $? -ne 0 ]] && exit 1
echo "---- Uploading artifacts to Github [OK]"
echo ""
echo "----------------------------------" echo "----------------------------------"
echo "RELEASE finished!" echo "RELEASE finished!"
echo "----------------------------------" echo "----------------------------------"
...@@ -148,7 +148,7 @@ To change the Pod's configuration, follow this steps: ...@@ -148,7 +148,7 @@ To change the Pod's configuration, follow this steps:
Your configuration file should have been processed. Your configuration file should have been processed.
## Build from source (database + Pod) ## Build from source
1. Installe project dependencies: 1. Installe project dependencies:
* Install build tools (Make, GCC, Git) * Install build tools (Make, GCC, Git)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment