[Release] Publish releases packages to Maven Central #11
Workflow file for this run
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: Publish packages to Maven Central | |
on: | |
release: | |
types: [created] # triggers on release creation | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Validate tag version format | |
run: | | |
# Fail if the release tag doesn't match x.x.x | |
if [[ ! "${{ github.event.release.tag_name }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "::error ::Invalid version format '${{ github.event.release.tag_name }}'. Must match x.x.x." | |
exit 1 | |
fi | |
- name: Set up Java | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '8' | |
distribution: 'temurin' | |
server-id: central-portal | |
server-username: MAVEN_USERNAME | |
server-password: MAVEN_PASSWORD | |
# import gpg | |
gpg-private-key: ${{ secrets.GPG_SIGNING_KEY }} | |
gpg-passphrase: MAVEN_GPG_PASSPHRASE | |
- name: Configure GPG for CI | |
run: | | |
mkdir -p ~/.gnupg | |
chmod 700 ~/.gnupg | |
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf | |
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf | |
echo "GPG_TTY=$(tty)" >> $GITHUB_ENV | |
- name: Test GPG signing | |
run: | | |
echo "test gpg" > test.txt | |
gpg -ab test.txt | |
gpg --verify test.txt.asc | |
rm test.txt test.asc | |
env: | |
GPG_TTY: ${{ env.GPG_TTY }} | |
- name: Set version | |
run: | | |
./mvnw versions:set -DnewVersion=${{ github.event.release.tag_name }} | |
- name: Publish package | |
run: | | |
./mvnw --batch-mode clean deploy \ | |
-Pcoding,publish-central -DskipTests --settings .mvn/settings.xml | |
env: | |
MAVEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} | |
MAVEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} | |
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }} | |
GPG_KEYID: ${{ secrets.GPG_KEYID }} | |
GPG_TTY: ${{ env.GPG_TTY }} |