Skip to content

Create release

Create release #2

name: 'Create release'
on:
workflow_dispatch:
inputs:
releaseVersion:
description: 'Version de la release (semver)'
required: true
default: 'x.x.x'
snapshotVersion:
description: 'Version de la Snapshot (semver)'
required: true
default: 'x.x.x-SNAPSHOT'
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: 'Checkout source code'
uses: 'actions/checkout@v3'
with:
fetch-depth: '0' # to get all the tags locally
# https://stackoverflow.com/questions/67550727/push-event-doesnt-trigger-workflow-on-push-paths-github-actions
token: ${{ secrets.TOKEN_GITHUB_FOR_GITHUB_ACTION }}
- name: 'Verify release is created only on "main" or "master" git branch'
run: |
CURRENT_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo $CURRENT_GIT_BRANCH
[[ "$CURRENT_GIT_BRANCH" == "main" || "$CURRENT_GIT_BRANCH" == "master" ]] && exit 0 || exit 1
- name: 'Verify version is semver formatted (X.X.X)'
env:
NEW_TAG: ${{ github.event.inputs.releaseVersion }}
NEW_TAG_SNAPSHOT: ${{ github.event.inputs.snapshotVersion }}
run: |
echo $NEW_TAG | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$'
echo $NEW_TAG_SNAPSHOT | grep -E '^[0-9]+\.[0-9]+\.[0-9]+-SNAPSHOT$'
- name: 'Verify version is not already used as a git tag'
env:
NEW_TAG: ${{ github.event.inputs.releaseVersion }}
run: |
[[ "$(git tag --list | grep $NEW_TAG)" == "" ]] && exit 0 || exit 1
- name: 'Generate the new version (patch few files + git tag)'
env:
NEW_TAG: ${{ github.event.inputs.releaseVersion }}
NEW_TAG_SNAPSHOT: ${{ github.event.inputs.snapshotVersion }}
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB_FOR_GITHUB_ACTION }}
run: |
# préparation de la release qui va :
# - modifier le numéro de version dans les pom.xml du projet
# - créer un tag git du numéro de version en question
# - pousser le tout sur le dépôt github et faire la fusion avec la branche develop
git config --global user.email "github-action@noreply"
git config --global user.name "Github Action"
# patch la version dans les pom.xml avec xmllint
sudo apt-get install -y libxml2-utils
for POM_FILE in $(ls */pom.xml)
do
echo -e "setns x=http://maven.apache.org/POM/4.0.0\ncd /x:project/x:version\nset $NEW_TAG\nsave" \
| xmllint --shell $POM_FILE
done
# création du tag
git add .
git commit -m "Version $NEW_TAG"
git tag $NEW_TAG
git push origin $NEW_TAG
git commit --amend -m "Version $NEW_TAG [skip ci]"
git push
# merge la préparation de la nouvelle version sur develop
git switch develop
git merge main -m "Merge main to develop [skip ci]"
git push
# switch version to snapshot version
for POM_FILE in $(ls */pom.xml)
do
echo -e "setns x=http://maven.apache.org/POM/4.0.0\ncd /x:project/x:version\nset $NEW_TAG_SNAPSHOT\nsave" \
| xmllint --shell $POM_FILE
done
git add .
git commit -m "Version $NEW_TAG_SNAPSHOT [skip ci]"
git push
- name: 'Create the github release'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.inputs.releaseVersion }}
generate_release_notes: true
token: ${{ secrets.TOKEN_GITHUB_FOR_GITHUB_ACTION }}