Skip to content
Snippets Groups Projects
Commit 1d4bc678 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[fix] Release: push force

parent 74002957
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
SCRIPT_DIR=$(dirname $0)
PROJECT_DIR=$(cd ${SCRIPT_DIR}/.. && pwd)
export PROJECT_DIR
fi;
cd ${PROJECT_DIR}
# Preparing the environment
. ${PROJECT_DIR}/scripts/env-global.sh
if [[ $? -ne 0 ]]; then
exit 1
fi
# Commit android project
cd ${PROJECT_DIR}/platforms/android || exit 1
git reset HEAD
git add -A
git commit -m "v$1"
git tag -f -a "v$1" -m "Release v$1"
# Push the tag
git push -f origin "v$1"
# Push the master branch
git push -f origin
if [[ $? -ne 0 ]]; then
echo "ERROR: cannot push platform/android project ! Continue anyway..."
fi
......@@ -15,18 +15,48 @@ if [[ $? -ne 0 ]]; then
exit 1
fi
if [[ -d "${PROJECT_DIR}/dist/desktop" ]]; then
cd "${PROJECT_DIR}/dist/desktop"
# Fetch last updates
git fetch origin && git merge origin/master || exit 1
# Build desktop assets
./release.sh $1
if [[ $? -ne 0 ]]; then
exit 1
fi
else
### Control that the script is run on `dev` branch
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ ! "$branch" = "master" ]];
then
echo ">> This script must be run under \`master\` branch"
exit 1
fi
### Get version to release
current=$(grep -P "version\": \"\d+.\d+.\d+(\w*)" package.json | grep -m 1 -oP "\d+.\d+.\d+(\w*)")
if [[ "_$current" == "_" ]]; then
echo "Unable to read the current version in 'package.json'. Please check version format is: x.y.z (x and y should be an integer)."
exit 1;
fi
### Check submodule exists
if [[ ! -d "${PROJECT_DIR}/dist/desktop" ]]; then
echo "ERROR: dist/desktop not found -> Make sure git submodule has been init!"
exit 1
fi;
### Sign extension
case "$1" in
pre|rel)
echo "Building v$current desktop artifacts..."
;;
*)
echo "No task given"
echo "Usage:"
echo " > $0 pre|rel"
exit 1
;;
esac
cd "${PROJECT_DIR}/dist/desktop"
# Fetch last updates
git fetch origin && git merge origin/master || exit 1
# Build desktop assets
./release.sh $current
if [[ $? -ne 0 ]]; then
exit 1
fi
......@@ -38,6 +38,7 @@ else
exit 1
fi
### check arguments
case "$1" in
del)
result=$(curl -i "$REPO_API_URL/releases/tags/v$current")
......@@ -46,117 +47,106 @@ case "$1" in
echo "Deleting existing release..."
curl -H 'Authorization: token $GITHUB_TOKEN' -XDELETE $release_url
fi
exit 0;
;;
pre|rel)
if [[ "_$2" != "_" ]]; then
if [[ $1 = "pre" ]]; then
prerelease="true"
else
prerelease="false"
fi
description=$(echo $2)
if [[ "_$description" = "_" ]]; then
description="Release v$current"
fi
result=$(curl -s -H ''"$GITHUT_AUTH"'' "$REPO_API_URL/releases/tags/v$current")
release_url=$(echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+/releases/\d+")
if [[ "_$release_url" != "_" ]]; then
echo "Deleting existing release... $release_url"
result=$(curl -H ''"$GITHUT_AUTH"'' -s -XDELETE $release_url)
if [[ "_$result" != "_" ]]; then
error_message=$(echo "$result" | grep -P "\"message\": \"[^\"]+" | grep -oP ": \"[^\"]+\"")
echo "Delete existing release failed with error$error_message"
exit 1
fi
else
echo "Release not exists yet on github."
fi
echo "Creating new release..."
echo " - tag: v$current"
echo " - description: $description"
result=$(curl -H ''"$GITHUT_AUTH"'' -s $REPO_API_URL/releases -d '{"tag_name": "v'"$current"'","target_commitish": "master","name": "'"$current"'","body": "'"$description"'","draft": false,"prerelease": '"$prerelease"'}')
#echo "DEBUG - $result"
upload_url=$(echo "$result" | grep -P "\"upload_url\": \"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+")
if [[ "_$upload_url" = "_" ]]; then
echo "Failed to create new release for repo $REPO."
echo "Server response:"
echo "$result"
exit 1
fi
### Sending files
echo "Uploading artifacts to ${upload_url} ..."
dirname=$(pwd)
# Upload web file
WEB_BASENAME="${PROJECT_NAME}-v$current-web.zip"
WEB_FILE="${DIST_WEB}/${WEB_BASENAME}"
if [[ -f "${WEB_FILE}" ]]; then
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${WEB_FILE}" "${upload_url}?name=${WEB_BASENAME}")
browser_download_url=$(echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+")
WEB_FILE_SHA256=$(cd ${DIST_WEB} && sha256sum "${WEB_BASENAME}")
echo " - ${browser_download_url} | Checksum: ${WEB_FILE_SHA256}"
else
echo " - ERROR: Web artifact (ZIP) not found! Skipping."
fi
# Upload web extension file
WEB_EXT_BASENAME="${PROJECT_NAME}-v$current-extension.zip"
WEB_EXT_FILE="${DIST_WEB}/${WEB_EXT_BASENAME}"
if [[ -f "${WEB_EXT_FILE}" ]]; then
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${WEB_EXT_FILE}" "${upload_url}?name=${WEB_EXT_BASENAME}")
browser_download_url=$(echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+")
WEB_EXT_FILE_SHA256=$(cd ${DIST_WEB} && sha256sum "${WEB_EXT_BASENAME}")
echo " - ${browser_download_url} | Checksum: ${WEB_EXT_FILE_SHA256}"
else
echo " - ERROR: Web extension artifact (ZIP) not found! Skipping."
fi
# Upload Android APK file
APK_BASENAME="${PROJECT_NAME}-v${current}-android.apk"
APK_FILE="${DIST_ANDROID}/${APK_BASENAME}"
if [[ -f "${APK_FILE}" ]]; then
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/vnd.android.package-archive' -T "${APK_FILE}" "${upload_url}?name=${APK_BASENAME}")
browser_download_url=$(echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+")
APK_FILE_SHA256=$(cd ${DIST_ANDROID} && sha256sum "${APK_BASENAME}")
echo " - ${browser_download_url} | Checksum: ${APK_FILE_SHA256}"
else
echo "- ERROR: Android artifact (APK) not found! Skipping."
fi
# Upload sha256 file (checksum)
SHA_BASENAME=${PROJECT_NAME}-v$current.sha256
SHA_FILE=${PROJECT_DIR}/dist/${SHA_BASENAME}
echo "${WEB_FILE_SHA256}" > ${SHA_FILE}
echo "${WEB_EXT_FILE_SHA256}" >> ${SHA_FILE}
echo "${APK_FILE_SHA256}" >> ${SHA_FILE}
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: text/plain' -T "${SHA_FILE}" "${upload_url}?name=${SHA_BASENAME}")
echo "-----------------------------------------"
echo "Successfully uploading files !"
echo " -> Release url: ${REPO_PUBLIC_URL}/releases/tag/v${current}"
exit 0
else
echo "Wrong arguments"
echo "Usage:"
echo " > $0 del|pre|rel <release_description>"
echo "With:"
echo " - del: delete existing release"
echo " - pre: use for pre-release"
echo " - rel: for full release"
exit 1
fi
pre)
prerelease="true"
echo "Creating new pre-release v$current..."
;;
rel)
prerelease="false"
echo "Creating new release v$current..."
;;
*)
echo "No task given"
echo "No task given, or wrong arguments"
echo "Usage:"
echo " > $0 del|pre|rel <release_description>"
echo " > $0 del|pre|rel <release_description>"
echo "With:"
echo " - del: delete existing release"
echo " - pre: use for pre-release"
echo " - rel: for full release"
exit 1
;;
esac
description=$(echo $2)
if [[ "_$description" = "_" ]]; then
description="Release v$current"
fi
result=$(curl -s -H ''"$GITHUT_AUTH"'' "$REPO_API_URL/releases/tags/v$current")
release_url=$(echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+/releases/\d+")
if [[ "_$release_url" != "_" ]]; then
echo "Deleting existing release... $release_url"
result=$(curl -H ''"$GITHUT_AUTH"'' -s -XDELETE $release_url)
if [[ "_$result" != "_" ]]; then
error_message=$(echo "$result" | grep -P "\"message\": \"[^\"]+" | grep -oP ": \"[^\"]+\"")
echo "Delete existing release failed with error$error_message"
exit 1
fi
else
echo "Release not exists yet on github."
fi
### Create the release
result=$(curl -H ''"$GITHUT_AUTH"'' -s $REPO_API_URL/releases -d '{"tag_name": "v'"$current"'","target_commitish": "master","name": "'"$current"'","body": "'"$description"'","draft": false,"prerelease": '"$prerelease"'}')
#echo "DEBUG - $result"
upload_url=$(echo "$result" | grep -P "\"upload_url\": \"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+")
if [[ "_$upload_url" = "_" ]]; then
echo "Failed to create new release for repo $REPO."
echo "Server response:"
echo "$result"
exit 1
fi
### Send files
echo "Uploading artifacts to ${upload_url} ..."
# Upload web file
WEB_BASENAME="${PROJECT_NAME}-v$current-web.zip"
WEB_FILE="${DIST_WEB}/${WEB_BASENAME}"
if [[ -f "${WEB_FILE}" ]]; then
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${WEB_FILE}" "${upload_url}?name=${WEB_BASENAME}")
browser_download_url=$(echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+")
WEB_FILE_SHA256=$(cd ${DIST_WEB} && sha256sum "${WEB_BASENAME}")
echo " - ${browser_download_url} | Checksum: ${WEB_FILE_SHA256}"
else
echo " - ERROR: Web artifact (ZIP) not found! Skipping."
fi
# Upload web extension file
WEB_EXT_BASENAME="${PROJECT_NAME}-v$current-extension.zip"
WEB_EXT_FILE="${DIST_WEB}/${WEB_EXT_BASENAME}"
if [[ -f "${WEB_EXT_FILE}" ]]; then
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${WEB_EXT_FILE}" "${upload_url}?name=${WEB_EXT_BASENAME}")
browser_download_url=$(echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+")
WEB_EXT_FILE_SHA256=$(cd ${DIST_WEB} && sha256sum "${WEB_EXT_BASENAME}")
echo " - ${browser_download_url} | Checksum: ${WEB_EXT_FILE_SHA256}"
else
echo " - ERROR: Web extension artifact (ZIP) not found! Skipping."
fi
# Upload Android APK file
APK_BASENAME="${PROJECT_NAME}-v${current}-android.apk"
APK_FILE="${DIST_ANDROID}/${APK_BASENAME}"
if [[ -f "${APK_FILE}" ]]; then
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/vnd.android.package-archive' -T "${APK_FILE}" "${upload_url}?name=${APK_BASENAME}")
browser_download_url=$(echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+")
APK_FILE_SHA256=$(cd ${DIST_ANDROID} && sha256sum "${APK_BASENAME}")
echo " - ${browser_download_url} | Checksum: ${APK_FILE_SHA256}"
else
echo "- ERROR: Android artifact (APK) not found! Skipping."
fi
# Upload sha256 file (checksum)
SHA_BASENAME=${PROJECT_NAME}-v$current.sha256
SHA_FILE=${PROJECT_DIR}/dist/${SHA_BASENAME}
echo "${WEB_FILE_SHA256}" > ${SHA_FILE}
echo "${WEB_EXT_FILE_SHA256}" >> ${SHA_FILE}
echo "${APK_FILE_SHA256}" >> ${SHA_FILE}
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: text/plain' -T "${SHA_FILE}" "${upload_url}?name=${SHA_BASENAME}")
### Success message
echo "Successfully uploaded files to: ${REPO_PUBLIC_URL}/releases/tag/v${current}"
......@@ -144,9 +144,9 @@ fi
git commit -m "v$2"
git tag -f -a "v$2" -m "${description}"
# Push the tag
git push origin "v$2"
git push -f origin "v$2"
# Push the master branch
git push origin
git push -f origin
if [[ $? -ne 0 ]]; then
exit 1
fi
......@@ -161,7 +161,7 @@ echo "----------------------------------"
#fi
echo "----------------------------------"
echo "- Uploading artifacts to Gihub ..."
echo "- Uploading artifacts to Github ..."
echo "----------------------------------"
# Pause (wait propagation to from git.duniter.org to github)
echo " Waiting 40s, for propagation to github..." && sleep 40s
......@@ -173,7 +173,7 @@ fi
echo "----------------------------------"
echo "- Building desktop artifacts..."
echo "----------------------------------"
. ${PROJECT_DIR}/scripts/release-desktop.sh $2 ''"$description"''
. ${PROJECT_DIR}/scripts/release-desktop.sh $1 ''"$description"''
if [[ $? -ne 0 ]]; then
exit 1
fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment