|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release-version: |
| 7 | + description: 'Release version (e.g. 1.0.0) — leave blank to use current POM version without -SNAPSHOT' |
| 8 | + required: false |
| 9 | + next-version: |
| 10 | + description: 'Next development version (e.g. 1.0.1-SNAPSHOT) — leave blank to use incremented patch version with -SNAPSHOT' |
| 11 | + required: false |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + pull-requests: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + release: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Set up Java |
| 26 | + uses: actions/setup-java@v4 |
| 27 | + with: |
| 28 | + java-version: '25' |
| 29 | + distribution: 'zulu' |
| 30 | + cache: 'maven' |
| 31 | + server-id: central |
| 32 | + server-username: MAVEN_USERNAME |
| 33 | + server-password: MAVEN_PASSWORD |
| 34 | + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} |
| 35 | + gpg-passphrase: MAVEN_GPG_PASSPHRASE |
| 36 | + |
| 37 | + - name: Determine Versions |
| 38 | + id: versions |
| 39 | + run: | |
| 40 | + CURRENT_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 41 | +
|
| 42 | + RELEASE_VERSION="${{ inputs.release-version }}" |
| 43 | + if [ -z "$RELEASE_VERSION" ]; then |
| 44 | + RELEASE_VERSION="${CURRENT_VERSION/-SNAPSHOT/}" |
| 45 | + fi |
| 46 | +
|
| 47 | + NEXT_VERSION="${{ inputs.next-version }}" |
| 48 | + if [ -z "$NEXT_VERSION" ]; then |
| 49 | + PATCH=$(echo "$RELEASE_VERSION" | cut -d. -f3) |
| 50 | + NEXT_PATCH=$((PATCH + 1)) |
| 51 | + NEXT_VERSION=$(echo "$RELEASE_VERSION" | sed "s/\.[0-9]*$/.${NEXT_PATCH}-SNAPSHOT/") |
| 52 | + fi |
| 53 | +
|
| 54 | + echo "release-version=$RELEASE_VERSION" >> $GITHUB_OUTPUT |
| 55 | + echo "next-version=$NEXT_VERSION" >> $GITHUB_OUTPUT |
| 56 | +
|
| 57 | + - name: Configure Git |
| 58 | + run: | |
| 59 | + git config user.name "github-actions[bot]" |
| 60 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 61 | +
|
| 62 | + - name: Create Release Branch |
| 63 | + run: git checkout -b release-${{ steps.versions.outputs.release-version }} |
| 64 | + |
| 65 | + - name: Set Release Version |
| 66 | + run: | |
| 67 | + ./mvnw versions:set-property \ |
| 68 | + -Dproperty=revision \ |
| 69 | + -DnewVersion=${{ steps.versions.outputs.release-version }} \ |
| 70 | + -DgenerateBackupPoms=false |
| 71 | +
|
| 72 | + - name: Build and Deploy Release |
| 73 | + run: ./mvnw clean deploy |
| 74 | + env: |
| 75 | + MAVEN_PUBLISH: "true" |
| 76 | + MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} |
| 77 | + MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} |
| 78 | + MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 79 | + |
| 80 | + - name: Commit and Tag Release |
| 81 | + run: | |
| 82 | + git add pom.xml |
| 83 | + git commit -m "Release ${{ steps.versions.outputs.release-version }}" |
| 84 | + git tag -a v${{ steps.versions.outputs.release-version }} -m "Release ${{ steps.versions.outputs.release-version }}" |
| 85 | +
|
| 86 | + - name: Set Next Development Version |
| 87 | + run: | |
| 88 | + ./mvnw versions:set-property \ |
| 89 | + -Dproperty=revision \ |
| 90 | + -DnewVersion=${{ steps.versions.outputs.next-version }} \ |
| 91 | + -DgenerateBackupPoms=false |
| 92 | +
|
| 93 | + - name: Commit Next Development Version |
| 94 | + run: | |
| 95 | + git add pom.xml |
| 96 | + git commit -m "Prepare for next development iteration ${{ steps.versions.outputs.next-version }}" |
| 97 | +
|
| 98 | + - name: Push Release Branch and Tag |
| 99 | + run: git push --follow-tags origin release-${{ steps.versions.outputs.release-version }} |
| 100 | + |
| 101 | + - name: Open and Merge PR to main |
| 102 | + env: |
| 103 | + GH_TOKEN: ${{ secrets.RELEASE_TOKEN }} |
| 104 | + run: | |
| 105 | + PR_URL=$(gh pr create \ |
| 106 | + --base main \ |
| 107 | + --head release-${{ steps.versions.outputs.release-version }} \ |
| 108 | + --title "Prepare for development of ${{ steps.versions.outputs.next-version }}" \ |
| 109 | + --body "Prepares next development iteration **${{ steps.versions.outputs.next-version }}**.") |
| 110 | +
|
| 111 | + gh pr merge "$PR_URL" --squash |
0 commit comments