-
Notifications
You must be signed in to change notification settings - Fork 1.2k
275 lines (267 loc) · 9.34 KB
/
cut-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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
---
name: Release
on:
push:
tags:
- v4.*
workflow_dispatch: {}
jobs:
config:
name: Config
runs-on: 'ubuntu-latest'
strategy:
matrix:
image: ['quay.io/projectquay/golang:1.20']
container:
image: ${{ matrix.image }}
outputs:
version: ${{ steps.setup.outputs.version }}
tar_prefix: ${{ steps.setup.outputs.tar_prefix }}
is_prerelease: ${{ startsWith(github.ref, 'refs/tags/') && (contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc')) }}
image_tag: ${{ steps.setup.outputs.image_tag }}
image_repo: ${{ steps.setup.outputs.image_repo }}
build_image: ${{ steps.setup.outputs.build_image }}
build_go_version: ${{ steps.setup.outputs.build_go_version }}
build_cache_key: ${{ steps.setup.outputs.cache_key }}
chglog_version: ${{ '0.15.1' }}
steps:
- name: Setup
id: setup
run: |
: "${tag:="$(basename "${GITHUB_REF}")"}"
: "${repo:=$GITHUB_REPOSITORY}"
test "${GITHUB_REPOSITORY_OWNER}" = quay && repo="projectquay/${GITHUB_REPOSITORY##*/}" ||:
cat <<. >>"$GITHUB_OUTPUT"
version=$tag
tar_prefix=clair-${tag}/
image_tag=${tag#v}
image_repo=${repo}
build_image=${{ matrix.image }}
build_go_version=$(go version | cut -f 3 -d ' ' | sed 's/^go//;s/\.[0-9]\+$//')
cache_key=$(go version | md5sum - | cut -f 1 -d ' ')
.
release-archive:
name: Create Release Archive
runs-on: 'ubuntu-latest'
needs: [config]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ./.github/actions/go-cache
with:
go: ${{ needs.config.outputs.build_go_version }}
- name: Create Release Archive
run: |
# Fix the checkout action overwriting the tag: (see https://github.com/actions/checkout/issues/882)
git fetch origin "+${GITHUB_REF}:${GITHUB_REF}"
git archive --prefix '${{ needs.config.outputs.tar_prefix }}' -o clair.tar "${GITHUB_REF}"
go mod vendor
tar -rf clair.tar --transform 's,^,${{ needs.config.outputs.tar_prefix }},' vendor
gzip clair.tar
mv clair.tar.gz clair-${{ needs.config.outputs.version }}.tar.gz
- name: Cache Changelog
uses: actions/cache@v3
id: chglog-cache
if: github.event_name != 'workflow_dispatch'
with:
path: /usr/local/bin/git-chglog
key: changelog-${{ needs.config.outputs.chglog_version }}
- name: Fetch Changelog
if: steps.chglog-cache.outputs.cache-hit != 'true' && github.event_name != 'workflow_dispatch'
run: |
cd "$RUNNER_TEMP"
v="${{ needs.config.outputs.chglog_version }}"
f="git-chglog_${v}_linux_amd64.tar.gz"
curl -fsOSL "https://github.com/git-chglog/git-chglog/releases/download/v${v}/${f}"
tar xvf "${f}"
install git-chglog /usr/local/bin
- name: Generate changelog
shell: bash
if: github.event_name != 'workflow_dispatch'
run: |
v="${{ needs.config.outputs.version }}"
echo "creating change log for tag: ${v}"
git-chglog "${v}" > changelog
- name: Fake changelog
if: github.event_name == 'workflow_dispatch'
run: touch changelog
- name: Upload Release Archive
uses: actions/upload-artifact@v3
with:
name: release
path: |
clair-${{ needs.config.outputs.version }}.tar.gz
changelog
if-no-files-found: error
release-binaries:
name: Create Release Binaries
runs-on: 'ubuntu-latest'
container: ${{ needs.config.outputs.build_image }}
needs: [config, release-archive]
strategy:
matrix:
goarch: ['arm64', 'amd64', '386', 'ppc64le', 's390x']
goos: ['linux', 'windows', 'darwin']
exclude:
- goos: darwin
goarch: '386'
- goos: darwin
goarch: arm64
- goos: windows
goarch: '386'
- goos: windows
goarch: 'ppc64le'
- goos: darwin
goarch: 'ppc64le'
- goos: windows
goarch: 's390x'
- goos: darwin
goarch: 's390x'
env:
GOOS: ${{matrix.goos}}
GOARCH: ${{matrix.goarch}}
steps:
- name: Fetch Artifacts
uses: actions/download-artifact@v3
id: download
with:
name: release
- name: Unpack
run: |
tar -xz -f ${{steps.download.outputs.download-path}}/clair-${{ needs.config.outputs.version }}.tar.gz --strip-components=1
- uses: actions/setup-go@v4
with:
go-version: ${{ needs.config.outputs.build_go_version }}
- name: Build
# Build with path trimming, ELF debug stripping, and no VCS injection (should be done by the `git archive` process).
run: |
go build\
-trimpath -ldflags="-s -w" -buildvcs=false\
-o "clairctl-${{matrix.goos}}-${{matrix.goarch}}"\
./cmd/clairctl
- name: Upload
uses: actions/upload-artifact@v3
with:
name: release
path: clairctl-${{matrix.goos}}-${{matrix.goarch}}
if-no-files-found: error
- name: Create Artifact on Failure
uses: actions/upload-artifact@v3
if: failure()
with:
name: workspace-${{matrix.goos}}-${{matrix.goarch}}
path: ${{ github.workspace }}
release:
name: Release
runs-on: 'ubuntu-latest'
if: github.event_name == 'push'
needs: [config, release-archive, release-binaries]
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Fetch Artifacts
uses: actions/download-artifact@v3
id: download
with:
name: release
- name: Create Release
uses: ncipollo/release-action@v1
id: create_release
with:
name: ${{ needs.config.outputs.version }} Release
bodyFile: ${{steps.download.outputs.download-path}}/changelog
prerelease: ${{ needs.config.outputs.is_prerelease }}
artifacts: '${{steps.download.outputs.download-path}}/clair-*'
publish-container:
name: Publish Container
runs-on: 'ubuntu-latest'
needs: [config, release-archive, release]
steps:
- name: Fetch Artifacts
uses: actions/download-artifact@v3
id: download
with:
name: release
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Extract Release
run: |
mkdir "${{ runner.temp }}/build"
tar -xz -f ${{steps.download.outputs.download-path}}/clair-${{ needs.config.outputs.version }}.tar.gz --strip-components=1 -C "${{ runner.temp }}/build"
- name: Build Container
uses: docker/build-push-action@v4
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: ${{ runner.temp }}/build
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
push: true
tags: |
quay.io/${{ needs.config.outputs.image_repo }}:${{ needs.config.outputs.image_tag }}
- name: Checkout
if: needs.config.outputs.is_prerelease == 'true'
uses: actions/checkout@v3
- name: Set Expiration
if: needs.config.outputs.is_prerelease == 'true'
uses: ./.github/actions/set-image-expiration
with:
repo: ${{ needs.config.outputs.image_repo }}
tag: ${{ needs.config.outputs.image_tag }}
token: ${{ secrets.QUAY_API_TOKEN }}
publish-binaries:
name: Publish Binaries
runs-on: 'ubuntu-latest'
needs: [release-archive, release]
strategy:
matrix:
goarch: ['arm64', 'amd64', '386', 'ppc64le', 's390x']
goos: ['linux', 'windows', 'darwin']
exclude:
- goos: darwin
goarch: '386'
- goos: darwin
goarch: arm64
- goos: windows
goarch: '386'
- goos: darwin
goarch: ppc64le
- goos: windows
goarch: ppc64le
- goos: windows
goarch: 's390x'
- goos: darwin
goarch: 's390x'
steps:
- name: Fetch Archive
uses: actions/download-artifact@v3
id: download
with:
name: release
- name: Publish clairctl-${{matrix.goos}}-${{matrix.goarch}}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{steps.download.outputs.download-path}}/clairctl-${{matrix.goos}}-${{matrix.goarch}}
asset_name: clairctl-${{matrix.goos}}-${{matrix.goarch}}
asset_content_type: application/octet-stream
deploy-documentation:
name: Deploy Documentation
runs-on: ubuntu-latest
needs: [release]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/documentation