|
| 1 | +#==============================================================# |
| 2 | +# File : release-sign.yml |
| 3 | +# Desc : Sign GitHub release assets with Sigstore cosign |
| 4 | +# Ctime : 2026-07-09 |
| 5 | +# Mtime : 2026-07-09 |
| 6 | +# License : Apache-2.0 @ https://pigsty.io/docs/about/license |
| 7 | +# Copyright : 2018-2026 Ruohang Feng / Vonng (rh@vonng.com) |
| 8 | +#==============================================================# |
| 9 | + |
| 10 | +name: Sign Release Assets |
| 11 | + |
| 12 | +on: |
| 13 | + workflow_dispatch: |
| 14 | + inputs: |
| 15 | + tag: |
| 16 | + description: "Release tag to sign, such as v4.3.0" |
| 17 | + required: true |
| 18 | + type: string |
| 19 | + |
| 20 | +permissions: read-all |
| 21 | + |
| 22 | +jobs: |
| 23 | + sign: |
| 24 | + name: Sign assets |
| 25 | + runs-on: ubuntu-latest |
| 26 | + if: github.ref == 'refs/heads/main' |
| 27 | + permissions: |
| 28 | + contents: write |
| 29 | + id-token: write |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Install cosign |
| 33 | + uses: sigstore/cosign-installer@398d4b0eeef1380460a10c8013a76f728fb906ac # v3 |
| 34 | + with: |
| 35 | + cosign-release: v2.5.2 |
| 36 | + |
| 37 | + - name: Download release assets |
| 38 | + env: |
| 39 | + GH_TOKEN: ${{ github.token }} |
| 40 | + TAG: ${{ inputs.tag }} |
| 41 | + run: | |
| 42 | + set -euo pipefail |
| 43 | + mkdir -p dist/release-assets |
| 44 | + gh release download "${TAG}" \ |
| 45 | + --repo "${GITHUB_REPOSITORY}" \ |
| 46 | + --dir dist/release-assets \ |
| 47 | + --clobber |
| 48 | + find dist/release-assets -maxdepth 1 -type f -print | sort |
| 49 | +
|
| 50 | + - name: Sign and upload assets |
| 51 | + env: |
| 52 | + GH_TOKEN: ${{ github.token }} |
| 53 | + TAG: ${{ inputs.tag }} |
| 54 | + run: | |
| 55 | + set -euo pipefail |
| 56 | + cd dist/release-assets |
| 57 | + shopt -s nullglob |
| 58 | +
|
| 59 | + expected_identity="https://github.com/${GITHUB_REPOSITORY}/.github/workflows/release-sign.yml@refs/heads/main" |
| 60 | +
|
| 61 | + assets=() |
| 62 | + for asset in *; do |
| 63 | + [ -f "${asset}" ] || continue |
| 64 | + case "${asset}" in |
| 65 | + *.sig|*.pem|*.intoto|*.intoto.jsonl|*.bundle|*.sigstore.json) |
| 66 | + continue |
| 67 | + ;; |
| 68 | + esac |
| 69 | + assets+=("${asset}") |
| 70 | + done |
| 71 | +
|
| 72 | + if [ "${#assets[@]}" -eq 0 ]; then |
| 73 | + echo "No unsigned release assets found for ${TAG}." |
| 74 | + exit 0 |
| 75 | + fi |
| 76 | +
|
| 77 | + for asset in "${assets[@]}"; do |
| 78 | + cosign sign-blob --yes \ |
| 79 | + --output-signature "${asset}.sig" \ |
| 80 | + --output-certificate "${asset}.pem" \ |
| 81 | + "${asset}" |
| 82 | +
|
| 83 | + cosign verify-blob \ |
| 84 | + --certificate "${asset}.pem" \ |
| 85 | + --signature "${asset}.sig" \ |
| 86 | + --certificate-identity "${expected_identity}" \ |
| 87 | + --certificate-oidc-issuer "https://token.actions.githubusercontent.com" \ |
| 88 | + "${asset}" |
| 89 | + done |
| 90 | +
|
| 91 | + gh release upload "${TAG}" ./*.sig ./*.pem \ |
| 92 | + --repo "${GITHUB_REPOSITORY}" \ |
| 93 | + --clobber |
0 commit comments