|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + # A tag is a release: it gets a version number, release notes, and a URL |
| 5 | + # that keeps meaning the same thing a year from now. |
| 6 | + push: |
| 7 | + tags: |
| 8 | + - "v*" |
| 9 | + # main is the rolling channel. kuma is consumed by rebuilding constantly, |
| 10 | + # so waiting for a tag to get a usable binary would mean the published |
| 11 | + # one is nearly always behind the tree it is meant to build from. |
| 12 | + branches: |
| 13 | + - main |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + # Keyless signing: cosign trades this token for a short-lived certificate |
| 19 | + # instead of anyone holding a private key. |
| 20 | + id-token: write |
| 21 | + |
| 22 | +env: |
| 23 | + CARGO_TERM_COLOR: always |
| 24 | + TARGET: x86_64-unknown-linux-musl |
| 25 | + |
| 26 | +jobs: |
| 27 | + release: |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v7 |
| 31 | + |
| 32 | + - name: work out what this build is |
| 33 | + id: what |
| 34 | + run: | |
| 35 | + set -euo pipefail |
| 36 | + version=$(cargo metadata --no-deps --format-version 1 \ |
| 37 | + | jq -r '.packages[] | select(.name == "kuma") | .version') |
| 38 | + # The asset name carries no version on purpose. A versioned |
| 39 | + # filename would make releases/latest/download/<name> change |
| 40 | + # every release, so the README could never hold a durable URL, |
| 41 | + # and the version is not lost: the tag has it and the binary |
| 42 | + # reports it. |
| 43 | + if [ "${GITHUB_REF_TYPE}" = "tag" ]; then |
| 44 | + # A tag that disagrees with Cargo.toml would publish a binary |
| 45 | + # whose own --version contradicts the release it sits in. That |
| 46 | + # is the exact class of lie the build stamp exists to prevent, |
| 47 | + # so it fails here rather than shipping. |
| 48 | + if [ "${GITHUB_REF_NAME}" != "v${version}" ]; then |
| 49 | + echo "tag ${GITHUB_REF_NAME} does not match Cargo.toml version ${version}" >&2 |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + { |
| 53 | + echo "tag=v${version}" |
| 54 | + echo "name=kuma-${TARGET}" |
| 55 | + echo "prerelease=false" |
| 56 | + echo "title=kuma v${version}" |
| 57 | + } >> "$GITHUB_OUTPUT" |
| 58 | + else |
| 59 | + { |
| 60 | + echo "tag=latest" |
| 61 | + echo "name=kuma-${TARGET}" |
| 62 | + echo "prerelease=true" |
| 63 | + echo "title=Rolling build from main" |
| 64 | + } >> "$GITHUB_OUTPUT" |
| 65 | + fi |
| 66 | +
|
| 67 | + - uses: dtolnay/rust-toolchain@stable |
| 68 | + with: |
| 69 | + targets: x86_64-unknown-linux-musl |
| 70 | + - uses: Swatinem/rust-cache@v2 |
| 71 | + |
| 72 | + # ci.yml runs on this same push, but nothing makes this job wait for |
| 73 | + # it, so without a gate here a red tree still publishes a binary. |
| 74 | + # Testing on the release target rather than the host's costs nothing |
| 75 | + # extra: it is one compile instead of two, and it exercises the |
| 76 | + # artifact actually being shipped. |
| 77 | + - name: test |
| 78 | + run: cargo test --locked --target "$TARGET" |
| 79 | + |
| 80 | + # Static by construction, not by flag: kuma is pure Rust with no NSS |
| 81 | + # calls and no in-process networking, so a musl build has nothing to |
| 82 | + # dynamically link. That is what lets it run on an image-based |
| 83 | + # desktop that has podman and no toolchain, which is the machine |
| 84 | + # most likely to want it. |
| 85 | + - name: build |
| 86 | + run: cargo build --locked --release --target "$TARGET" |
| 87 | + |
| 88 | + - name: package |
| 89 | + id: pkg |
| 90 | + run: | |
| 91 | + set -euo pipefail |
| 92 | + name='${{ steps.what.outputs.name }}' |
| 93 | + cp "target/${TARGET}/release/kuma" "$name" |
| 94 | + strip "$name" |
| 95 | + sha256sum "$name" > "${name}.sha256" |
| 96 | + # Prove the artifact runs before publishing it. A binary that |
| 97 | + # cannot answer --version on a clean runner is not a release. |
| 98 | + "./$name" --version |
| 99 | + echo "name=$name" >> "$GITHUB_OUTPUT" |
| 100 | +
|
| 101 | + - uses: sigstore/cosign-installer@v3 |
| 102 | + |
| 103 | + - name: sign |
| 104 | + run: | |
| 105 | + set -euo pipefail |
| 106 | + cosign sign-blob --yes \ |
| 107 | + --output-signature '${{ steps.pkg.outputs.name }}.sig' \ |
| 108 | + --output-certificate '${{ steps.pkg.outputs.name }}.pem' \ |
| 109 | + '${{ steps.pkg.outputs.name }}' |
| 110 | +
|
| 111 | + # The rolling release is one moving target, so its old assets and tag |
| 112 | + # are cleared first. Deleting the tag matters: gh reuses an existing |
| 113 | + # one and the release would keep pointing at the commit it was first |
| 114 | + # cut from. |
| 115 | + - name: clear the rolling release |
| 116 | + if: steps.what.outputs.tag == 'latest' |
| 117 | + run: | |
| 118 | + gh release delete latest --yes --cleanup-tag || true |
| 119 | + env: |
| 120 | + GH_TOKEN: ${{ github.token }} |
| 121 | + |
| 122 | + - name: publish |
| 123 | + run: | |
| 124 | + set -euo pipefail |
| 125 | + gh release create '${{ steps.what.outputs.tag }}' \ |
| 126 | + --title '${{ steps.what.outputs.title }}' \ |
| 127 | + --notes "$(cat <<'NOTES' |
| 128 | + Static `x86_64` binary, no runtime dependencies. |
| 129 | +
|
| 130 | + ```console |
| 131 | + $ curl -LO ${{ github.server_url }}/${{ github.repository }}/releases/download/${{ steps.what.outputs.tag }}/${{ steps.pkg.outputs.name }} |
| 132 | + $ chmod +x ${{ steps.pkg.outputs.name }} && sudo mv ${{ steps.pkg.outputs.name }} /usr/local/bin/kuma |
| 133 | + ``` |
| 134 | +
|
| 135 | + Verify it came from this workflow: |
| 136 | +
|
| 137 | + ```console |
| 138 | + $ cosign verify-blob \ |
| 139 | + --certificate ${{ steps.pkg.outputs.name }}.pem \ |
| 140 | + --signature ${{ steps.pkg.outputs.name }}.sig \ |
| 141 | + --certificate-identity-regexp '^${{ github.server_url }}/${{ github.repository }}/' \ |
| 142 | + --certificate-oidc-issuer https://token.actions.githubusercontent.com \ |
| 143 | + ${{ steps.pkg.outputs.name }} |
| 144 | + ``` |
| 145 | +
|
| 146 | + Built from `${{ github.sha }}`. |
| 147 | + NOTES |
| 148 | + )" \ |
| 149 | + ${{ steps.what.outputs.prerelease == 'true' && '--prerelease' || '' }} \ |
| 150 | + --target '${{ github.sha }}' \ |
| 151 | + '${{ steps.pkg.outputs.name }}' \ |
| 152 | + '${{ steps.pkg.outputs.name }}.sha256' \ |
| 153 | + '${{ steps.pkg.outputs.name }}.sig' \ |
| 154 | + '${{ steps.pkg.outputs.name }}.pem' |
| 155 | + env: |
| 156 | + GH_TOKEN: ${{ github.token }} |
0 commit comments