|
| 1 | +name: Release / Sure-AIO |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request_target: |
| 6 | + types: [closed] |
| 7 | + |
| 8 | +jobs: |
| 9 | + prepare-release: |
| 10 | + if: ${{ github.ref == 'refs/heads/main' }} |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: write |
| 14 | + pull-requests: write |
| 15 | + outputs: |
| 16 | + release_version: ${{ steps.version.outputs.release_version }} |
| 17 | + steps: |
| 18 | + - name: Checkout |
| 19 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Install git-cliff |
| 24 | + env: |
| 25 | + GIT_CLIFF_VERSION: 2.12.0 |
| 26 | + run: | |
| 27 | + archive="git-cliff-${GIT_CLIFF_VERSION}-x86_64-unknown-linux-gnu.tar.gz" |
| 28 | + curl -fsSL -o "/tmp/${archive}" "https://github.com/orhun/git-cliff/releases/download/v${GIT_CLIFF_VERSION}/${archive}" |
| 29 | + tar -xzf "/tmp/${archive}" -C /tmp |
| 30 | + install "/tmp/git-cliff-${GIT_CLIFF_VERSION}/git-cliff" /usr/local/bin/git-cliff |
| 31 | + git-cliff --version |
| 32 | +
|
| 33 | + - name: Compute release version |
| 34 | + id: version |
| 35 | + run: | |
| 36 | + release_version="$(python3 scripts/release.py next-version)" |
| 37 | + echo "release_version=${release_version}" >> "${GITHUB_OUTPUT}" |
| 38 | +
|
| 39 | + - name: Generate changelog |
| 40 | + env: |
| 41 | + GITHUB_REPO: ${{ github.repository }} |
| 42 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + RELEASE_VERSION: ${{ steps.version.outputs.release_version }} |
| 44 | + run: | |
| 45 | + git-cliff --config cliff.toml --tag "${RELEASE_VERSION}" --output CHANGELOG.md |
| 46 | + parsed_version="$(python3 scripts/release.py latest-changelog-version)" |
| 47 | + if [[ "${parsed_version}" != "${RELEASE_VERSION}" ]]; then |
| 48 | + echo "Generated changelog top section ${parsed_version} does not match ${RELEASE_VERSION}" >&2 |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Create release PR |
| 53 | + uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0 |
| 54 | + with: |
| 55 | + commit-message: "chore(release): ${{ steps.version.outputs.release_version }}" |
| 56 | + title: "chore(release): ${{ steps.version.outputs.release_version }}" |
| 57 | + body: | |
| 58 | + This PR prepares `${{ steps.version.outputs.release_version }}`. |
| 59 | +
|
| 60 | + - updates `CHANGELOG.md` with `git-cliff` |
| 61 | + - is intended to be merged to `main` |
| 62 | + - will trigger GitHub Release publishing after merge |
| 63 | + branch: "release/${{ steps.version.outputs.release_version }}" |
| 64 | + delete-branch: true |
| 65 | + |
| 66 | + publish-release-on-merge: |
| 67 | + if: "${{ github.event_name == 'pull_request_target' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' && startsWith(github.event.pull_request.title, 'chore(release): ') }}" |
| 68 | + runs-on: ubuntu-latest |
| 69 | + permissions: |
| 70 | + contents: write |
| 71 | + steps: |
| 72 | + - name: Checkout merge commit |
| 73 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 74 | + with: |
| 75 | + ref: ${{ github.event.pull_request.merge_commit_sha }} |
| 76 | + fetch-depth: 0 |
| 77 | + |
| 78 | + - name: Determine release version |
| 79 | + id: version |
| 80 | + env: |
| 81 | + PR_TITLE: ${{ github.event.pull_request.title }} |
| 82 | + run: | |
| 83 | + release_version="${PR_TITLE#chore(release): }" |
| 84 | + echo "release_version=${release_version}" >> "${GITHUB_OUTPUT}" |
| 85 | + changelog_version="$(python3 scripts/release.py latest-changelog-version)" |
| 86 | + if [[ "${changelog_version}" != "${release_version}" ]]; then |
| 87 | + echo "CHANGELOG top entry ${changelog_version} does not match ${release_version}" >&2 |
| 88 | + exit 1 |
| 89 | + fi |
| 90 | +
|
| 91 | + - name: Extract release notes |
| 92 | + id: notes |
| 93 | + env: |
| 94 | + RELEASE_VERSION: ${{ steps.version.outputs.release_version }} |
| 95 | + run: | |
| 96 | + { |
| 97 | + echo "release_notes<<EOF" |
| 98 | + python3 scripts/release.py extract-release-notes "${RELEASE_VERSION}" |
| 99 | + echo "EOF" |
| 100 | + } >> "${GITHUB_OUTPUT}" |
| 101 | +
|
| 102 | + - name: Create Git tag if missing |
| 103 | + env: |
| 104 | + RELEASE_VERSION: ${{ steps.version.outputs.release_version }} |
| 105 | + MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }} |
| 106 | + run: | |
| 107 | + if git rev-parse "${RELEASE_VERSION}" >/dev/null 2>&1; then |
| 108 | + echo "Tag ${RELEASE_VERSION} already exists; skipping." |
| 109 | + exit 0 |
| 110 | + fi |
| 111 | +
|
| 112 | + git config user.name "github-actions[bot]" |
| 113 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 114 | + git tag "${RELEASE_VERSION}" "${MERGE_SHA}" |
| 115 | + git push origin "${RELEASE_VERSION}" |
| 116 | +
|
| 117 | + - name: Publish GitHub release |
| 118 | + env: |
| 119 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 120 | + RELEASE_VERSION: ${{ steps.version.outputs.release_version }} |
| 121 | + RELEASE_NOTES: ${{ steps.notes.outputs.release_notes }} |
| 122 | + MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }} |
| 123 | + run: | |
| 124 | + if gh release view "${RELEASE_VERSION}" >/dev/null 2>&1; then |
| 125 | + echo "GitHub release ${RELEASE_VERSION} already exists; skipping." |
| 126 | + exit 0 |
| 127 | + fi |
| 128 | +
|
| 129 | + notes_file="$(mktemp)" |
| 130 | + printf '%s\n' "${RELEASE_NOTES}" > "${notes_file}" |
| 131 | + gh release create "${RELEASE_VERSION}" \ |
| 132 | + --title "${RELEASE_VERSION}" \ |
| 133 | + --notes-file "${notes_file}" \ |
| 134 | + --target "${MERGE_SHA}" |
0 commit comments