|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + required: false |
| 8 | + type: string |
| 9 | + default: '' |
| 10 | + description: Release version number (without v, defaults to gradle.properties) |
| 11 | + |
| 12 | +jobs: |
| 13 | + publish-release: |
| 14 | + name: Publish release |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + # write permission is required to create a GitHub release |
| 18 | + contents: write |
| 19 | + # write permission is required for autolabeler |
| 20 | + # otherwise, read permission is required at least |
| 21 | + pull-requests: read |
| 22 | + steps: |
| 23 | + - name: Validate input parameters |
| 24 | + # language=bash |
| 25 | + run: | |
| 26 | + # Ensure we release from master or release/** branches, ensure version number follows semver |
| 27 | + BRANCH_NAME=${GITHUB_REF##refs/heads/} |
| 28 | + if [[ ! "$BRANCH_NAME" =~ ^(master|release/.+)$ ]]; then |
| 29 | + echo "Error: Release must be created from 'master' or 'release/**' branch. Current branch is '$BRANCH_NAME'" |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | +
|
| 33 | + # Validate version follows semver or is empty |
| 34 | + VERSION="${{ inputs.version }}" |
| 35 | + if [[ -n "$VERSION" && ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 36 | + echo "Error: Version must be blank or follow semantic versioning format (x.y.z). Got '$VERSION'" |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | +
|
| 40 | + - name: Checkout code |
| 41 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 |
| 42 | + |
| 43 | + - name: Get the release version |
| 44 | + id: release_version |
| 45 | + shell: bash |
| 46 | + # language=bash |
| 47 | + run: | |
| 48 | + if [[ -n "${{ inputs.version }}" ]]; then |
| 49 | + VERSION="${{ inputs.version }}" |
| 50 | + echo "Got release version from workflow input: $VERSION" |
| 51 | + else |
| 52 | + VERSION=$(grep "^current.version=" gradle.properties | cut -d'=' -f2) |
| 53 | + echo "Got release version from gradle.properties: $VERSION" |
| 54 | + fi |
| 55 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 56 | +
|
| 57 | + - name: Check if tag exists |
| 58 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 |
| 59 | + env: |
| 60 | + VERSION: ${{ steps.release_version.outputs.version }} |
| 61 | + with: |
| 62 | + # language=javascript |
| 63 | + script: | |
| 64 | + const tag = `v${process.env.VERSION}`; |
| 65 | + // Check if the tag exists |
| 66 | + const { data: tags } = await github.rest.git.listMatchingRefs({ |
| 67 | + owner: context.repo.owner, |
| 68 | + repo: context.repo.repo, |
| 69 | + ref: `tags/${tag}` |
| 70 | + }); |
| 71 | + if (tags.length > 0) { |
| 72 | + core.setFailed(`Tag ${tag} already exists. Bump version in gradle.properties and try releasing again.`); |
| 73 | + } |
| 74 | +
|
| 75 | + - name: Prepare git name and email |
| 76 | + # language=bash |
| 77 | + run: | |
| 78 | + # Configure git user.name and user.email |
| 79 | + # See https://github.com/actions/checkout?tab=readme-ov-file#push-a-commit-using-the-built-in-token |
| 80 | + git config user.name "github-actions[bot]" |
| 81 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 82 | +
|
| 83 | + - uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2 |
| 84 | + id: app_token |
| 85 | + with: |
| 86 | + app-id: ${{ vars.GH_BUMP_VERSION_APP_ID }} |
| 87 | + private-key: ${{ secrets.GH_BUMP_VERSION_APP_KEY }} |
| 88 | + |
| 89 | + - name: Update version in gradle.properties to ${{ steps.release_version.outputs.version }} |
| 90 | + uses: ./.github/actions/update_version |
| 91 | + with: |
| 92 | + token: ${{ steps.app_token.outputs.token }} |
| 93 | + version: ${{ steps.release_version.outputs.version }} |
| 94 | + |
| 95 | + - name: Set up JDK 21 |
| 96 | + uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4 |
| 97 | + with: |
| 98 | + distribution: zulu |
| 99 | + java-version: 21 |
| 100 | + server-id: central |
| 101 | + |
| 102 | + # Publish to Central before generating a tag, so we don't need to drop the tag if |
| 103 | + # Central deployment fails. |
| 104 | + - name: Publish to Central Portal |
| 105 | + uses: burrunan/gradle-cache-action@663fbad34e03c8f12b27f4999ac46e3d90f87eca # v3 |
| 106 | + with: |
| 107 | + arguments: publishPlugins publishAllPublicationsToCentralPortal |
| 108 | + # language=properties |
| 109 | + properties: | |
| 110 | + release=true |
| 111 | + centralPortalPublishingType=AUTOMATIC |
| 112 | + env: |
| 113 | + CENTRAL_PORTAL_USERNAME: ${{ secrets.MAVEN_USER }} |
| 114 | + CENTRAL_PORTAL_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} |
| 115 | + SIGNING_PGP_PRIVATE_KEY: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} |
| 116 | + SIGNING_PGP_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} |
| 117 | + GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} |
| 118 | + GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} |
| 119 | + |
| 120 | + - name: Publish GitHub release |
| 121 | + uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v6 |
| 122 | + id: publish_release |
| 123 | + with: |
| 124 | + disable-autolabeler: true |
| 125 | + publish: true |
| 126 | + latest: ${{ github.ref_name == github.event.repository.default_branch }} |
| 127 | + version: ${{ steps.release_version.outputs.version }} |
| 128 | + env: |
| 129 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 130 | + |
| 131 | + - name: Compute the next patch version |
| 132 | + id: next_version |
| 133 | + # language=bash |
| 134 | + run: | |
| 135 | + # Compute the next patch version |
| 136 | + IFS='.' read -r major minor patch <<< "${{ steps.release_version.outputs.version }}" |
| 137 | + next_version="${major}.${minor}.$((patch + 1))" |
| 138 | + echo "Next version: $next_version" |
| 139 | + echo "version=$next_version" >> "$GITHUB_OUTPUT" |
| 140 | +
|
| 141 | + - name: Update version in gradle.properties to ${{ steps.next_version.outputs.version }} |
| 142 | + uses: ./.github/actions/update_version |
| 143 | + with: |
| 144 | + token: ${{ steps.app_token.outputs.token }} |
| 145 | + version: ${{ steps.next_version.outputs.version }} |
0 commit comments