Commit d35445dd authored by LAVENIER's avatar LAVENIER
Browse files

[enh] Add release bash scripts

parent 39d27c26
Pipeline #12824 canceled with stages
in 1 minute and 7 seconds
......@@ -12,12 +12,12 @@ log.txt
.vscode/
npm-debug.log*
.idea/
.sourcemaps/
.sass-cache/
.tmp/
.versions/
.local/**
.idea
.sourcemaps
.sass-cache
.tmp
.versions
.local
coverage/
dist/
node_modules/
......@@ -37,3 +37,4 @@ Thumbs.db
UserInterfaceState.xcuserstate
yarn.lock
resources/android/build/local
package-lock.json
#!/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;
echo "Preparing project environment..."
echo " - using Project dir: $PROJECT_DIR"
if [[ ! -f "${PROJECT_DIR}/package.json" ]]; then
echo "ERROR: Invalid project dir: file 'package.json' not found in ${PROJECT_DIR}"
echo " -> Make sure to run the script inside his directory, or export env variable 'PROJECT_DIR'"
exit 1
fi;
PROJECT_NAME=sar-app
OWNER=simm
REPO="${OWNER}/${PROJECT_NAME}"
REPO_API_URL="https://api.github.com/repos/${REPO}"
REPO_PUBLIC_URL="https://github.com/${REPO}"
NODE_VERSION=12
NODE_OPTIONS=--max-old-space-size=4096 # Avoid Javascript memory heap space
ANDROID_NDK_VERSION=21.0.6113669 # Should be compatible with 'cordova-sqlite-storage' plugin
ANDROID_SDK_VERSION=29.0.3
ANDROID_SDK_CLI_VERSION=6858069
ANDROID_SDK_ROOT="${HOME}/Android/Sdk"
ANDROID_ALTERNATIVE_SDK_ROOT=/usr/lib/android-sdk
ANDROID_SDK_CLI_ROOT=${ANDROID_SDK_ROOT}/cli
ANDROID_OUTPUT_APK_PREFIX=app
ANDROID_OUTPUT_APK=${PROJECT_DIR}/platforms/android/${ANDROID_OUTPUT_APK_PREFIX}/build/outputs/apk
ANDROID_OUTPUT_APK_DEBUG=${ANDROID_OUTPUT_APK}/debug
ANDROID_OUTPUT_APK_RELEASE=${ANDROID_OUTPUT_APK}/release
# /!\ WARN can be define in your <project>/.local/env.sh file
#JAVA_HOME=
GRADLE_VERSION=6.5.1
GRADLE_HOME=${HOME}/.gradle/${GRADLE_VERSION}
CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip
GRADLE_OPTS=-Dorg.gradle.jvmargs=-Xmx512m
# Override with a local file, if any
if [[ -f "${PROJECT_DIR}/.local/env.sh" ]]; then
echo "Loading environment variables from: '.local/env.sh'"
source ${PROJECT_DIR}/.local/env.sh
[[ $? -ne 0 ]] && exit 1
else
echo "No file '${PROJECT_DIR}/.local/env.sh' found. Will use defaults"
fi
# Checking Java installed
if [[ "_" == "_${JAVA_HOME}" ]]; then
JAVA_CMD=`which java`
if [[ "_" == "_${JAVA_CMD}" ]]; then
echo "ERROR: No Java installed. Please install java, or set env variable JAVA_HOME "
exit 1
fi
# Check the Java version
JAVA_VERSION=`java -version 2>&1 | egrep "(java|openjdk) version" | awk '{print $3}' | tr -d \"`
if [[ $? -ne 0 ]]; then
echo "No Java JRE 1.8 found in machine. This is required for Android artifacts."
exit 1
fi
JAVA_MAJOR_VERSION=`echo ${JAVA_VERSION} | awk '{split($0, array, ".")} END{print array[1]}'`
JAVA_MINOR_VERSION=`echo ${JAVA_VERSION} | awk '{split($0, array, ".")} END{print array[2]}'`
if [[ ${JAVA_MAJOR_VERSION} -ne 11 ]] || [[ ${JAVA_MINOR_VERSION} -ne 0 ]]; then
echo "Require a Java JRE in version 11.0, but found ${JAVA_VERSION}. You can override your default JAVA_HOME in '.local/env.sh'."
exit 1
fi
fi
# Check Android SDK root path
if [[ "_" == "_${ANDROID_SDK_ROOT}" || ! -d "${ANDROID_SDK_ROOT}" ]]; then
if [[ -d "${ANDROID_ALTERNATIVE_SDK_ROOT}" ]]; then
export ANDROID_SDK_ROOT="${ANDROID_ALTERNATIVE_SDK_ROOT}"
else
echo "ERROR: Please set env variable ANDROID_SDK_ROOT to an existing directory"
exit 1
fi
fi
# Add Java, Android SDK tools to path
PATH=${ANDROID_SDK_CLI_ROOT}/bin:${GRADLE_HOME}/bin:${JAVA_HOME}/bin$:$PATH
# Node JS (using nvm - Node Version Manager)
NVM_DIR="$HOME/.config/nvm"
if [[ ! -d "${NVM_DIR}" && -d "$HOME/.nvm" ]]; then
NVM_DIR="$HOME/.nvm" ## Try alternative path
fi
if [[ -d "${NVM_DIR}" ]]; then
# Load NVM
. ${NVM_DIR}/nvm.sh
# Switch to expected version
nvm use ${NODE_VERSION}
# Or install it
if [[ $? -ne 0 ]]; then
nvm install ${NODE_VERSION}
[[ $? -ne 0 ]] && exit 1
# Switch to expected version
nvm use ${NODE_VERSION}
[[ $? -ne 0 ]] && exit 1
fi
else
echo "nvm (Node version manager) not found (directory ${NVM_DIR} not found)."
echo "Please install nvm (see https://github.com/nvm-sh/nvm), then retry"
exit 1
fi
# Export useful variables
export PATH \
PROJECT_DIR \
JAVA_HOME \
NVM_DIR \
NODE_OPTIONS \
GRADLE_HOME \
GRADLE_OPTS \
ANDROID_SDK_ROOT \
ANDROID_SDK_CLI_ROOT \
CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL
# Install global dependencies
IONIC_PATH=`which ionic`
CORDOVA_PATH=`which cordova`
CORDOVA_RES_PATH=`which cordova-res`
NATIVE_RUN_PATH=`which native-run`
if [[ "_" == "_${IONIC_PATH}" || "_" == "_${CORDOVA_PATH}" || "_" == "_${CORDOVA_RES_PATH}" || "_" == "_${NATIVE_RUN_PATH}" ]]; then
echo "Installing global dependencies..."
npm install -g cordova cordova-res @ionic/cli native-run
[[ $? -ne 0 ]] && exit 1
fi
# Install project dependencies
if [[ ! -d "${PROJECT_DIR}/node_modules" ]]; then
echo "Installing project dependencies..."
cd ${PROJECT_DIR}
npm install
fi
#!/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}
# Read parameters
version=$1
release_description=$2
PROJECT_DIR=`pwd`
# Check version format
if [[ ! $version =~ ^[0-9]+.[0-9]+.[0-9]+(-(alpha|beta|rc)[0-9]+)?$ ]]; then
echo "Wrong version format"
echo "Usage:"
echo " > ./release-finish.sh <version> <release_description>"
echo "with:"
echo " - version: x.y.z"
echo " - release_description: a comment on release"
exit 1
fi
### Control that the script is run on `release` branch
branch=`git rev-parse --abbrev-ref HEAD`
if [[ ! "$branch" = "release/$version" ]]
then
echo ">> This script must be run under \`develop\` or \`release/$version\` branch"
exit 1
fi
description="echo $release_description"
if [[ "_$description" == "_" ]]; then
description="Release $version"
fi
cd $PROJECT_DIR
rm src/assets/i18n/*-${version}.json
git add package.json src/assets/manifest.json config.xml install.sh
git commit -m ''"$description"''
# finishing release with:
# -F: fetch master & develop before
# -m: use default message
# -p: push all tags after finish
git flow release finish -F -p "$version" -m ''"$description"''
#!/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;
# Preparing Android environment
cd ${PROJECT_DIR}
source ${PROJECT_DIR}/scripts/env-global.sh
### Variables
task=$1
release_description=$2
### Control that the script is run on `dev` branch
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ ! "$branch" = "master" ]] && [[ ! "$branch" = "develop" ]] && [[ ! "$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"
exit 1
fi
### Get version to release
version=$(grep -m1 -P "version\": \"\d+.\d+.\d+(-\w+[0-9]+)?" package.json | grep -oP "\d+.\d+.\d+(-\w+[0-9]+)?")
if [[ "_$version" == "_" ]]; then
echo "ERROR: Unable to read 'version' in the file 'package.json'."
echo " - Make sure the file 'package.json' exists and is readable."
echo " - Check version format is: x.y.z (x and y should be an integer)"
exit 1
fi
echo "Sending v$version extension to Github..."
### get auth token
if [[ "_${GITHUB_TOKEN}" == "_" ]]; then
# Get it from user config dir
GITHUB_TOKEN=$(cat ~/.config/${PROJECT_NAME}/.github)
fi
if [[ "_${GITHUB_TOKEN}" != "_" ]]; then
GITHUT_AUTH="Authorization: token ${GITHUB_TOKEN}"
else
echo "ERROR: Unable to find github authentication token file: "
echo " - You can create such a token at https://github.com/settings/tokens > 'Generate a new token'."
echo " - [if CI] Add a pipeline variable named 'GITHUB_TOKEN';"
echo " - [else] Or copy/paste the token into the file '~/.config/${PROJECT_NAME}/.github'."
exit 1
fi
### check arguments
case "$task" in
del)
result=`curl -i "$REPO_API_URL/releases/tags/$version"`
release_url=`echo "$result" | grep -P "\"url\": \"[^\"]+" | grep -oP "$REPO_API_URL/releases/\d+"`
if [[ $release_url != "" ]]; then
echo "Deleting existing release..."
curl -H ''"$GITHUT_AUTH"'' -XDELETE $release_url
fi
exit 0;
;;
pre|rel)
if [[ "${task}" = "pre" ]]; then
prerelease="true"
else
prerelease="false"
fi
description=`echo $release_description`
if [[ "_$description" = "_" ]]; then
description="Release $version"
fi
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+"`
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: $version"
echo " - description: $description"
result=`curl -X POST -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/.-]+"`
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 files to ${upload_url} ..."
DIRNAME=$(pwd)
ZIP_FILE="${DIRNAME}/dist/${PROJECT_NAME}.zip"
if [[ -f "${ZIP_FILE}" ]]; then
artifact_name="${PROJECT_NAME}-${version}-web.zip"
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${ZIP_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/.-]+")
ZIP_SHA256=$(sha256sum "${ZIP_FILE}" | sed 's/ /\n/gi' | head -n 1)
echo " - ${browser_download_url} | SHA256 Checksum: ${ZIP_SHA256}"
echo "${ZIP_SHA256} ${artifact_name}" > "${ZIP_FILE}.sha256"
result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: text/plain' -T "${ZIP_FILE}.sha256" "${upload_url}?name=${artifact_name}.sha256")
else
echo " - ERROR: Web release (ZIP) not found! Skipping."
missing_file=true
fi
# APK_FILE="${ANDROID_OUTPUT_APK_RELEASE}/${ANDROID_OUTPUT_APK_PREFIX}-release-signed.apk"
# if [[ -f "${APK_FILE}" ]]; then
# artifact_name="${PROJECT_NAME}-${version}-android.apk"
# result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/vnd.android.package-archive' -T "${APK_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/.-]+")
# APK_SHA256=$(sha256sum "${APK_FILE}" | sed 's/ /\n/gi' | head -n 1)
# echo " - ${browser_download_url} | SHA256 Checksum: ${APK_SHA256}"
# echo "${APK_SHA256} ${artifact_name}" > "${APK_FILE}.sha256"
# result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: text/plain' -T "${APK_FILE}.sha256" "${upload_url}?name=${artifact_name}.sha256")
# else
# echo "- ERROR: Android release (APK) not found! Skipping."
# missing_file=true
# fi
if [[ ${missing_file} == true ]]; then
echo "-----------------------------------------"
echo "ERROR: missing some artifacts (see logs)"
echo " -> Release url: ${REPO_PUBLIC_URL}/releases/tag/${version}"
exit 1
else
echo "-----------------------------------------"
echo "Successfully uploading files !"
echo " -> Release url: ${REPO_PUBLIC_URL}/releases/tag/${version}"
exit 0
fi
;;
*)
echo "Wrong arguments"
echo "Usage:"
echo " > ./release-to-github.sh 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
#!/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}
# Read parameters
task=$1
version=$2
release_description=$3
# Check version format
if [[ ! $task =~ ^(pre|rel)$ || ! $version =~ ^[0-9]+.[0-9]+.[0-9]+(-(alpha|beta|rc)[0-9]+)?$ ]]; then
echo "Wrong version format"
echo "Usage:"
echo " > $0 pre|rel <version> <release_description>"
echo "with:"
echo " - pre: use for pre-release"
echo " - rel: for full release"
echo " - version: x.y.z"
echo " - release_description: a comment on release"
exit 1
fi
### Control that the script is run on `dev` branch
resumeRelease=0
branch=`git rev-parse --abbrev-ref HEAD`
if [[ ! "$branch" = "develop" ]]
then
if [[ "$branch" = "release/$version" ]]
then
echo "Resuming release ..."
resumeRelease=1
else
echo ">> This script must be run under \`develop\` or \`release/$version\` branch"
exit 1
fi
fi
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]+)?"`
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
echo "Current version: $current"
echo "**********************************"
if [[ $resumeRelease = 0 ]]
then
echo "* Starting release..."
else
echo "* Resuming release..."
fi
echo "**********************************"
echo "* new build version: $version"
echo "**********************************"
if [[ $resumeRelease = 0 ]]
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
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]+)?"`
sed -i "s/ version=\"$currentConfigXmlVersion\"/ version=\"$version\"/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]+)?"`
sed -i "s/version\": \"$currentManifestJsonVersion\"/version\": \"$version\"/g" src/assets/manifest.json
# Bump the install.sh
sed -i "s/echo \".*\" #lastest/echo \"$version\" #lastest/g" install.sh
;;
*)
echo "No task given"
;;
esac
echo "----------------------------------"
echo "- Compiling sources..."
echo "----------------------------------"
npm run build.prod
[[ $? -ne 0 ]] && exit 1
echo "----------------------------------"
echo "- Creating web artifact..."
echo "----------------------------------"
mkdir -p "${PROJECT_DIR}/dist"
ZIP_FILE=${PROJECT_DIR}/dist/${PROJECT_NAME}.zip
if [[ -f "$ZIP_FILE" ]]; then
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"
exit 1
fi
description="$release_description"
if [[ "_$description" == "_" ]]; then
description="Release $version"
fi
echo "**********************************"
echo "* Finishing release"
echo "**********************************"
cd ${PROJECT_DIR}/scripts || exit 1
./release-finish.sh "$version" ''"$release_description"''
[[ $? -ne 0 ]] && exit 1
# Pause (if propagation is need between hosted git server and github)
sleep 40s
#echo "**********************************"
#echo "* Uploading artifacts to Github..."
#echo "**********************************"
#cd $PROJECT_DIR/scripts
#./release-to-github.sh "$task" ''"$description"''
#[[ $? -ne 0 ]] && exit 1
#echo "----------------------------------"
#echo "- Building desktop artifacts..."
#echo "----------------------------------"
#git submodule init
#git submodule sync
#git submodule update --remote --merge
#if [[ -d "$PROJECT_DIR/platforms/desktop" ]]; then
# cd platforms/desktop
# # Build desktop assets
# ./release.sh $version
# if [[ $? -ne 0 ]]; then
# exit 1
# fi
#else
# echo "WARN: platform/desktop not found -> Skipping desktop build!"
#fi;
echo "**********************************"
echo "* Build release succeed !"
echo "**********************************"
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