From 307f55572e7c5a9b5da402626200c3a31046c208 Mon Sep 17 00:00:00 2001 From: QuCMGisaia Date: Mon, 6 Jan 2025 15:44:34 +0100 Subject: [PATCH] ci: add release with github action --- .github/workflows/release.yml | 48 +++++++++++++++++++++++++++++++++++ release.sh | 48 +++++++++++++++++------------------ 2 files changed, 72 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..c9b3a05f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,48 @@ +name: Release ARLAS-wui + +on: + workflow_dispatch: + inputs: + version: + description: Version to release + required: true + stage: + type: choice + description: Stage of the release + required: true + options: + - beta + - rc + - stable + stage_iteration: + description: Iteration of the release (needed for beta and rc) + required: false + latest: + type: boolean + description: Latest release? + default: true + +run-name: Release ARLAS-wui ${{inputs.version}} ${{inputs.stage}} ${{inputs.stage_iteration}} + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.1.4 + with: + fetch-depth: 0 + - uses: actions/setup-node@v4 + with: + registry-url: 'https://registry.npmjs.org' + - name: Extract branch name + shell: bash + run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT + id: extract_branch + - name: Release + env: + # secrets are defined here : https://github.com/organizations/gisaia/settings/secrets/actions + NPM_EMAIL: ${{ secrets.NPM_EMAIL }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + GITHUB_CHANGELOG_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + bash release.sh -version=${{inputs.version}} -s=${{inputs.stage}} -i=${{inputs.stage_iteration}} -ref_branch=${{ steps.extract_branch.outputs.branch }} ${{inputs.latest && ' ' || '--not-latest'}} diff --git a/release.sh b/release.sh index 780af816..72eb511f 100755 --- a/release.sh +++ b/release.sh @@ -3,9 +3,6 @@ set -e SCRIPT_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd)" PROJECT_ROOT_DIRECTORY="$(dirname "$SCRIPT_DIRECTORY")" -# dockerlogin=`docker info | sed '/Username:/!d;s/.* //'` -# if [ -z "$dockerlogin" ] ; then echo "your are not logged on dockerhub"; exit -1; else echo "logged as "$dockerlogin ; fi - if [ -z "$GITHUB_CHANGELOG_TOKEN" ] ; then echo "Please set GITHUB_CHANGELOG_TOKEN environment variable"; exit -1; fi function clean { @@ -16,30 +13,27 @@ function clean { trap clean EXIT usage(){ - echo "Usage: ./release.sh -rel=X [--no-tests]" - echo " -rel|--app-release release arlas-app X version" - echo " -dev|--app-dev development arlas-app version (-SNAPSHOT qualifier will be automatically added)" - echo " --no-tests Skip running integration tests" - echo " --not-latest Doesn't tag the release version as the latest." - echo " -s|--stage Stage of the release : beta | rc | stable. If --stage is 'rc' or 'beta', there is no merge of develop into master (if -ref_branch=develop)" - echo " -i|--stage_iteration=n, the released version will be : [x].[y].[z]-beta.[n] OR [x].[y].[z]-rc.[n] according to the given --stage" - echo " -ref_branch | --reference_branch from which branch to start the release." + echo "Usage: ./release.sh -version=X [--no-tests]" + echo " -version Release ARLAS-wui X version" + echo " --no-tests Skip running integration tests" + echo " --not-latest Doesn't tag the release version as the latest." + echo " -s|--stage Stage of the release : beta | rc | stable. If --stage is 'rc' or 'beta', there is no merge of develop into master (if -ref_branch=develop)" + echo " -i|--stage_iteration=n The released version will be : [x].[y].[z]-beta.[n] OR [x].[y].[z]-rc.[n] according to the given --stage" + echo " -ref_branch|--reference_branch From which branch to start the release." echo " Add -ref_branch=develop for a new official release" echo " Add -ref_branch=x.x.x for a maintenance release" exit 1 } + STAGE="stable" TESTS="YES" IS_LATEST_VERSION="YES" + for i in "$@" do case $i in - -rel=*|--app-release=*) - APP_REL="${i#*=}" - shift # past argument=value - ;; - -dev=*|--app-dev=*) - APP_DEV="${i#*=}" + -version=*) + VERSION="${i#*=}" shift # past argument=value ;; --no-tests) @@ -68,9 +62,6 @@ case $i in esac done -VERSION="${APP_REL}" -DEV="${APP_DEV}" - if [ "$TESTS" == "YES" ]; then ng lint ng test @@ -135,7 +126,7 @@ git pull origin "$REF_BRANCH" if [ "${STAGE}" == "rc" ] || [ "${STAGE}" == "beta" ]; then - VERSION="${APP_REL}-${STAGE}.${STAGE_ITERATION}" + VERSION="${VERSION}-${STAGE}.${STAGE_ITERATION}" fi echo "==> Set version" @@ -174,10 +165,12 @@ echo "==> Docker" docker build -f docker/Dockerfile-production --no-cache --build-arg version=${VERSION} --tag gisaia/arlas-wui:${VERSION} . docker build -f docker/Dockerfile-production-no-analytics --no-cache --build-arg version=${VERSION} --tag gisaia/arlas-wui:${VERSION}-no-analytics . +echo " -- Publishing docker images" docker push gisaia/arlas-wui:${VERSION} docker push gisaia/arlas-wui:${VERSION}-no-analytics if [ "${STAGE}" == "stable" ] && [ "${IS_LATEST_VERSION}" == "YES" ]; then + echo " -- Publishing latest" docker tag gisaia/arlas-wui:${VERSION} gisaia/arlas-wui:latest docker push gisaia/arlas-wui:latest fi @@ -193,6 +186,7 @@ if [ "${STAGE}" == "rc" ] || [ "${STAGE}" == "beta" ]; echo " -- tagged as ${STAGE}" npm publish --tag=${STAGE} else + echo " -- Stable release" npm publish fi cd ../.. @@ -214,10 +208,16 @@ if [ "${REF_BRANCH}" == "develop" ] && [ "${STAGE}" == "stable" ]; git rebase origin/master fi -npm --no-git-tag-version version "${DEV}-dev" -npm --no-git-tag-version --prefix src version "${DEV}-dev" +IFS='.' read -ra TAB <<< "$VERSION" +major=${TAB[0]} +minor=${TAB[1]} +newminor=$(( $minor + 1 )) +newDevVersion=${major}.${newminor}.0 + +npm --no-git-tag-version version "${newDevVersion}-dev" +npm --no-git-tag-version --prefix src version "${newDevVersion}-dev" -git commit -a -m "development version ${DEV}-dev" +git commit -a -m "development version ${newDevVersion}-dev" git push origin ${REF_BRANCH} echo "==> Well done :)"