|
| 1 | +name: Release to Maven Central |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 21 | + |
| 22 | + - name: Set up Java |
| 23 | + uses: actions/setup-java@v4 |
| 24 | + with: |
| 25 | + distribution: temurin |
| 26 | + java-version: '17' |
| 27 | + server-id: central |
| 28 | + server-username: CENTRAL_USERNAME |
| 29 | + server-password: CENTRAL_PASSWORD |
| 30 | + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} |
| 31 | + gpg-passphrase: GPG_PASSPHRASE |
| 32 | + |
| 33 | + - name: Configure Git |
| 34 | + run: | |
| 35 | + git config user.name "github-actions[bot]" |
| 36 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 37 | +
|
| 38 | + - name: Get current version and increment |
| 39 | + id: version |
| 40 | + run: | |
| 41 | + CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 42 | + echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 43 | +
|
| 44 | + # Remove -SNAPSHOT if present |
| 45 | + RELEASE_VERSION=${CURRENT_VERSION%-SNAPSHOT} |
| 46 | + echo "release=$RELEASE_VERSION" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + # Calculate next version (increment patch) |
| 49 | + IFS='.' read -r major minor patch <<< "$RELEASE_VERSION" |
| 50 | + NEXT_VERSION="$major.$minor.$((patch + 1))-SNAPSHOT" |
| 51 | + echo "next=$NEXT_VERSION" >> $GITHUB_OUTPUT |
| 52 | +
|
| 53 | + - name: Set release version |
| 54 | + run: | |
| 55 | + mvn versions:set -DnewVersion=${{ steps.version.outputs.release }} -DgenerateBackupPoms=false |
| 56 | +
|
| 57 | + - name: Build and verify |
| 58 | + run: mvn -B clean verify -Prelease |
| 59 | + env: |
| 60 | + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 61 | + |
| 62 | + - name: Deploy to Maven Central |
| 63 | + run: mvn -B deploy -Prelease -DskipTests |
| 64 | + env: |
| 65 | + CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }} |
| 66 | + CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }} |
| 67 | + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 68 | + |
| 69 | + - name: Create Git tag |
| 70 | + run: | |
| 71 | + git tag -a "v${{ steps.version.outputs.release }}" -m "Release v${{ steps.version.outputs.release }}" |
| 72 | + git push origin "v${{ steps.version.outputs.release }}" |
| 73 | +
|
| 74 | + - name: Create GitHub Release |
| 75 | + uses: softprops/action-gh-release@v1 |
| 76 | + with: |
| 77 | + tag_name: v${{ steps.version.outputs.release }} |
| 78 | + name: Release v${{ steps.version.outputs.release }} |
| 79 | + generate_release_notes: true |
| 80 | + env: |
| 81 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + |
| 83 | + - name: Set next development version |
| 84 | + run: | |
| 85 | + mvn versions:set -DnewVersion=${{ steps.version.outputs.next }} -DgenerateBackupPoms=false |
| 86 | + git add pom.xml |
| 87 | + git commit -m "chore: bump version to ${{ steps.version.outputs.next }} [skip ci]" |
| 88 | + git push origin main |
0 commit comments