The following is a quick recipe to use a Git tag as a release trigger using GitHub actions.
name: trigger
on:
push:
tags:
- release-*
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
with:
token: ${{ secrets.GIT_PASSWORD }}
- name: Release from given branch with given version
run: |
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
TAG=${GITHUB_REF}
RELEASE=${TAG%%-*}
CANDIDATE=${TAG:${#RELEASE}+1}
VERSION=${CANDIDATE#*-}
BRANCH=${CANDIDATE%-*}
echo "Releasing $VERSION from $BRANCH branch"
git checkout $BRANCH
git checkout -b release
mvn -B versions:set versions:commit -DnewVersion=$VERSION
git config --global user.email "noreply@noreply.com"
git config --global user.name "Automated release"
git commit -a -m "Releasing version $VERSION"
git tag v$VERSION -f
git push origin v$VERSION -f
git checkout $BRANCH
git branch -D release
git push origin :${TAG}
Adjust the username and the email address in the 2 git config commands. Add the GIT_PASSWORD secret as a secret to your GitHub account (note this should be a personal access token that is allowed to push to your GitHub repository).
Now you are ready to trigger a release pipeline by pushing a tag of the following format:
release-BRANCH-VERSION
Where BRANCH denotes the branch you want to release from and VERSION denotes you want to use for the release tag.
Posted June 23rd, 2021