|
| 1 | +name: Release on Tag |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'release/[0-9]*.[0-9]*.[0-9]*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write # push tags, push commits |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: release-${{ github.ref }} |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + release: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Set up Java, Central creds and GPG |
| 26 | + uses: actions/setup-java@v4 |
| 27 | + with: |
| 28 | + distribution: temurin |
| 29 | + java-version: '21' |
| 30 | + cache: maven |
| 31 | + server-id: central |
| 32 | + server-username: CENTRAL_USERNAME |
| 33 | + server-password: CENTRAL_PASSWORD |
| 34 | + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} |
| 35 | + gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} |
| 36 | + |
| 37 | + - name: Create GitHub Release with notes |
| 38 | + uses: softprops/action-gh-release@v2 |
| 39 | + with: |
| 40 | + tag_name: ${{ github.ref_name }} |
| 41 | + generate_release_notes: true |
| 42 | + |
| 43 | + - name: Build and Deploy to Central |
| 44 | + env: |
| 45 | + CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }} |
| 46 | + CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }} |
| 47 | + run: | |
| 48 | + mvn -B -ntp clean deploy |
| 49 | +
|
| 50 | + - name: Configure Git identity |
| 51 | + run: | |
| 52 | + git config user.name "github-actions[bot]" |
| 53 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 54 | +
|
| 55 | + - name: Create branch from tag for PR |
| 56 | + id: prbranch |
| 57 | + run: | |
| 58 | + BRANCH_NAME="release-bot-$(date +%Y%m%d-%H%M%S)" |
| 59 | + git checkout -B "$BRANCH_NAME" $GITHUB_SHA |
| 60 | + git push origin "$BRANCH_NAME" |
| 61 | + echo "branch=$BRANCH_NAME" >> "$GITHUB_OUTPUT" |
| 62 | +
|
| 63 | + - name: Open PR back to main |
| 64 | + env: |
| 65 | + GH_TOKEN: ${{ github.token }} |
| 66 | + run: | |
| 67 | + gh pr create \ |
| 68 | + --title "chore: merge release ${{ github.ref_name }} to main" \ |
| 69 | + --body "Automated PR created from tag ${{ github.ref_name }}." \ |
| 70 | + --base main \ |
| 71 | + --head "${{ steps.prbranch.outputs.branch }}" \ |
| 72 | + || echo "PR already exists or nothing to compare" |
0 commit comments