1+ name : Publish release
2+
3+ description : Publish release, container image, SBOMS, signs artifacts.
4+
5+ inputs :
6+ go-version :
7+ required : true
8+ description : go version to install on the runner
9+ github_token :
10+ required : true
11+ description : github token used for the release
12+ registry_username :
13+ required : true
14+ description : Container registry username
15+ registry_password :
16+ required : true
17+ description : Container registry password
18+ registry :
19+ required : true
20+ description : registry used to publish container images
21+
22+
23+ outputs :
24+ hashes :
25+ value : ${{ steps.binary.outputs.hashes }}
26+ description : hash of the cheksum file in base64
27+ name :
28+ value : ${{ steps.image.outputs.name }}
29+ description : name of the published container image
30+ digest :
31+ value : ${{ steps.image.outputs.digest }}
32+ description : published image digest
33+
34+ runs :
35+ using : composite
36+ steps :
37+ # Install go with specific version
38+ - name : Set up Go
39+ uses : actions/setup-go@v5
40+ with :
41+ go-version : ${{ inputs.go-version }} # same version than the one in the go.mod or in the .go-version
42+ # Register to ghcr.io container Registry
43+ - name : ' Login to GitHub Container Registry'
44+ uses : docker/login-action@v1
45+ with :
46+ registry : ${{ inputs.registry}}
47+ username : ${{ inputs.registry_username }}
48+ password : ${{ inputs.registry_password }}
49+ # Install ko to publish container images
50+ - name : Set up Ko
51+ uses : ko-build/setup-ko@v0.7
52+ # Install cosign to sign artfacts with goreleaser
53+ - name : Install Cosign
54+ uses : sigstore/cosign-installer@v3.5.0
55+ # Get LDFLAGS with a makefile command
56+ - shell : bash
57+ name : Get LDFLAGS
58+ id : get_ldlflags # need to define id to pass the variable to other steps
59+ run : |
60+ echo "ldflags= $(make get-ldflags)" >> "$GITHUB_OUTPUT"
61+ # Install other dependencies like scanners and go librairies
62+ - shell : bash
63+ name : Install dependencies
64+ run : |
65+ curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
66+ curl -sSfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v0.49.1
67+ # Run command goreleaser release based on .goreleaser.yml
68+ # LDFLAGS are passed thanks to the steps.job_id.outputs.variable_name variable
69+ - name : Run GoReleaser
70+ uses : goreleaser/goreleaser-action@v5
71+ id : goreleaser
72+ with :
73+ distribution : goreleaser
74+ version : latest
75+ args : release
76+ env :
77+ GITHUB_TOKEN : ${{ inputs.github_token }}
78+ LDFLAGS : ${{steps.get_ldlflags.outputs.ldflags}}
79+ # Get artifacts from goreleaser's step outputs to generate cheksums file abse64 hashes
80+ # Provenance generator action needs to have a base64 hash for generating blobs provenance
81+ # The hash is passed as an output of goreleaser job
82+ - shell : bash
83+ name : Generate binary hashes
84+ id : binary
85+ env :
86+ ARTIFACTS : " ${{ steps.goreleaser.outputs.artifacts }}"
87+ run : |
88+ set -euo pipefail
89+ checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path')
90+ echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT"
91+ # Get artifacts from the goreleaser's step outputs to retrieve Docker Manifest containing the image and its digest
92+ # Image Provenance generator action needs to have the image name and a digest for generating provenance and publish it to the container registry
93+ - shell : bash
94+ name : Image digest
95+ id : image
96+ env :
97+ ARTIFACTS : " ${{ steps.goreleaser.outputs.artifacts }}"
98+ run : |
99+ set -euo pipefail
100+ image_and_digest=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Docker Manifest") | .path')
101+ image=$(echo "${image_and_digest}" | cut -d'@' -f1 | cut -d':' -f1)
102+ digest=$(echo "${image_and_digest}" | cut -d'@' -f2)
103+ echo "name=$image" >> "$GITHUB_OUTPUT"
104+ echo "digest=$digest" >> "$GITHUB_OUTPUT"
105+ # Sign image with cosign sign command
106+ - shell : bash
107+ name : Generate Image Signature
108+ env :
109+ # COSIGN_REPOSITORY: ghcr.io/${{github.owner}}/signatures # need to use this variable for having a dfiferent signature repository
110+ IMAGE : ${{ steps.image.outputs.name }}@${{ steps.image.outputs.digest }}
111+ run : |
112+ cosign sign --yes \
113+ ${{ env.IMAGE }}
0 commit comments