|
| 1 | +# Attested source release for zircote/.github. |
| 2 | +# |
| 3 | +# This repo preaches attested delivery, so its own releases are attested: a |
| 4 | +# deterministic source bundle, a SLSA build-provenance attestation signed by |
| 5 | +# THIS workflow's OIDC identity, and a fail-closed self-verify. Consumers keep |
| 6 | +# pinning reusable workflows/actions by 40-char SHA; tags + Releases give them a |
| 7 | +# human-readable changelog and a verifiable artifact per release. |
| 8 | +# |
| 9 | +# Cut a release: |
| 10 | +# git tag v1.2.0 && git push origin v1.2.0 |
| 11 | +# or run this workflow manually (workflow_dispatch) against an existing tag. |
| 12 | +# Verify a release artifact: see RELEASING.md. |
| 13 | + |
| 14 | +name: release |
| 15 | + |
| 16 | +on: |
| 17 | + push: |
| 18 | + tags: |
| 19 | + # GitHub Actions tag filters are glob, not regex. These coarse globs match |
| 20 | + # any vX.Y.Z[-pre]; the job's first step validates strict semver. |
| 21 | + - 'v*.*.*' # stable, e.g. v1.2.0 |
| 22 | + - 'v*.*.*-*' # prerelease, e.g. v1.2.0-rc.1 |
| 23 | + workflow_dispatch: |
| 24 | + inputs: |
| 25 | + tag: |
| 26 | + description: 'Existing semver tag to (re)release, e.g. v1.2.0' |
| 27 | + required: true |
| 28 | + type: string |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: read |
| 32 | + |
| 33 | +concurrency: |
| 34 | + group: release-${{ github.ref_name }} |
| 35 | + cancel-in-progress: false |
| 36 | + |
| 37 | +jobs: |
| 38 | + release: |
| 39 | + name: Attested source release |
| 40 | + runs-on: ubuntu-latest |
| 41 | + permissions: |
| 42 | + contents: write # create the GitHub Release, read the tag |
| 43 | + id-token: write # OIDC for keyless Sigstore signing |
| 44 | + attestations: write # write the build-provenance attestation |
| 45 | + steps: |
| 46 | + - name: Resolve and validate tag |
| 47 | + id: tag |
| 48 | + env: |
| 49 | + EVENT: ${{ github.event_name }} |
| 50 | + REF_NAME: ${{ github.ref_name }} |
| 51 | + DISPATCH_TAG: ${{ inputs.tag }} |
| 52 | + run: | |
| 53 | + if [ "$EVENT" = "workflow_dispatch" ]; then |
| 54 | + TAG="$DISPATCH_TAG" |
| 55 | + else |
| 56 | + TAG="$REF_NAME" |
| 57 | + fi |
| 58 | + # Fail closed on anything that is not vMAJOR.MINOR.PATCH[-prerelease]. |
| 59 | + if ! printf '%s' "$TAG" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then |
| 60 | + echo "::error::Tag '$TAG' is not semver (expected vX.Y.Z or vX.Y.Z-pre)" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + PRERELEASE=false |
| 64 | + case "$TAG" in *-*) PRERELEASE=true ;; esac |
| 65 | + { |
| 66 | + echo "tag=$TAG" |
| 67 | + echo "version=${TAG#v}" |
| 68 | + echo "prerelease=$PRERELEASE" |
| 69 | + } >> "$GITHUB_OUTPUT" |
| 70 | +
|
| 71 | + - name: Checkout at tag |
| 72 | + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 73 | + with: |
| 74 | + ref: ${{ steps.tag.outputs.tag }} |
| 75 | + fetch-depth: 0 |
| 76 | + fetch-tags: true |
| 77 | + |
| 78 | + - name: Build deterministic source bundle |
| 79 | + id: bundle |
| 80 | + env: |
| 81 | + TAG: ${{ steps.tag.outputs.tag }} |
| 82 | + VERSION: ${{ steps.tag.outputs.version }} |
| 83 | + run: | |
| 84 | + ARTIFACT="zircote-github-${VERSION}.tar.gz" |
| 85 | + # git archive is reproducible: same tree -> identical bytes/digest. |
| 86 | + git archive --format=tar.gz --prefix="zircote-github-${VERSION}/" \ |
| 87 | + -o "$ARTIFACT" "$TAG" |
| 88 | + sha256sum "$ARTIFACT" | tee "$ARTIFACT.sha256" |
| 89 | + echo "artifact=$ARTIFACT" >> "$GITHUB_OUTPUT" |
| 90 | +
|
| 91 | + - name: Attest build provenance |
| 92 | + uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0 |
| 93 | + with: |
| 94 | + subject-path: ${{ steps.bundle.outputs.artifact }} |
| 95 | + |
| 96 | + - name: Create GitHub Release |
| 97 | + env: |
| 98 | + GH_TOKEN: ${{ github.token }} |
| 99 | + REPO: ${{ github.repository }} |
| 100 | + TAG: ${{ steps.tag.outputs.tag }} |
| 101 | + ARTIFACT: ${{ steps.bundle.outputs.artifact }} |
| 102 | + PRERELEASE: ${{ steps.tag.outputs.prerelease }} |
| 103 | + run: | |
| 104 | + PRE_FLAG="" |
| 105 | + [ "$PRERELEASE" = "true" ] && PRE_FLAG="--prerelease" |
| 106 | + # Idempotent: a re-dispatch against an existing tag refreshes the |
| 107 | + # release assets instead of failing on an already-published release. |
| 108 | + if gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then |
| 109 | + echo "Release $TAG already exists; refreshing assets." |
| 110 | + gh release upload "$TAG" "$ARTIFACT" "$ARTIFACT.sha256" \ |
| 111 | + --repo "$REPO" --clobber |
| 112 | + else |
| 113 | + gh release create "$TAG" \ |
| 114 | + --repo "$REPO" \ |
| 115 | + --title "$TAG" \ |
| 116 | + --generate-notes \ |
| 117 | + --verify-tag \ |
| 118 | + $PRE_FLAG \ |
| 119 | + "$ARTIFACT" "$ARTIFACT.sha256" |
| 120 | + fi |
| 121 | +
|
| 122 | + - name: Verify the attestation (fail-closed dogfood) |
| 123 | + env: |
| 124 | + GH_TOKEN: ${{ github.token }} |
| 125 | + REPO: ${{ github.repository }} |
| 126 | + ARTIFACT: ${{ steps.bundle.outputs.artifact }} |
| 127 | + run: | |
| 128 | + SIGNER="${REPO}/.github/workflows/release.yml" |
| 129 | + # Tolerate brief attestation-index propagation, but fail closed. |
| 130 | + for attempt in 1 2 3 4 5; do |
| 131 | + if gh attestation verify "$ARTIFACT" \ |
| 132 | + --repo "$REPO" --signer-workflow "$SIGNER"; then |
| 133 | + echo "Attestation verified on attempt $attempt." |
| 134 | + exit 0 |
| 135 | + fi |
| 136 | + echo "Not yet verifiable (attempt $attempt); retrying in 10s..." |
| 137 | + sleep 10 |
| 138 | + done |
| 139 | + echo "::error::Attestation did not verify — refusing to leave an unverified release." |
| 140 | + exit 1 |
0 commit comments