|
| 1 | +# Copyright 2026 NVIDIA CORPORATION |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +# Release, step 2 of 2 — Tag & Publish (automatic). |
| 5 | +# |
| 6 | +# Fires when a "release/prepare-*" PR from release-prepare.yaml is merged into main or a v*.* |
| 7 | +# branch. Reads the freshly-folded top section of CHANGELOG.md, creates the git tag, and creates |
| 8 | +# the GitHub Release with that section as the notes. |
| 9 | + |
| 10 | +name: Release — Tag & Publish |
| 11 | + |
| 12 | +on: |
| 13 | + pull_request: |
| 14 | + types: [closed] |
| 15 | + branches: |
| 16 | + - main |
| 17 | + - 'v*.*' |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: write |
| 21 | + |
| 22 | +concurrency: |
| 23 | + group: release-publish |
| 24 | + cancel-in-progress: false |
| 25 | + |
| 26 | +jobs: |
| 27 | + publish: |
| 28 | + name: Tag & create GitHub Release |
| 29 | + if: >- |
| 30 | + github.event.pull_request.merged == true && |
| 31 | + startsWith(github.event.pull_request.head.ref, 'release/prepare-') |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - name: Checkout merged ${{ github.event.pull_request.base.ref }} |
| 35 | + uses: actions/checkout@v6 |
| 36 | + with: |
| 37 | + ref: ${{ github.event.pull_request.base.ref }} |
| 38 | + fetch-depth: 0 |
| 39 | + fetch-tags: true |
| 40 | + token: ${{ secrets.KAIBOT_TOKEN }} |
| 41 | + |
| 42 | + - name: Derive version and release notes from CHANGELOG.md |
| 43 | + id: notes |
| 44 | + env: |
| 45 | + HEAD_REF: ${{ github.event.pull_request.head.ref }} |
| 46 | + run: | |
| 47 | + set -euo pipefail |
| 48 | +
|
| 49 | + # Top "## [VERSION] - date" heading is the version this PR just folded in. |
| 50 | + VERSION="$(grep -m1 -oE '^## \[[^]]+\]' CHANGELOG.md | sed -E 's/^## \[(.+)\]/\1/')" |
| 51 | + BRANCH_VERSION="${HEAD_REF#release/prepare-}" |
| 52 | + if [ -z "$VERSION" ]; then |
| 53 | + echo "::error::Could not read a version heading from CHANGELOG.md"; exit 1 |
| 54 | + fi |
| 55 | + if [ "$VERSION" != "$BRANCH_VERSION" ]; then |
| 56 | + echo "::error::CHANGELOG top version ($VERSION) != branch version ($BRANCH_VERSION)"; exit 1 |
| 57 | + fi |
| 58 | + if git rev-parse -q --verify "refs/tags/$VERSION" >/dev/null; then |
| 59 | + echo "::error::Tag $VERSION already exists"; exit 1 |
| 60 | + fi |
| 61 | +
|
| 62 | + # Extract the body of the top section (everything after its heading, up to the next |
| 63 | + # "## [" heading), trimming leading blank lines. |
| 64 | + awk ' |
| 65 | + /^## \[/ { n++; if (n==1) next; if (n==2) exit } |
| 66 | + n==1 { print } |
| 67 | + ' CHANGELOG.md | sed '/./,$!d' > "${RUNNER_TEMP:-/tmp}/notes.md" |
| 68 | +
|
| 69 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 70 | + echo "Release $VERSION notes:"; cat "${RUNNER_TEMP:-/tmp}/notes.md" |
| 71 | +
|
| 72 | + - name: Create and push tag |
| 73 | + env: |
| 74 | + VERSION: ${{ steps.notes.outputs.version }} |
| 75 | + run: | |
| 76 | + set -euo pipefail |
| 77 | + git config --local user.name "kai-release-bot" |
| 78 | + git config --local user.email "action@github.com" |
| 79 | + git tag "$VERSION" |
| 80 | + git push origin "refs/tags/$VERSION" |
| 81 | +
|
| 82 | + - name: Create GitHub Release |
| 83 | + env: |
| 84 | + GH_TOKEN: ${{ secrets.KAIBOT_TOKEN }} |
| 85 | + VERSION: ${{ steps.notes.outputs.version }} |
| 86 | + run: | |
| 87 | + set -euo pipefail |
| 88 | + gh release create "$VERSION" \ |
| 89 | + --title "$VERSION" \ |
| 90 | + --notes-file "${RUNNER_TEMP:-/tmp}/notes.md" |
0 commit comments