|
| 1 | +name: Release |
| 2 | + |
| 3 | +# Read-only by default. Only the `release` job needs `contents: write` |
| 4 | +# to create the GitHub release — declared on the job itself, following |
| 5 | +# least-privilege. |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + tags: |
| 12 | + - "v[0-9]+.[0-9]+.[0-9]+" |
| 13 | + |
| 14 | +# Serialise releases per-tag so re-running a tag (or pushing two tags |
| 15 | +# back-to-back) doesn't race on the same GitHub release page. Don't |
| 16 | +# cancel an in-progress release — a half-created release is worse than |
| 17 | +# a queued duplicate. |
| 18 | +concurrency: |
| 19 | + group: release-${{ github.ref }} |
| 20 | + cancel-in-progress: false |
| 21 | + |
| 22 | +jobs: |
| 23 | + validate: |
| 24 | + name: Validate Release |
| 25 | + runs-on: ubuntu-latest |
| 26 | + timeout-minutes: 5 |
| 27 | + |
| 28 | + # Read-only: validate just inspects the tag. |
| 29 | + permissions: |
| 30 | + contents: read |
| 31 | + |
| 32 | + outputs: |
| 33 | + version: ${{ steps.version.outputs.version }} |
| 34 | + tag: ${{ steps.version.outputs.tag }} |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Determine version |
| 38 | + id: version |
| 39 | + shell: bash |
| 40 | + run: | |
| 41 | + TAG="${GITHUB_REF#refs/tags/}" |
| 42 | +
|
| 43 | + # The push trigger already filters on the tag glob, but the |
| 44 | + # glob can't fully anchor SemVer — re-validate here so a |
| 45 | + # malformed tag fails loudly instead of producing a bad release. |
| 46 | + if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 47 | + echo "Error: Invalid tag format: $TAG" |
| 48 | + echo "Expected format: v0.0.0" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | +
|
| 52 | + VERSION="${TAG#v}" |
| 53 | + echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
| 54 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 55 | + echo "Release version: $VERSION (tag: $TAG)" |
| 56 | +
|
| 57 | + release: |
| 58 | + name: Create Release |
| 59 | + needs: validate |
| 60 | + runs-on: ubuntu-latest |
| 61 | + timeout-minutes: 10 |
| 62 | + |
| 63 | + # The only job that needs elevated scope: `contents: write` to |
| 64 | + # create the GitHub release. This is a files-only repository, so |
| 65 | + # there are no build artefacts to attest — the tag itself is the |
| 66 | + # verifiable, immutable reference. |
| 67 | + permissions: |
| 68 | + contents: write |
| 69 | + |
| 70 | + steps: |
| 71 | + - name: Checkout repository |
| 72 | + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 73 | + |
| 74 | + - name: Extract release notes from CHANGELOG |
| 75 | + id: release-notes |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + VERSION="${{ needs.validate.outputs.version }}" |
| 79 | +
|
| 80 | + # Extract the notes for this version from CHANGELOG.md. |
| 81 | + # index()==1 is a literal (non-regex) prefix match on the |
| 82 | + # "## [x.y.z]" heading; we print until the next "## [" heading. |
| 83 | + awk -v ver="## [${VERSION}]" ' |
| 84 | + index($0, ver) == 1 { found=1; next } |
| 85 | + found && /^## \[/ { exit } |
| 86 | + found { print } |
| 87 | + ' CHANGELOG.md > release_notes.md |
| 88 | +
|
| 89 | + # Trim leading, then trailing, blank lines. |
| 90 | + sed -i '/./,$!d' release_notes.md |
| 91 | + sed -i ':a;/^[[:space:]]*$/{$d;N;ba}' release_notes.md |
| 92 | +
|
| 93 | + if [[ -s release_notes.md ]]; then |
| 94 | + echo "Found release notes in CHANGELOG.md:" |
| 95 | + else |
| 96 | + echo "No CHANGELOG entry for ${VERSION}, using default" |
| 97 | + echo "Release ${VERSION}" > release_notes.md |
| 98 | + fi |
| 99 | +
|
| 100 | + echo "--- Release Notes ---" |
| 101 | + cat release_notes.md |
| 102 | +
|
| 103 | + - name: Build release bundle |
| 104 | + id: bundle |
| 105 | + shell: bash |
| 106 | + run: | |
| 107 | + TAG="${{ needs.validate.outputs.tag }}" |
| 108 | + DIR="arm-cmake-toolchains-${TAG}" |
| 109 | + ZIP="${DIR}.zip" |
| 110 | +
|
| 111 | + # Assemble a curated bundle — just the files a consumer needs — |
| 112 | + # rather than shipping the repo's CI, tooling, and governance |
| 113 | + # via GitHub's auto-generated source archive. |
| 114 | + mkdir "$DIR" |
| 115 | + cp arm_none_eabi_gcc.cmake arm_none_eabi_llvm.cmake CHANGELOG.md LICENCE "$DIR/" |
| 116 | +
|
| 117 | + # A bundle-specific README that points back to the project and |
| 118 | + # invites contributions. Substitute the release version into it. |
| 119 | + sed "s/__VERSION__/${TAG}/g" .github/release-assets/README.md > "$DIR/README.md" |
| 120 | +
|
| 121 | + zip -r "$ZIP" "$DIR" |
| 122 | + echo "zip=$ZIP" >> "$GITHUB_OUTPUT" |
| 123 | +
|
| 124 | + echo "--- Bundle contents ---" |
| 125 | + unzip -l "$ZIP" |
| 126 | +
|
| 127 | + - name: Create GitHub Release |
| 128 | + shell: bash |
| 129 | + env: |
| 130 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 131 | + run: | |
| 132 | + TAG="${{ needs.validate.outputs.tag }}" |
| 133 | + ZIP="${{ steps.bundle.outputs.zip }}" |
| 134 | +
|
| 135 | + # gh CLI is more reliable than third-party release actions. |
| 136 | + # Only clean vX.Y.Z tags reach this workflow, so every release |
| 137 | + # is a stable one and is marked "latest". The curated bundle |
| 138 | + # is attached as a release asset alongside the notes. |
| 139 | + gh release create "$TAG" \ |
| 140 | + --title "$TAG" \ |
| 141 | + --notes-file release_notes.md \ |
| 142 | + --latest \ |
| 143 | + "$ZIP" |
| 144 | +
|
| 145 | + echo "Release created: $TAG (asset: $ZIP)" |
0 commit comments