|
1 | | -name: Cut Release |
| 1 | +name: Release |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | tags: |
6 | 6 | - "v*" |
7 | 7 |
|
8 | | -concurrency: cut-release |
9 | | - |
10 | | -permissions: |
11 | | - contents: write # needed to write releases |
12 | | - id-token: write # needed for keyless signing |
13 | | - packages: write # needed for pushing the images to ghcr.io |
14 | | - |
15 | 8 | jobs: |
16 | 9 | release: |
17 | | - outputs: |
18 | | - hashes: ${{ steps.hash.outputs.hashes }} |
19 | | - tag_name: ${{ steps.tag.outputs.tag_name }} |
20 | 10 | runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + attestations: write |
| 13 | + contents: write |
| 14 | + id-token: write |
| 15 | + packages: write |
| 16 | + env: |
| 17 | + KO_DOCKER_REPO: ghcr.io/github/policy-controller-webhook |
| 18 | + KOCACHE: /tmp/ko |
21 | 19 | steps: |
22 | | - - uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1 |
| 20 | + - uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5 |
23 | 21 | with: |
24 | | - android: true |
25 | | - dotnet: true |
26 | | - haskell: true |
27 | | - large-packages: true |
28 | | - docker-images: true |
29 | | - swap-storage: true |
30 | | - |
31 | | - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
32 | | - |
33 | | - - uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 |
| 22 | + ref: "release" |
| 23 | + - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 |
34 | 24 | with: |
35 | | - go-version-file: './go.mod' |
| 25 | + go-version-file: "./go.mod" |
36 | 26 | check-latest: true |
37 | | - |
38 | | - - uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da |
39 | | - |
40 | | - - uses: anchore/sbom-action/download-syft@fc46e51fd3cb168ffb36c6d1915723c47db58abb # v0.17.7 |
41 | | - |
42 | | - - uses: ko-build/setup-ko@3aebd0597dc1e9d1a26bcfdb7cbeb19c131d3037 # v0.7 |
43 | | - |
44 | | - - name: Set up Cloud SDK |
45 | | - uses: google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f # v2.1.7 |
46 | | - with: |
47 | | - workload_identity_provider: 'projects/498091336538/locations/global/workloadIdentityPools/githubactions/providers/sigstore-policy-controller' |
48 | | - service_account: '[email protected]' |
49 | | - |
50 | | - - name: 'Set up Cloud SDK' |
51 | | - uses: google-github-actions/setup-gcloud@6189d56e4096ee891640bb02ac264be376592d6a # v2.1.2 |
52 | | - |
53 | | - - name: creds |
54 | | - run: gcloud auth configure-docker --quiet |
55 | | - |
56 | | - - name: Set LDFLAGS |
57 | | - id: ldflags |
| 27 | + - uses: ko-build/setup-ko@ace48d793556083a76f1e3e6068850c1f4a369aa # v0.6 |
| 28 | + - name: Build and publish webhook to GHCR |
| 29 | + id: build |
58 | 30 | run: | |
59 | | - source ./release/ldflags.sh |
60 | | - goflags=$(ldflags) |
61 | | - echo "GO_FLAGS="${goflags}"" >> "$GITHUB_ENV" |
62 | | -
|
63 | | - - name: Set tag output |
64 | | - id: tag |
65 | | - run: echo "tag_name=${GITHUB_REF#refs/*/}" >> "$GITHUB_OUTPUT" |
66 | | - |
67 | | - - name: Run GoReleaser |
68 | | - id: run-goreleaser |
69 | | - uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0 |
| 31 | + export GIT_HASH=`git rev-parse HEAD` |
| 32 | + export GIT_VERSION=`git describe --tags --always --dirty` |
| 33 | + export BUILD_DATE=`date +%Y-%m-%dT%H:%M:%SZ` |
| 34 | + export LDFLAGS="-buildid= -X sigs.k8s.io/release-utils/version.gitVersion=$GIT_VERSION -X sigs.k8s.io/release-utils/version.gitCommit=$GIT_HASH -X sigs.k8s.io/release-utils/version.buildDate=$BUILD_DATE" |
| 35 | +
|
| 36 | + mkdir -p ${{ env.KOCACHE }} |
| 37 | + # ko build should print ghcr.io/github/policy-controller-webhook@sha256:<digest> |
| 38 | + # to standard out. Capture the image digest for the build provenance step |
| 39 | + IMAGE_DIGEST=$(ko build --bare --tags $GIT_VERSION --tags $GIT_HASH --platform=linux/amd64 github.com/sigstore/policy-controller/cmd/webhook | cut -d'@' -f2) |
| 40 | + echo "image_digest=$IMAGE_DIGEST" >> $GITHUB_OUTPUT |
| 41 | + - name: Attest |
| 42 | + uses: actions/attest-build-provenance@951c0c5f8e375ad4efad33405ab77f7ded2358e4 # v1.1.1 |
| 43 | + id: attest |
70 | 44 | with: |
71 | | - version: latest |
72 | | - args: release --clean --timeout 120m |
73 | | - env: |
74 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
75 | | - LDFLAGS: ${{ env.GO_FLAGS }} |
76 | | - |
77 | | - - name: Generate subject |
78 | | - id: hash |
79 | | - env: |
80 | | - ARTIFACTS: "${{ steps.run-goreleaser.outputs.artifacts }}" |
81 | | - run: | |
82 | | - set -euo pipefail |
83 | | - checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path') |
84 | | - echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT" |
85 | | -
|
86 | | - - name: build images |
87 | | - run: | |
88 | | - make build-sign-release-images |
89 | | - env: |
90 | | - LDFLAGS: ${{ env.GO_FLAGS }} |
91 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
92 | | - |
93 | | - - name: copy-signed-release-to-ghcr |
94 | | - run: make copy-signed-release-to-ghcr || true |
95 | | - env: |
96 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
97 | | - |
98 | | - provenance: |
99 | | - needs: [release] |
100 | | - permissions: |
101 | | - actions: read # To read the workflow path. |
102 | | - id-token: write # To sign the provenance. |
103 | | - contents: write # To add assets to a release. |
104 | | - uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected] |
105 | | - with: |
106 | | - base64-subjects: "${{ needs.release.outputs.hashes }}" |
107 | | - upload-assets: true # upload to a new release |
108 | | - upload-tag-name: "${{ needs.release.outputs.tag_name }}" |
| 45 | + subject-name: ${{ env.KO_DOCKER_REPO }} |
| 46 | + subject-digest: ${{ steps.build.outputs.image_digest }} |
| 47 | + push-to-registry: true |
0 commit comments