Skip to content

Publish package to Maven and GitHub #14

Publish package to Maven and GitHub

Publish package to Maven and GitHub #14

Workflow file for this run

name: Publish package to Maven and GitHub
on:
workflow_dispatch:
env:
JAVA_VERSION: '21'
DISTRIBUTION: 'temurin'
jobs:
# Publish to Maven Central
publish-maven-central:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# Check out the repository code
- uses: actions/checkout@v4
# Set up Maven Central Repository with GPG signing
- name: ☕ Set up Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.DISTRIBUTION }}
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.GPG_SIGNING_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
# Publish package using the 'release' profile to exclude 'universal-coverage'
- name: 📦 Publish package
run: mvn -P central -B deploy
env:
MAVEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}
# Publish to GitHub Packages Apache Maven
publish-github-packages:
# Wait until publication is done at Maven Central, before creating the release at Github
needs: publish-maven-central
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
outputs:
version: ${{ steps.latest-tag.outputs.tag }}
steps:
# Check out the repository code
- uses: actions/checkout@v4
# Set up
- name: ☕ Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.DISTRIBUTION }}
server-id: github
# Publish package using the 'release' profile to exclude 'universal-coverage'
- name: 📦 Publish package
run: mvn -P github -B deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Push tags and files
- name: 📤 Push tags and files
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git push && git push --tags
# Get the latest tag
- name: 🔍 Get the latest tag
id: latest-tag
uses: WyriHaximus/[email protected]
# Create GitHub Release
create-github-release:
needs: publish-github-packages
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# Use the latest pushed tag
- name: ✨ Create GitHub Release
uses: ncipollo/[email protected]
with:
generateReleaseNotes: true
tag: ${{ needs.publish-github-packages.outputs.version }}
commit: main