Maven Publish #66
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
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created | |
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path | |
name: Maven Publish | |
on: | |
workflow_dispatch: | |
inputs: | |
releaseVersion: | |
description: 'Version de la release (semver)' | |
required: true | |
default: 'x.x.x' | |
jobs: | |
maven-publish: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
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 }} | |
run: | | |
echo $NEW_TAG | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | |
- 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 }} | |
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 | |
git config --global user.email "github-action@noreply" | |
git config --global user.name "Github Action" | |
mvn release:prepare \ | |
--batch-mode \ | |
-DreleaseVersion=$NEW_TAG \ | |
-Darguments=-DskipTests \ | |
-DtagNameFormat="@{project.version}" | |
# merge la préparation de la nouvelle version sur develop | |
# (version X.X.X-SNAPSHOT) | |
# CURRENT_GIT_BRANCH vaut main ou master, c'est la où est créé la release | |
CURRENT_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
git switch develop | |
git merge $CURRENT_GIT_BRANCH | |
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 }} | |
- name: Set up Maven Central Repository | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
server-id: ossrh | |
server-username: MAVEN_USERNAME | |
server-password: MAVEN_PASSWORD | |
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} | |
gpg-passphrase: MAVEN_GPG_PASSPHRASE | |
- name: Deploy with Maven | |
run: mvn -B release:perform -PtoOSSRH | |
env: | |
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} | |
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} | |
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} |