|
| 1 | +# Release to Maven Central via Central Publisher Portal |
| 2 | +# https://central.sonatype.org/publish/publish-portal-guide/ |
| 3 | +# |
| 4 | +# Required GitHub secrets (Settings → Secrets and variables → Actions): |
| 5 | +# CENTRAL_TOKEN_USERNAME - Portal token username (from https://central.sonatype.com/usertoken) |
| 6 | +# CENTRAL_TOKEN_PASSWORD - Portal token password (from same page; save on first view, cannot be retrieved later) |
| 7 | +# GPG_SECRET_KEY - Armored GPG private key for signing |
| 8 | +# GPG_PASSPHRASE - Passphrase for the GPG key |
| 9 | +# PAT - Personal access token with repo scope (for pushing commits/tags) |
| 10 | +# |
| 11 | +name: IABGPP-Java 4.X Release |
| 12 | + |
| 13 | +on: |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + version: |
| 17 | + description: 'The release version (e.g., 4.x.x)' |
| 18 | + required: true |
| 19 | + default: '' |
| 20 | + |
| 21 | +jobs: |
| 22 | + release: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + # Checkout the repository with full history for tagging |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + # Set up Java |
| 32 | + - name: Set up Java |
| 33 | + uses: actions/setup-java@v4 |
| 34 | + with: |
| 35 | + distribution: 'temurin' |
| 36 | + java-version: '21' |
| 37 | + |
| 38 | + # Import GPG secret key for signing |
| 39 | + - name: Import GPG key |
| 40 | + run: | |
| 41 | + echo "${{ secrets.GPG_SECRET_KEY }}" > secret_key.asc |
| 42 | + gpg --import --no-tty --batch secret_key.asc || { echo "GPG import failed"; cat secret_key.asc; exit 1; } |
| 43 | + rm -f secret_key.asc |
| 44 | +
|
| 45 | + # Generate settings.xml with Central Publisher Portal token credentials |
| 46 | + # Token from: https://central.sonatype.com/usertoken |
| 47 | + - name: Create settings.xml |
| 48 | + env: |
| 49 | + CENTRAL_TOKEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} |
| 50 | + CENTRAL_TOKEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} |
| 51 | + run: | |
| 52 | + mkdir -p ~/.m2 |
| 53 | + cat > ~/.m2/settings.xml << EOF |
| 54 | + <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" |
| 55 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 56 | + xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> |
| 57 | + <servers> |
| 58 | + <server> |
| 59 | + <id>central</id> |
| 60 | + <username>${CENTRAL_TOKEN_USERNAME}</username> |
| 61 | + <password>${CENTRAL_TOKEN_PASSWORD}</password> |
| 62 | + </server> |
| 63 | + </servers> |
| 64 | + </settings> |
| 65 | + EOF |
| 66 | +
|
| 67 | + # Pull latest changes from master |
| 68 | + - name: Pull latest changes |
| 69 | + run: git pull origin 4.X |
| 70 | + |
| 71 | + # Set the release version in pom.xml |
| 72 | + - name: Set release version |
| 73 | + run: mvn versions:set -DnewVersion=${{ github.event.inputs.version }} -DgenerateBackupPoms=false |
| 74 | + |
| 75 | + # Build and deploy to Central Publisher Portal (mvn deploy uploads bundle and publishes) |
| 76 | + - name: Deploy release |
| 77 | + run: | |
| 78 | + echo "pinentry-mode loopback" > ~/.gnupg/gpg.conf |
| 79 | + echo "use-agent" >> ~/.gnupg/gpg.conf |
| 80 | + export GPG_TTY=$(tty || echo /dev/tty) |
| 81 | + mvn clean deploy --settings ~/.m2/settings.xml -Dgpg.passphrase="${{ secrets.GPG_PASSPHRASE }}" -Prelease |
| 82 | +
|
| 83 | + # Commit the release version and create a tag |
| 84 | + - name: Commit and tag release |
| 85 | + run: | |
| 86 | + git config user.email "mayank@iabtechlab.com" |
| 87 | + git config user.name "Mayank Mishra" |
| 88 | + git add . |
| 89 | + git commit -m "${{ github.event.inputs.version }}" |
| 90 | + git tag "${{ github.event.inputs.version }}" |
| 91 | +
|
| 92 | + # Set the next snapshot version |
| 93 | + - name: Set next snapshot version |
| 94 | + run: mvn versions:set -DnextSnapshot=true -DgenerateBackupPoms=false |
| 95 | + |
| 96 | + # Commit the snapshot version |
| 97 | + - name: Commit snapshot version |
| 98 | + run: | |
| 99 | + NEW_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 100 | + git add . |
| 101 | + git commit -m "$NEW_VERSION" |
| 102 | +
|
| 103 | + # Push commits and tags to GitHub |
| 104 | + - name: Push changes |
| 105 | + run: | |
| 106 | + git status |
| 107 | + git push; git push --tags |
| 108 | + env: |
| 109 | + GITHUB_TOKEN: ${{ secrets.PAT }} |
0 commit comments