2222permissions :
2323 contents : write
2424 packages : write
25+ security-events : write
2526
2627jobs :
28+ codeql-audit :
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+
36+ - uses : github/codeql-action/init@v3
37+ with :
38+ languages : actions,go
39+ - uses : github/codeql-action/analyze@v3
40+
41+ go-audit :
42+ runs-on : ubuntu-latest
43+ steps :
44+ - name : Check out code
45+ uses : actions/checkout@v5
46+
47+ - name : Install Go
48+ uses : actions/setup-go@v5
49+ with :
50+ go-version-file : go.mod
51+
52+ - name : Check Go dependencies
53+ uses : golang/govulncheck-action@v1
54+ with :
55+ go-package : ./...
56+ output-format : sarif
57+ output-file : govulncheck.sarif
58+ - name : Upload SARIF file
59+ uses : github/codeql-action/upload-sarif@v3
60+ with :
61+ sarif_file : govulncheck.sarif
62+
63+ - name : Check Go source code
64+ uses : securego/gosec@master
65+ with :
66+ args : ' -no-fail -fmt sarif -out gosec.sarif ./...'
67+ - name : Upload SARIF file
68+ uses : github/codeql-action/upload-sarif@v3
69+ with :
70+ sarif_file : gosec.sarif
71+
72+ nix-audit :
73+ runs-on : ubuntu-latest
74+ steps :
75+ - name : Check out code
76+ uses : actions/checkout@v5
77+
78+ - name : Check Nix flake inputs
79+ uses : DeterminateSystems/flake-checker-action@main
80+ with :
81+ send-statistics : false
82+
2783 build-go :
84+ needs : [ codeql-audit, go-audit, nix-audit ]
2885 runs-on : ubuntu-latest
2986 strategy :
3087 matrix :
@@ -68,8 +125,10 @@ jobs:
68125 with :
69126 name : multigres-operator-${{matrix.arch}}
70127 path : dist/*
128+ if-no-files-found : error
129+ retention-days : 7
71130
72- build-push- container :
131+ build-container :
73132 needs : [ build-go ]
74133 runs-on : ubuntu-latest
75134 steps :
@@ -82,13 +141,6 @@ jobs:
82141 - name : Setup Docker buildx
83142 uses : docker/setup-buildx-action@v3
84143
85- - name : Log into registry
86- uses : docker/login-action@v3
87- with :
88- registry : ghcr.io
89- username : ${{ github.actor }}
90- password : ${{ secrets.GITHUB_TOKEN }}
91-
92144 - name : Extract container metadata
93145 id : meta
94146 uses : docker/metadata-action@v5
@@ -106,22 +158,71 @@ jobs:
106158 pattern : multigres-operator-*
107159 path : dist/
108160
109- - name : Build and push container image
110- id : build-and-push
161+ - name : Build container image
111162 uses : docker/build-push-action@v5
112163 with :
113164 context : .
114165 file : Containerfile
115166 platforms : linux/${{ join(fromJson(inputs.architectures), ',linux/') }}
116- push : ${{ inputs.push-container-image }}
167+ push : false
117168 tags : ${{ steps.meta.outputs.tags }}
118169 labels : ${{ steps.meta.outputs.labels }}
119170 provenance : false
120171 cache-from : type=gha
121172 cache-to : type=gha,mode=max
173+ outputs : type=docker,dest=container-image.tar
174+
175+ - name : Upload image artifact
176+ uses : actions/upload-artifact@v4
177+ with :
178+ name : container-image-tar
179+ path : container-image.tar
180+ if-no-files-found : error
181+ retention-days : 7
182+
183+ container-audit :
184+ needs : [ build-container ]
185+ runs-on : ubuntu-latest
186+ steps :
187+ - name : Scan image
188+ uses : anchore/scan-action@v6
189+ with :
190+ image : " ghcr.io/${{ github.repository }}:${{ github.sha }}"
191+
192+ push-container :
193+ needs : [ container-audit ]
194+ runs-on : ubuntu-latest
195+ if : ${{ inputs.push-container-image }}
196+ steps :
197+ - name : Download image artifact
198+ uses : actions/download-artifact@v4
199+ with :
200+ name : container-image-tar
201+ path : .
202+
203+ - name : Log into registry
204+ uses : docker/login-action@v3
205+ with :
206+ registry : ghcr.io
207+ username : ${{ github.actor }}
208+ password : ${{ secrets.GITHUB_TOKEN }}
209+
210+ - name : Push to registry
211+ run : |
212+ IMAGE="ghcr.io/${{ github.repository }}"
213+ docker load --input container-image.tar
214+ docker push "$IMAGE:${{ github.sha }}"
215+ if [ "${{ github.ref }}" = "refs/heads/main" ]; then
216+ docker tag "$IMAGE:${{ github.sha }}" "$IMAGE:latest"
217+ docker push "$IMAGE:latest"
218+ fi
219+ if [ "${{ github.ref_type }}" = "tag" ]; then
220+ docker tag "$IMAGE:${{ github.sha }}" "$IMAGE:${{ github.ref_name }}"
221+ docker push "$IMAGE:${{ github.ref_name }}"
222+ fi
122223
123224 create-release :
124- needs : [ build-go ]
225+ needs : [ container-audit ]
125226 runs-on : ubuntu-latest
126227 if : ${{ inputs.create-release }}
127228 steps :
0 commit comments