-
Notifications
You must be signed in to change notification settings - Fork 236
223 lines (190 loc) · 6.8 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: Release
on:
pull_request_target:
types:
- closed
branches:
- master
- main
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
permissions:
contents: write
packages: write
security-events: write
env:
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
PULL_REQUEST_BRANCH: ${{ github.head_ref }}
BRANCH: ${{ github.event.pull_request.head.ref }}
REGISTRY: ghcr.io
IMAGE_NAME: "ghcr.io/${{ github.repository }}"
RELEASE: true
jobs:
config:
if: github.triggering_actor != 'dependabot[bot]' && github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
go-version: ${{ fromJson(steps.config.outputs.config).go-version }}
deploy-pull-request: ${{ fromJson(steps.config.outputs.config).deploy.pull-request }}
deploy-sign-docker-image: ${{ fromJson(steps.config.outputs.config).deploy.sign-docker-image }}
deploy-pre-release-matrix: ${{ steps.pre-release-matrix.outputs.matrix }}
deploy-release-matrix: ${{ steps.release-matrix.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Read config
id: config
run: echo "config=$(jq -M -c '.' ./.github/workflow-config.json)" >> $GITHUB_OUTPUT
- name: List Pre-release profiles
id: deploy-pr-images-profiles
run: echo "profiles=$(jq -c -M '.deploy."pull-request-images"' .github/workflow-config.json)" >> $GITHUB_OUTPUT
- name: Deploy pre-release matrix
id: pre-release-matrix
run: echo 'matrix={"include":${{ steps.deploy-pr-images-profiles.outputs.profiles }} }' >> $GITHUB_OUTPUT
- name: List release profiles
id: deploy-images-profiles
run: echo "profiles=$(jq -c -M '.deploy."release-images"' .github/workflow-config.json)" >> $GITHUB_OUTPUT
- name: Deploy release matrix
id: release-matrix
run: echo 'matrix={"include":${{ steps.deploy-images-profiles.outputs.profiles }} }' >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs:
- config
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Golang
uses: actions/setup-go@v3
with:
go-version: ${{ needs.config.outputs.go-version }}
- name: Get makefile versions
id: version
run: |
version=$(make version)
echo "version=$version" >> $GITHUB_OUTPUT
- name: Setup Golang cache
uses: actions/cache@v3
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build artifact
run: make go-build
- name: Run test
run: make go-test
- name: Go lint
continue-on-error: true
uses: golangci/golangci-lint-action@v3
with:
args: --issues-exit-code=0
skip-pkg-cache: true
skip-build-cache: true
- name: Package artifact
run: |
mv dist/*.tar.gz application.tar.gz
- name: Upload build output
uses: actions/upload-artifact@v3
with:
name: application
path: "./application.tar.gz"
- name: Upload test coverage
uses: actions/upload-artifact@v3
with:
name: test-coverage
path: "./test-coverage.out"
release:
runs-on: ubuntu-latest
needs:
- config
- build
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set release version
id: version
run: echo "version=${{ needs.build.outputs.version }}" >> $GITHUB_OUTPUT
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: application
path: "."
- name: Rename artifact
run: mv application.tar.gz ${{ github.event.repository.name }}.tar.gz
- name: Create release
uses: softprops/action-gh-release@v1
id: create-release
with:
name: Release ${{ steps.version.outputs.version }}
tag_name: ${{ steps.version.outputs.version }}
token: ${{ secrets.GITHUB_TOKEN }}
body: ${{ steps.changelog.outputs.changelog }}
files: |
./${{ github.event.repository.name }}.tar.gz
draft: false
prerelease: false
generate_release_notes: true
deploy:
name: deploy-[${{ matrix.name }}]
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix: ${{ fromJson(needs.config.outputs.deploy-release-matrix) }}
if: ${{ !failure() && needs.release.result == 'success' && needs.config.outputs.deploy-pull-request == 'true' }}
needs:
- config
- build
- release
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${{ env.REGISTRY }} -u $ --password-stdin
- name: Build image
id: docker-meta
env:
VERSION: "${{ needs.release.outputs.version }}"
run: |
make ${{ matrix.name }}-image
TAG_SUFFIX=$(echo "-${{ matrix.name }}" | sed s/-ubuntu//)
echo "image-id=$IMAGE_NAME" >> $GITHUB_OUTPUT
echo "image-version=${VERSION}${TAG_SUFFIX}" >> $GITHUB_OUTPUT
make push-${{ matrix.name }}-image
- name: Setup cosign
if: ${{ needs.config.outputs.deploy-sign-docker-image == 'true' }}
uses: sigstore/cosign-installer@main
- name: Write signing key to disk (only needed for `cosign sign --key`)
if: ${{ needs.config.outputs.deploy-sign-docker-image == 'true' }}
continue-on-error: true
run: echo "${{ secrets.SIGNING_SECRET }}" > cosign.key
- name: Sign the published Docker image
if: ${{ needs.config.outputs.deploy-sign-docker-image == 'true' }}
continue-on-error: true
env:
COSIGN_PASSWORD: ""
VERSION: "${{ needs.release.outputs.version }}"
run: make sign-${{ matrix.name }}-image
- name: Container scan
uses: aquasecurity/[email protected]
env:
image-ref: "${{ steps.docker-meta.outputs.image-id }}:${{ steps.docker-meta.outputs.image-version }}"
with:
image-ref: "${{ env.image-ref }}"
ignore-unfixed: true
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
format: "sarif"
output: "trivy-results.sarif"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: "trivy-results.sarif"
category: trivy-${{ matrix.name }}