|
| 1 | +name: Publish - Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + component_path: |
| 7 | + description: "Gradle path of the component to publish, e.g. :components:bom" |
| 8 | + required: true |
| 9 | + default: ":components:bom" |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: publish-release-${{ inputs.component_path }} |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +jobs: |
| 19 | + publish-release: |
| 20 | + name: Publish release |
| 21 | + runs-on: ubuntu-latest |
| 22 | + timeout-minutes: 60 |
| 23 | + |
| 24 | + env: |
| 25 | + COMPONENT_PATH: ${{ inputs.component_path }} |
| 26 | + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} |
| 27 | + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} |
| 28 | + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_IN_MEMORY_KEY }} |
| 29 | + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_IN_MEMORY_KEY_ID }} |
| 30 | + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_IN_MEMORY_KEY_PASSWORD }} |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Validate branch |
| 34 | + run: | |
| 35 | + set -euo pipefail |
| 36 | +
|
| 37 | + if [[ "${GITHUB_REF_NAME}" != "main" ]]; then |
| 38 | + echo "Releases must be published from main. Current ref: ${GITHUB_REF_NAME}" |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | +
|
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 44 | + with: |
| 45 | + fetch-depth: 0 |
| 46 | + |
| 47 | + - name: Setup Gradle environment |
| 48 | + uses: ./.github/actions/setup-gradle |
| 49 | + |
| 50 | + - name: Configure Git author |
| 51 | + run: | |
| 52 | + git config user.name "TMC Release Bot" |
| 53 | + git config user.email "tmc-release-bot@thunderbird.net" |
| 54 | +
|
| 55 | + - name: Create release tag |
| 56 | + id: release-tag |
| 57 | + run: | |
| 58 | + set -euo pipefail |
| 59 | +
|
| 60 | + tag="$(./gradlew -q "${COMPONENT_PATH}:printReleaseTag")" |
| 61 | +
|
| 62 | + if git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then |
| 63 | + tag_commit="$(git rev-list -n 1 "${tag}")" |
| 64 | + head_commit="$(git rev-parse HEAD)" |
| 65 | +
|
| 66 | + if [[ "${tag_commit}" != "${head_commit}" ]]; then |
| 67 | + echo "Release tag ${tag} already exists but does not point at HEAD." |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | +
|
| 71 | + echo "Release tag ${tag} already exists on HEAD." |
| 72 | + echo "tag=${tag}" >> "${GITHUB_OUTPUT}" |
| 73 | + exit 0 |
| 74 | + fi |
| 75 | +
|
| 76 | + ./gradlew "${COMPONENT_PATH}:createReleaseTag" |
| 77 | +
|
| 78 | + if ! git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then |
| 79 | + echo "Expected release tag ${tag} to be created." |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | +
|
| 83 | + echo "tag=${tag}" >> "${GITHUB_OUTPUT}" |
| 84 | +
|
| 85 | + - name: Write release notes |
| 86 | + run: ./gradlew "${COMPONENT_PATH}:writeReleaseNotes" -PreleaseNotesFile="${RUNNER_TEMP}/release-notes.md" |
| 87 | + |
| 88 | + - name: Publish release |
| 89 | + run: ./gradlew "${COMPONENT_PATH}:validateStableVersionForPublishing" "${COMPONENT_PATH}:publishAndReleaseToMavenCentral" |
| 90 | + |
| 91 | + - name: Push release tag |
| 92 | + run: | |
| 93 | + set -euo pipefail |
| 94 | +
|
| 95 | + tag="${{ steps.release-tag.outputs.tag }}" |
| 96 | + if git ls-remote --exit-code --tags origin "refs/tags/${tag}" >/dev/null 2>&1; then |
| 97 | + echo "Remote release tag ${tag} already exists." |
| 98 | + exit 0 |
| 99 | + fi |
| 100 | +
|
| 101 | + git push origin "refs/tags/${tag}" |
| 102 | +
|
| 103 | + - name: Create GitHub release |
| 104 | + env: |
| 105 | + GH_TOKEN: ${{ github.token }} |
| 106 | + run: | |
| 107 | + set -euo pipefail |
| 108 | +
|
| 109 | + tag="${{ steps.release-tag.outputs.tag }}" |
| 110 | + if gh release view "${tag}" >/dev/null 2>&1; then |
| 111 | + echo "GitHub release ${tag} already exists." |
| 112 | + exit 0 |
| 113 | + fi |
| 114 | +
|
| 115 | + gh release create "${tag}" \ |
| 116 | + --title "${tag}" \ |
| 117 | + --target "${GITHUB_SHA}" \ |
| 118 | + --verify-tag \ |
| 119 | + --notes-file "${RUNNER_TEMP}/release-notes.md" |
0 commit comments