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 Nix flake inputs
76+ uses : DeterminateSystems/flake-checker-action@main
77+ with :
78+ send-statistics : false
79+
2780 build-go :
81+ needs : [ codeql-audit, go-audit, nix-audit ]
2882 runs-on : ubuntu-latest
2983 strategy :
3084 matrix :
@@ -68,8 +122,10 @@ jobs:
68122 with :
69123 name : multigres-operator-${{matrix.arch}}
70124 path : dist/*
125+ if-no-files-found : error
126+ retention-days : 7
71127
72- build-push- container :
128+ build-container :
73129 needs : [ build-go ]
74130 runs-on : ubuntu-latest
75131 steps :
@@ -82,13 +138,6 @@ jobs:
82138 - name : Setup Docker buildx
83139 uses : docker/setup-buildx-action@v3
84140
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-
92141 - name : Extract container metadata
93142 id : meta
94143 uses : docker/metadata-action@v5
@@ -106,22 +155,67 @@ jobs:
106155 pattern : multigres-operator-*
107156 path : dist/
108157
109- - name : Build and push container image
110- id : build-and-push
158+ - name : Build container image
111159 uses : docker/build-push-action@v5
112160 with :
113161 context : .
114162 file : Containerfile
115163 platforms : linux/${{ join(fromJson(inputs.architectures), ',linux/') }}
116- push : ${{ inputs.push-container-image }}
164+ push : false
117165 tags : ${{ steps.meta.outputs.tags }}
118166 labels : ${{ steps.meta.outputs.labels }}
119167 provenance : false
120168 cache-from : type=gha
121169 cache-to : type=gha,mode=max
170+ outputs : type=docker,dest=container-image.tar
171+
172+ - name : Upload image artifact
173+ uses : actions/upload-artifact@v4
174+ with :
175+ name : container-image-tar
176+ path : container-image.tar
177+ if-no-files-found : error
178+ retention-days : 7
179+
180+ container-audit :
181+ needs : [ build-container ]
182+ runs-on : ubuntu-latest
183+ steps : []
184+
185+ push-container :
186+ needs : [ container-audit ]
187+ runs-on : ubuntu-latest
188+ if : ${{ inputs.push-container-image }}
189+ steps :
190+ - name : Download image artifact
191+ uses : actions/download-artifact@v4
192+ with :
193+ name : container-image-tar
194+ path : .
195+
196+ - name : Log into registry
197+ uses : docker/login-action@v3
198+ with :
199+ registry : ghcr.io
200+ username : ${{ github.actor }}
201+ password : ${{ secrets.GITHUB_TOKEN }}
202+
203+ - name : Push to registry
204+ run : |
205+ IMAGE="ghcr.io/${{ github.repository }}"
206+ docker load --input container-image.tar
207+ docker push "$IMAGE:${{ github.sha }}"
208+ if [ "${{ github.ref }}" = "refs/heads/main" ]; then
209+ docker tag "$IMAGE:${{ github.sha }}" "$IMAGE:latest"
210+ docker push "$IMAGE:latest"
211+ fi
212+ if [ "${{ github.ref_type }}" = "tag" ]; then
213+ docker tag "$IMAGE:${{ github.sha }}" "$IMAGE:${{ github.ref_name }}"
214+ docker push "$IMAGE:${{ github.ref_name }}"
215+ fi
122216
123217 create-release :
124- needs : [ build-go ]
218+ needs : [ container-audit ]
125219 runs-on : ubuntu-latest
126220 if : ${{ inputs.create-release }}
127221 steps :
0 commit comments