|
| 1 | +# Tag-Triggered Maven Central Release (GitHub Actions) |
| 2 | + |
| 3 | +- Trigger: push tag `releases/X.Y.Z` (no leading `v`). |
| 4 | +- CI creates a GitHub Release from the tag, then deploys to Maven Central. |
| 5 | +- CI opens a PR back to `main` from `release-bot-YYYYMMDD-HHMMSS` (no version bumps). |
| 6 | + |
| 7 | +## Workflow (drop-in) |
| 8 | + |
| 9 | +```yaml |
| 10 | +name: Release on Tag |
| 11 | +on: |
| 12 | + push: |
| 13 | + tags: |
| 14 | + - 'releases/*' |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | +jobs: |
| 19 | + release: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + with: { fetch-depth: 0 } |
| 24 | + - uses: actions/setup-java@v4 |
| 25 | + with: |
| 26 | + distribution: temurin |
| 27 | + java-version: '21' |
| 28 | + cache: maven |
| 29 | + server-id: central |
| 30 | + server-username: CENTRAL_USERNAME |
| 31 | + server-password: CENTRAL_PASSWORD |
| 32 | + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} |
| 33 | + gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} |
| 34 | + - uses: softprops/action-gh-release@v2 |
| 35 | + with: |
| 36 | + tag_name: ${{ github.ref_name }} |
| 37 | + generate_release_notes: true |
| 38 | + - name: Build and Deploy to Central |
| 39 | + env: |
| 40 | + CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }} |
| 41 | + CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }} |
| 42 | + run: mvn -B -ntp clean deploy |
| 43 | + - name: Configure Git identity |
| 44 | + run: | |
| 45 | + git config user.name "github-actions[bot]" |
| 46 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 47 | + - name: Create branch from tag and PR to main |
| 48 | + env: { GH_TOKEN: ${{ github.token }} } |
| 49 | + run: | |
| 50 | + BRANCH_NAME="release-bot-$(date +%Y%m%d-%H%M%S)" |
| 51 | + git checkout -B "$BRANCH_NAME" $GITHUB_SHA |
| 52 | + git push origin "$BRANCH_NAME" |
| 53 | + gh pr create \ |
| 54 | + --title "chore: merge release ${{ github.ref_name }} to main" \ |
| 55 | + --body "Automated PR created from tag ${{ github.ref_name }}." \ |
| 56 | + --base main \ |
| 57 | + --head "$BRANCH_NAME" || true |
| 58 | +``` |
| 59 | +
|
| 60 | +## Secrets (one-time) |
| 61 | +
|
| 62 | +- CENTRAL_USERNAME, CENTRAL_PASSWORD (Central Portal token) |
| 63 | +- GPG_PRIVATE_KEY (ASCII-armored secret key), GPG_PASSPHRASE |
| 64 | +
|
| 65 | +zsh helper (uses gh, gpg): |
| 66 | +
|
| 67 | +```zsh |
| 68 | +#!/usr/bin/env zsh |
| 69 | +set -euo pipefail |
| 70 | +export CENTRAL_USERNAME=your_user |
| 71 | +export CENTRAL_PASSWORD=your_pass |
| 72 | +export GPG_PASSPHRASE=your_passphrase |
| 73 | +export GPG_KEY_ID=YOUR_KEY_ID # or export GPG_PRIVATE_KEY="$(gpg --armor --export-secret-keys YOUR_KEY_ID)" |
| 74 | +./scripts/setup-release-secrets.zsh |
| 75 | +``` |
| 76 | + |
| 77 | +## Trigger a Release |
| 78 | + |
| 79 | +```bash |
| 80 | +git tag 'releases/0.1.0' |
| 81 | +git push origin 'releases/0.1.0' |
| 82 | +``` |
| 83 | + |
| 84 | +## Publish this doc as a Gist |
| 85 | + |
| 86 | +```bash |
| 87 | +gh gist create -p -d "Tag-triggered Maven Central release via GitHub Actions" RELEASE-GIST.md |
| 88 | +``` |
0 commit comments