From 67cf80dceb602a3dc787496c24cd19e0445c1550 Mon Sep 17 00:00:00 2001 From: lectrical <14344693+lectrical@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:43:44 +0000 Subject: [PATCH] workflows: actions/attest-build-provenance Provide Github provenance for release assets cretaed during a workflow. --- .github/workflows/ci.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d599d36753..33c9b80947 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -294,6 +294,9 @@ jobs: docker: runs-on: ubuntu-latest permissions: + id-token: write + contents: read + attestations: write packages: write needs: linux steps: @@ -329,7 +332,8 @@ jobs: id: metadata with: images: ghcr.io/${{ github.repository }} - tags: ${{ startsWith(github.ref, 'refs/tags/jq-') + tags: > + ${{ startsWith(github.ref, 'refs/tags/jq-') && format('type=match,pattern=jq-(.*),group=1,value={0}', github.ref_name) || 'type=sha,format=long' }} - name: Set up QEMU @@ -344,6 +348,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and release Docker image uses: docker/build-push-action@v6 + id: build-push with: context: . push: ${{ startsWith(github.ref, 'refs/tags/jq-') }} @@ -351,11 +356,20 @@ jobs: platforms: linux/386,linux/amd64,linux/arm64,linux/mips64le,linux/ppc64le,linux/riscv64,linux/s390x tags: ${{ steps.metadata.outputs.tags }} labels: ${{ steps.metadata.outputs.labels }} + - name: attest-build-provenance + if: startsWith(github.ref, 'refs/tags/') + uses: actions/attest-build-provenance@v2 + with: + subject-name: ghcr.io/${{ github.repository }} + subject-digest: ${{ steps.build-push.outputs.digest }} + push-to-registry: true release: runs-on: ubuntu-latest permissions: contents: write + id-token: write + attestations: write pull-requests: write environment: release needs: [linux, macos, windows, dist, docker] @@ -378,6 +392,10 @@ jobs: sha256sum jq-* > sha256sum.txt gh release create "$TAG_NAME" --draft --title "jq ${TAG_NAME#jq-}" --generate-notes gh release upload "$TAG_NAME" --clobber jq-* sha256sum.txt + - name: attest-build-provenance + uses: actions/attest-build-provenance@v2 + with: + subject-path: jq-* - name: Import GPG key uses: crazy-max/ghaction-import-gpg@v6 with: