Commit 2ec7d84c authored by PECQUOT's avatar PECQUOT

update scripts

parent 62c17b50
#!/bin/bash
# LP 08/01/2020 : Gitlab ne prend pas encore en charge l'envoi de fichier sur une release,
# c'est dans leur tuyau : https://gitlab.com/gitlab-org/gitlab/-/issues/17838
# affaire à suivre !!
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
SCRIPT_DIR=$(dirname $0)
PROJECT_DIR=$(cd ${SCRIPT_DIR}/.. && pwd)
SCRIPT_DIR=$(dirname "$0")
PROJECT_DIR=$(cd "${SCRIPT_DIR}"/.. && pwd)
export PROJECT_DIR
fi;
task=$1
# Preparing environment
cd ${PROJECT_DIR}
source ${PROJECT_DIR}/scripts/env-global.sh
cd "${PROJECT_DIR}" || exit 1
source "${PROJECT_DIR}"/scripts/env-global.sh
### Control that the script is run on `dev` branch
branch=`git rev-parse --abbrev-ref HEAD`
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ ! "$branch" = "master" ]] && [[ ! "$branch" =~ ^release/[0-9]+.[0-9]+.[0-9]+(-(alpha|beta|rc)[0-9]+)?$ ]];
then
echo ">> This script must be run under \`master\` or a \`release\` branch"
......@@ -22,7 +26,7 @@ then
fi
### Get version to release
current=`grep -m1 -P "version\": \"\d+.\d+.\d+(-(\w+)[0-9]+)?" package.json | grep -oP "\d+.\d+.\d+(-(\w+)[0-9]+)?"`
current=$(grep -m1 -P "version\": \"\d+.\d+.\d+(-(\w+)[0-9]+)?" package.json | grep -oP "\d+.\d+.\d+(-(\w+)[0-9]+)?")
if [[ "_$current" == "_" ]]; then
echo "ERROR: Unable to read 'version' in the file 'package.json'."
echo " - Make sure the file 'package.json' exists and is readable."
......@@ -32,13 +36,13 @@ echo "Current version: $current"
### Get repo URL
PROJECT_NAME=quadrige3-app
REMOTE_URL=`git remote -v | grep -P "push" | grep -oP "(https:\/\/gitlab.ifremer.fr\/|git@gitlab.ifremer.fr:)[^ ]+"`
#REMOTE_URL=`git remote -v | grep -P "push" | grep -oP "(https:\/\/gitlab.ifremer.fr\/|git@gitlab.ifremer.fr:)[^ ]+"`
REPO="quadrige/quadrige3-app"
REPO_API_URL=https://gitlab.ifremer.fr/api/v4/projects/quadrige%2Fquadrige3-app
REPO_PUBLIC_URL=https://gitlab.ifremer.fr/$REPO
### get auth token
GITLAB_TOKEN=`cat ~/.config/${PROJECT_NAME}/.gitlab`
GITLAB_TOKEN=$(cat ~/.config/${PROJECT_NAME}/.gitlab)
if [[ "_$GITLAB_TOKEN" != "_" ]]; then
GITLAB_AUTH="Authorization: Bearer $GITLAB_TOKEN"
else
......@@ -50,7 +54,7 @@ fi
case "$task" in
del)
result=`curl --header ''"$GITLAB_AUTH"'' "$REPO_API_URL/releases/$current" -o /dev/null -s -w "%{http_code}\n"`
result=$(curl --header ''"$GITLAB_AUTH"'' "$REPO_API_URL/releases/$current" -o /dev/null -s -w "%{http_code}\n")
if [[ $result = 200 ]]; then
echo "Deleting existing release..."
curl --header ''"$GITLAB_AUTH"'' "$REPO_API_URL/releases/$current" --request DELETE
......@@ -65,18 +69,18 @@ case "$task" in
prerelease="false"
fi
description=`echo $2`
description=$2
if [[ "_$description" = "_" ]]; then
description="Release $current"
fi
result=`curl -s -H ''"$GITLAB_AUTH"'' "$REPO_API_URL/releases/tags/$current"`
release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+/releases/\d+"`
result=$(curl -s -H ''"$GITLAB_AUTH"'' "$REPO_API_URL/releases/tags/$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 ''"$GITLAB_AUTH"'' -s -XDELETE $release_url`
result=$(curl -H ''"$GITLAB_AUTH"'' -s -XDELETE "$release_url")
if [[ "_$result" != "_" ]]; then
error_message=`echo "$result" | grep -P "\"message\": \"[^\"]+" | grep -oP ": \"[^\"]+\""`
error_message=$(echo "$result" | grep -P "\"message\": \"[^\"]+" | grep -oP ": \"[^\"]+\"")
echo "Delete existing release failed with error $error_message"
exit 1
fi
......@@ -87,8 +91,8 @@ case "$task" in
echo "Creating new release..."
echo " - tag: $current"
echo " - description: $description"
result=`curl -H ''"$GITLAB_AUTH"'' -s $REPO_API_URL/releases -d '{"tag_name": "'"$current"'","target_commitish": "master","name": "'"$current"'","body": "'"$description"'","draft": false,"prerelease": '"$prerelease"'}'`
upload_url=`echo "$result" | grep -P "\"upload_url\": \"[^\"]+" | grep -oP "https://[A-Za-z0-9/.-]+"`
result=$(curl -H ''"$GITLAB_AUTH"'' -s $REPO_API_URL/releases -d '{"tag_name": "'"$current"'","target_commitish": "master","name": "'"$current"'","body": "'"$description"'","draft": false,"prerelease": '"$prerelease"'}')
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."
......
#!/bin/bash
# Get to the root project
if [[ "_" == "_${PROJECT_DIR}" ]]; then
SCRIPT_DIR=$(dirname $0)
SCRIPT_DIR=$(dirname "$0")
PROJECT_DIR=$(cd "${SCRIPT_DIR}/.." && pwd)
export PROJECT_DIR
fi;
......@@ -10,7 +10,7 @@ fi;
#. ${PROJECT_DIR}/scripts/env-android.sh
#[[ $? -ne 0 ]] && exit 1
cd ${PROJECT_DIR}
cd "${PROJECT_DIR}" || exit 1
# Read parameters
task=$1
......@@ -46,7 +46,7 @@ fi
### Control that the script is run on `dev` branch
resumeRelease=0
branch=`git rev-parse --abbrev-ref HEAD`
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ ! "$branch" = "develop" ]]
then
if [[ "$branch" = "release/$version" ]]
......@@ -59,10 +59,10 @@ then
fi
fi
PROJECT_DIR=`pwd`
PROJECT_DIR=$(pwd)
### Get current version (package.json)
current=`grep -oP "version\": \"\d+.\d+.\d+(-(alpha|beta|rc)[0-9]+)?" package.json | grep -m 1 -oP "\d+.\d+.\d+(-(alpha|beta|rc)[0-9]+)?"`
current=$(grep -oP "version\": \"\d+.\d+.\d+(-(alpha|beta|rc)[0-9]+)?" package.json | grep -m 1 -oP "\d+.\d+.\d+(-(alpha|beta|rc)[0-9]+)?")
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;
......@@ -94,20 +94,21 @@ then
read -r -p "Is these new versions correct ? [y/N] " response
response=${response,,} # tolower
[[ ! "$response" =~ ^(yes|y)$ ]] && exit 1
git flow release start "$version"
[[ $? -ne 0 ]] && exit 1
if ! git flow release start "$version"; then
exit 1
fi
fi
case "$task" in
rel|pre)
# Change the version in files: 'package.json' and 'config.xml'
sed -i "s/version\": \"$current\"/version\": \"$version\"/g" package.json
currentConfigXmlVersion=`grep -oP "version=\"\d+.\d+.\d+(-(alpha|beta|rc)[0-9]+)?\"" config.xml | grep -oP "\d+.\d+.\d+(-(alpha|beta|rc)[0-9]+)?"`
currentConfigXmlVersion=$(grep -oP "version=\"\d+.\d+.\d+(-(alpha|beta|rc)[0-9]+)?\"" config.xml | grep -oP "\d+.\d+.\d+(-(alpha|beta|rc)[0-9]+)?")
sed -i "s/ version=\"$currentConfigXmlVersion\"/ version=\"$version\"/g" config.xml
# sed -i "s/ android-versionCode=\"$currentAndroid\"/ android-versionCode=\"$androidVersion\"/g" config.xml
# Change version in file: 'src/assets/manifest.json'
currentManifestJsonVersion=`grep -oP "version\": \"\d+.\d+.\d+(-(alpha|beta|rc)[0-9]+)?\"" src/assets/manifest.json | grep -oP "\d+.\d+.\d+(-(alpha|beta|rc)[0-9]+)?"`
currentManifestJsonVersion=$(grep -oP "version\": \"\d+.\d+.\d+(-(alpha|beta|rc)[0-9]+)?\"" src/assets/manifest.json | grep -oP "\d+.\d+.\d+(-(alpha|beta|rc)[0-9]+)?")
sed -i "s/version\": \"$currentManifestJsonVersion\"/version\": \"$version\"/g" src/assets/manifest.json
# Bump the install.sh
......@@ -121,8 +122,9 @@ esac
echo "----------------------------------"
echo "- Compiling sources..."
echo "----------------------------------"
npm run build.prod
[[ $? -ne 0 ]] && exit 1
if ! npm run build.prod; then
exit 1
fi
echo "----------------------------------"
echo "- Creating web artifact..."
......@@ -130,12 +132,11 @@ echo "----------------------------------"
mkdir -p "${PROJECT_DIR}/dist"
ZIP_FILE=${PROJECT_DIR}/dist/${PROJECT_NAME}.zip
if [[ -f "$ZIP_FILE" ]]; then
rm $ZIP_FILE
rm "$ZIP_FILE"
fi
cd $PROJECT_DIR/www
zip -q -r $ZIP_FILE .
if [[ $? -ne 0 ]]; then
echo "Connot create the archive for the web artifact"
cd "$PROJECT_DIR"/www || exit 1
if ! zip -q -r "$ZIP_FILE" .; then
echo "Cannot create the archive for the web artifact"
exit 1
fi
......@@ -175,9 +176,10 @@ fi
echo "**********************************"
echo "* Uploading artifacts to Github..."
echo "**********************************"
cd $PROJECT_DIR/scripts
./release-to-gitlab.sh "$task" ''"$description"''
[[ $? -ne 0 ]] && exit 1
cd "$PROJECT_DIR"/scripts || exit 1
if ! ./release-to-gitlab.sh "$task" ''"$description"''; then
exit 1
fi
#echo "----------------------------------"
#echo "- Building desktop artifacts..."
......@@ -202,9 +204,11 @@ cd $PROJECT_DIR/scripts
echo "**********************************"
echo "* Finishing release"
echo "**********************************"
cd ${PROJECT_DIR}/scripts || exit 1
./release-finish.sh "$version" ''"$release_description"''
[[ $? -ne 0 ]] && exit 1
cd "${PROJECT_DIR}"/scripts || exit 1
if ! ./release-finish.sh "$version" ''"$release_description"'';
then
exit 1
fi
echo "**********************************"
echo "* Build release succeed !"
......
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