2222permissions :
2323 contents : write
2424 packages : write
25+ security-events : write
2526
2627jobs :
28+ scan-dependencies :
29+ runs-on : ubuntu-latest
30+ steps :
31+ - name : Check out code
32+ uses : actions/checkout@v5
33+
34+ - uses : actions/dependency-review-action@v4
35+ # this action requires a base and head
36+ if : ${{ github.event_name == 'pull_request' }}
37+
38+ scan-codeql :
39+ runs-on : ubuntu-latest
40+ steps :
41+ - name : Check out code
42+ uses : actions/checkout@v5
43+
44+ - uses : github/codeql-action/init@v3
45+ with :
46+ languages : actions,go
47+ - uses : github/codeql-action/analyze@v3
48+
49+ scan-nix :
50+ runs-on : ubuntu-latest
51+ steps :
52+ - name : Check out code
53+ uses : actions/checkout@v5
54+
55+ - name : Check Nix flake inputs
56+ uses : DeterminateSystems/flake-checker-action@main
57+ with :
58+ send-statistics : false
59+
2760 build-go :
61+ needs : [ scan-dependencies, scan-codeql, scan-nix ]
2862 runs-on : ubuntu-latest
2963 strategy :
3064 matrix :
68102 with :
69103 name : multigres-operator-${{matrix.arch}}
70104 path : dist/*
105+ if-no-files-found : error
106+ retention-days : 7
71107
72108 build-push-container :
73109 needs : [ build-go ]
@@ -79,49 +115,85 @@ jobs:
79115 - name : Set up QEMU
80116 uses : docker/setup-qemu-action@v3
81117
118+ - name : Set up Docker for multi-platform
119+ uses : docker/setup-docker-action@v4
120+ with :
121+ daemon-config : |
122+ {
123+ "debug": true,
124+ "features": {
125+ "containerd-snapshotter": true
126+ }
127+ }
128+
82129 - name : Setup Docker buildx
83130 uses : docker/setup-buildx-action@v3
84131
132+ - uses : actions/download-artifact@v5
133+ with :
134+ pattern : multigres-operator-*
135+ path : dist/
136+
85137 - name : Log into registry
138+ if : ${{ inputs.push-container-image }}
86139 uses : docker/login-action@v3
87140 with :
88141 registry : ghcr.io
89142 username : ${{ github.actor }}
90143 password : ${{ secrets.GITHUB_TOKEN }}
91144
92- - name : Extract container metadata
93- id : meta
94- uses : docker/metadata-action@v5
95- with :
96- github-token : ${{ secrets.GITHUB_TOKEN }}
97- images : ghcr.io/${{ github.repository }}
98- tags : |
99- type=ref,event=branch,prefix=
100- type=ref,event=tag,prefix=
101- type=sha,format=short,prefix=
102- type=sha,format=long,prefix=
103-
104- - uses : actions/download-artifact@v5
105- with :
106- pattern : multigres-operator-*
107- path : dist/
108-
109- - name : Build and push container image
110- id : build-and-push
145+ - name : Build container image
111146 uses : docker/build-push-action@v5
112147 with :
113148 context : .
114149 file : Containerfile
115150 platforms : linux/${{ join(fromJson(inputs.architectures), ',linux/') }}
116- push : ${{ inputs.push-container-image }}
117- tags : ${{ steps.meta.outputs.tags }}
118- labels : ${{ steps.meta.outputs.labels }}
151+ load : true
152+ push : false
153+ tags : " ghcr.io/ ${{ github.repository }}:${{ github.sha }}"
119154 provenance : false
120155 cache-from : type=gha
121156 cache-to : type=gha,mode=max
157+ outputs : type=oci,dest=container-image.tar
158+
159+ - name : Push to registry (sha)
160+ run : |
161+ IMAGE="ghcr.io/${{ github.repository }}"
162+ docker push "$IMAGE:${{ github.sha }}"
163+
164+ # grype requires that the container image be pushed already because
165+ # the scanner runs in a container with a different local registry
166+ - name : Scan image with grype
167+ if : ${{ inputs.push-container-image }}
168+ id : scan
169+ uses : anchore/scan-action@v6
170+ continue-on-error : true
171+ with :
172+ image : " ghcr.io/${{ github.repository }}:${{ github.sha }}"
173+ cache-db : true
174+ - name : Upload SARIF file
175+ uses : github/codeql-action/upload-sarif@v3
176+ with :
177+ sarif_file : ${{ steps.scan.outputs.sarif }}
178+ - name : Success
179+ if : ${{ steps.scan.outcome == 'failure' }}
180+ run : exit 1
181+
182+ - name : Push to registry (proper)
183+ if : ${{ inputs.push-container-image }}
184+ run : |
185+ IMAGE="ghcr.io/${{ github.repository }}"
186+ if [ "${{ github.ref }}" = "refs/heads/main" ]; then
187+ docker tag "$IMAGE:${{ github.sha }}" "$IMAGE:latest"
188+ docker push "$IMAGE:latest"
189+ fi
190+ if [ "${{ github.ref_type }}" = "tag" ]; then
191+ docker tag "$IMAGE:${{ github.sha }}" "$IMAGE:${{ github.ref_name }}"
192+ docker push "$IMAGE:${{ github.ref_name }}"
193+ fi
122194
123195 create-release :
124- needs : [ build-go ]
196+ needs : [ scan-container ]
125197 runs-on : ubuntu-latest
126198 if : ${{ inputs.create-release }}
127199 steps :
0 commit comments