[pull] develop from ehrbase:develop #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a Release | |
name: "Release" | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "Version to release, defaults to project.version" | |
required: false | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup - Java 21 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '21' | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# This will be used by git in all further steps | |
# We need a PERSONAL ACCESS TOKEN so pushes trigger other github actions | |
token: ${{ secrets.BOT_ACCESS_TOKEN }} | |
run: | | |
# Config git robot user | |
git config --global user.email "[email protected]" | |
git config --global user.name "bot" | |
# | |
# Uses the input version or read the version from the project pom | |
# | |
- name: Calculate Release Version | |
run: | | |
if [ -z "${{ github.event.inputs.version }}" ] | |
then | |
version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT//') | |
else | |
version=${{ github.event.inputs.version }} | |
fi | |
echo "Release version: ${version}" | |
# Set as Environment for all further steps | |
echo "VERSION=${version}" >> $GITHUB_ENV | |
# | |
# Uses the enforcer plugin to ensure no -SNAPSHOT version are used | |
# | |
- name: Enforce no SNAPSHOT used | |
run: | | |
mvn -P no-snapshots enforcer:enforce | |
# | |
# Create a new release branch and adjust the release version and changelog. | |
# | |
- name: Create Release Branch | |
run: | | |
# create branch | |
git checkout -b release/v${VERSION} | |
# Update version | |
mvn versions:set -DnewVersion=${VERSION} -DprocessAllModules=true | |
# Update Changelog | |
sed -i "s/\[unreleased\]/\[${VERSION}\]/" CHANGELOG.md | |
sed -i "s/...HEAD/\...v${VERSION}/" CHANGELOG.md | |
# | |
# Publish release branch | |
# | |
- name: Publish Release Branch | |
run: | | |
# commit & push | |
git add -A | |
git commit -m "release ${VERSION}: updated version to ${VERSION}" | |
git push -u origin release/v${VERSION} | |
# | |
# Wait for status of commit to change from pending | |
# | |
- name: Wait for CI pipeline | |
run: | | |
STATUS="pending" | |
# Get commit last commit of release branch | |
COMMIT=$(git rev-parse HEAD) | |
echo "Listen for commit $COMMIT" | |
WAITED="0" | |
# Time between calls | |
SLEEP_TIME="15" | |
while [ "$STATUS" == "pending" ] && [ "$WAITED" -le 1800 ] | |
do | |
sleep ${SLEEP_TIME} | |
WAITED=$((WAITED+SLEEP_TIME)) | |
STATUS=$(gh api /repos/${{ github.repository }}/commits/"${COMMIT}"/status -q .state) | |
echo "status : $STATUS" | |
echo "waited $WAITED s" | |
done | |
echo "status : $STATUS" | |
if [ "$STATUS" != "success" ] | |
then exit 1 | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }} | |
# | |
# In case the CI build was successful - we can merge everything back into the master branch | |
# | |
- name: Merge into Master | |
run: | | |
git checkout master | |
git pull | |
git merge --no-ff release/v${VERSION} | |
git tag -a -m "v${VERSION}" "v${VERSION}" | |
git push --follow-tags | |
# | |
# Create the actual github release for the version using the actual changelog | |
# | |
- name: Create Github Release | |
run: | | |
gh release create "v${VERSION}" -t "v${VERSION}" -F CHANGELOG.md -R ${{ github.repository }} --target master | |
env: | |
GITHUB_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }} | |
- name: Prepare next dev version | |
run: | | |
# increment minor version and add SNAPSHOT | |
ARRAY_VERSION=( ${VERSION//./ } ) | |
git checkout release/v${VERSION} | |
NEXT_VERSION=${ARRAY_VERSION[0]}.$((ARRAY_VERSION[1]+1)).0-SNAPSHOT | |
echo "next version: $NEXT_VERSION" | |
# update version | |
mvn versions:set -DnewVersion=${NEXT_VERSION} -DprocessAllModules=true | |
#edit changelog | |
sed -i '8i ## [unreleased]\n ### Added\n ### Changed \n ### Fixed \n' CHANGELOG.md | |
replace="$ a \[unreleased\]: https:\/\/github.com\/ehrbase\/ehrbase\/compare\/v$VERSION...HEAD" | |
sed -i "${replace}" CHANGELOG.md | |
- name: Merge into dev | |
run: | | |
git add -A | |
git commit -m " Updated version to ${NEXT_VERSION}" | |
git checkout develop | |
git pull | |
git merge --no-ff release/v${VERSION} | |
git push |