Workflow file for this run
This file contains hidden or 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 to Maven Central | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: Release version without v prefix (e.g. 1.0.2) | |
| required: true | |
| type: string | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Resolve version | |
| run: | | |
| if [ "${{ github.event_name }}" = "release" ]; then | |
| VERSION="${{ github.event.release.tag_name }}" | |
| else | |
| VERSION="${{ inputs.version }}" | |
| fi | |
| VERSION="${VERSION#v}" | |
| echo "Publishing version: $VERSION" | |
| echo "VERSION=$VERSION" >> "$GITHUB_ENV" | |
| - name: Set up Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| cache: maven | |
| - name: Configure Maven settings | |
| run: | | |
| mkdir -p ~/.m2 | |
| cat > ~/.m2/settings.xml <<EOF | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" | |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd"> | |
| <servers> | |
| <server> | |
| <id>central</id> | |
| <username>${MAVEN_USERNAME}</username> | |
| <password>${MAVEN_PASSWORD}</password> | |
| </server> | |
| </servers> | |
| </settings> | |
| EOF | |
| env: | |
| MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} | |
| MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} | |
| - name: Import GPG key | |
| run: | | |
| install -m 700 -d ~/.gnupg | |
| printf '%s\n' "$GPG_PRIVATE_KEY" | gpg --batch --import --yes --no-tty | |
| gpg --list-secret-keys --keyid-format long | |
| env: | |
| GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} | |
| - name: Set project version | |
| run: mvn --batch-mode versions:set -DnewVersion="$VERSION" -DgenerateBackupPoms=false | |
| - name: Publish to Maven Central | |
| run: mvn --batch-mode clean deploy -Prelease -DskipTests | |
| env: | |
| MAVEN_GPG_PASSPHRASE: "" |