ci: Add a workflow to delete old packages. #738
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: release | |
on: | |
# Test that it works on pull_request or merge group; | |
# goreleaser goes into snapshot mode if not a tag; | |
# docker image will be built but not pushed for pull requests or merge group events. | |
pull_request: | |
merge_group: | |
push: | |
tags: | |
- v* | |
jobs: | |
goreleaser: | |
runs-on: ubuntu-latest | |
permissions: | |
# goreleaser writes to the releases api | |
contents: write | |
# docker writes packages to container registry | |
packages: write | |
env: | |
flags: "" | |
outputs: | |
hashes: ${{ steps.hash.outputs.hashes }} | |
steps: | |
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }} | |
run: echo "flags=--snapshot" >> $GITHUB_ENV | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- run: git fetch --force --tags | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
cache: true | |
- uses: docker/[email protected] | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: goreleaser/goreleaser-action@v5 | |
id: run-goreleaser | |
with: | |
version: latest | |
args: release --clean ${{ env.flags }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Generate subject | |
id: hash | |
env: | |
ARTIFACTS: "${{ steps.run-goreleaser.outputs.artifacts }}" | |
run: | | |
set -euo pipefail | |
hashes=$(echo $ARTIFACTS | jq --raw-output '.[] | {name, "digest": (.extra.Digest // .extra.Checksum)} | select(.digest) | {digest} + {name} | join(" ") | sub("^sha256:";"")' | base64 -w0) | |
echo "hashes=$hashes" >> $GITHUB_OUTPUT | |
provenance: | |
needs: [goreleaser] | |
permissions: | |
actions: read # To read the workflow path. | |
id-token: write # To sign the provenance. | |
contents: write # To add assets to a release. | |
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected] | |
with: | |
base64-subjects: "${{ needs.goreleaser.outputs.hashes }}" | |
upload-assets: true # upload to a new release | |
verify: | |
needs: [goreleaser, provenance] | |
if: ${{ startsWith(github.ref, 'refs/tags/v') }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read # Download release assets | |
env: | |
CHECKSUMS: ${{ needs.goreleaser.outputs.hashes }} | |
PROVENANCE: "${{ needs.provenance.outputs.provenance-name }}" | |
steps: | |
- uses: slsa-framework/slsa-verifier/actions/[email protected] | |
- name: download assets | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
set -euo pipefail | |
gh release download "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" | |
- name: verify assets | |
run: | | |
set -euo pipefail | |
checksums=$(echo "$CHECKSUMS" | base64 -d) | |
while read -r line; do | |
fn=$(echo $line | cut -d ' ' -f2) | |
echo "Verifying $fn" | |
slsa-verifier verify-artifact --provenance-path "$PROVENANCE" \ | |
--source-uri "github.com/$GITHUB_REPOSITORY" \ | |
--source-tag "$GITHUB_REF_NAME" \ | |
"$fn" | |
done <<<"$checksums" |