Skip to content

Commit

Permalink
ci: add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbousquet committed Sep 27, 2024
1 parent 1df92b1 commit a548d1b
Show file tree
Hide file tree
Showing 2 changed files with 232 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Release ARLAS-web-core

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


jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- 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-actions.sh -version=${{inputs.version}} -s=${{inputs.stage}} -i=${{inputs.stage_iteration}} -ref_branch=${{ steps.extract_branch.outputs.branch }}
194 changes: 194 additions & 0 deletions release-actions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
#!/bin/bash
set -e

npmlogin=`npm whoami`
if [ -z "$npmlogin" ] ; then echo "your are not logged on npm"; exit -1; else echo "logged as "$npmlogin ; fi

usage(){
echo "Usage: ./release.sh -version='1.0.0' -ref_branch=develop --stage=beta|rc|stable"
echo " -version arlas-web-core version release,level of evolution"
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
}


# ARGUMENTS $1 = VERSION $2 = ref_branch $3 stage $4 stage iteration (for beta & rc)
releaseProd(){

local VERSION=$1
local BRANCH=$2
local STAGE_LOCAL=$3
local STAGE_ITERATION_LOCAL=$4

if [ "${STAGE_LOCAL}" == "rc" ] || [ "${STAGE_LOCAL}" == "beta" ];
then
local VERSION="${VERSION}-${STAGE_LOCAL}.${STAGE_ITERATION_LOCAL}"
fi

echo "=> Get "$BRANCH" branch of ARLAS-web-core project"
git checkout "$BRANCH"
git pull origin "$BRANCH"
echo "=> Test to lint and build the project on "$BRANCH" branch"
npm --no-git-tag-version version ${VERSION}

echo "=> Build the ARLAS-web-core library"
npm install
npm run lint
npm run build-release

echo "=> Tag version $VERSION"
git add .
commit_message_release="Release prod version $VERSION"
git tag -a v"$VERSION" -m "$commit_message_release"
git push origin v"$VERSION"

echo "=> Generate CHANGELOG"
docker run -it --rm -v "$(pwd)":/usr/local/src/your-app gisaia/github-changelog-generator:latest github_changelog_generator \
-u gisaia -p ARLAS-web-core --token ${GITHUB_CHANGELOG_TOKEN} --no-pr-wo-labels --no-issues-wo-labels --no-unreleased \
--issue-line-labels conf,documentation,CI,ALL,DONUT,RESULTLIST,POWERBARS,HISTOGRAM,MAP \
--exclude-labels type:duplicate,type:question,type:wontfix,type:invalid \
--bug-labels type:bug --enhancement-labels type:enhancement --breaking-labels type:breaking \
--enhancement-label "**New stuff:**" --issues-label "**Miscellaneous:**" \
--exclude-tags v3.1.2 --since-tag v4.0.0

echo " -- Remove tag to add generated CHANGELOG"
git tag -d v"$VERSION"
git push origin :v"$VERSION"

echo " -- Commit release version"
git commit -a -m "$commit_message_release" --allow-empty
git tag v"$VERSION"
git push origin v"$VERSION"
git push origin "$BRANCH"

cp README-NPM.md dist/README.md
cp LICENSE.txt dist/LICENSE
cp package-release.json dist/package.json
npm --no-git-tag-version --prefix dist version ${VERSION}
cd dist

echo "=> Publish to npm"
if [ "${STAGE_LOCAL}" == "rc" ] || [ "${STAGE_LOCAL}" == "beta" ];
then
echo " -- tagged as ${STAGE_LOCAL}"
npm publish --tag=${STAGE_LOCAL}
else
npm publish
fi
cd ..
rm -rf dist
if [ "$BRANCH" == "develop" ] && [ "$STAGE_LOCAL" == "stable" ];
then
echo "=> Merge develop into master"
git checkout master
git pull origin master
git merge origin/develop
git push origin master

git checkout develop
git pull origin develop
git rebase origin/master
fi
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"-dev0"
git add .
commit_message="update package.json to"-"$newDevVersion"
git commit -m "$commit_message" --allow-empty
git push origin "$BRANCH"
echo "Well done :)"

}

# ARGUMENTS $1 = VERSION $2 = patch/minor/major $3 = PROJECT $4 ref_branch $5 is beta $6 stage_iteration
# ARGUMENTS $1 = VERSION $2 = ref_branch $3 stage $4 stage iteration (for beta & rc)
release(){
releaseProd $1 $2 $3 $4
}
STAGE="stable"
for i in "$@"
do
case $i in
-version=*)
RELEASE_VERSION="${i#*=}"
shift # past argument=value
;;
-ref_branch=*)
REF_BRANCH="${i#*=}"
shift # past argument=value
;;
-s=*)
STAGE="${i#*=}"
shift # past argument=value
;;
-i=*)
STAGE_ITERATION="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done

if [ -z ${REF_BRANCH+x} ];
then
echo ""
echo "###########"
echo "-ref_branch is missing."
echo " Add -ref_branch=develop for a new official release"
echo " Add -ref_branch=x.x.x for a maintenance release"
echo "###########"
echo ""
usage;
fi

if [ -z ${STAGE+x} ];
then
echo ""
echo "###########"
echo "-s=*|--stage* is missing."
echo " Add --stage=beta|rc|stable to define the release stage"
echo "###########"
echo ""
usage;
fi

if [ "${STAGE}" != "beta" ] && [ "${STAGE}" != "rc" ] && [ "${STAGE}" != "stable" ];
then
echo ""
echo "###########"
echo "Stage ${STAGE} is invalid."
echo " Add --stage=beta|rc|stable to define the release stage"
echo "###########"
echo ""
usage;
fi

if [ "${STAGE}" == "beta" ] || [ "${STAGE}" == "rc" ];
then
if [ -z ${STAGE_ITERATION+x} ];
then
echo ""
echo "###########"
echo "You chose to release this version as ${STAGE}."
echo "--stage_iteration is missing."
echo " Add -i=n|--stage_iteration=n, the released version will be : [x].[y].[z]-${STAGE}.[n]"
echo "###########"
echo ""
usage;
fi
fi

if [ ! -z ${RELEASE_VERSION+x} ];
then
echo "Release ARLAS-web-core version : ${RELEASE_VERSION}";
release ${RELEASE_VERSION} ${REF_BRANCH} ${STAGE} ${STAGE_ITERATION}
fi

0 comments on commit a548d1b

Please sign in to comment.