Add version tag #3
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
name: Add version tag | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
paths: # only add version tag if pom.xml has changed because it contains the version number | |
- pom.xml | |
jobs: | |
add-version-tag: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' # You can choose other distributions like 'zulu' or 'temurin' | |
java-version: '11' | |
- name: add version tag | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | |
git config --local user.email "[email protected]" | |
git config --local user.name "github-actions[bot]" | |
# Delete the local tag if it exists | |
git tag -d "v$VERSION" || true # Ignore if the tag doesn't exist | |
git tag -a "v$VERSION" -m "Tagging version $VERSION" | |
git push origin :refs/tags/v$VERSION || true # delete remote tag, if exists | |
git push origin "v$VERSION" # create remote tag | |
echo "### Version tag v$VERSION added" >> $GITHUB_STEP_SUMMARY | |
echo "The repository has been tagged with v$VERSION" >> $GITHUB_STEP_SUMMARY |