-
Notifications
You must be signed in to change notification settings - Fork 16
260 lines (223 loc) · 8.87 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
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
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+"
paths-ignore:
- "**.md"
- "docs/**"
jobs:
release:
runs-on: ubuntu-latest
env:
CGO_ENABLED: "0"
COSIGN_VERSION: v2.4.0
GGCR_VERSION: v0.20.2
REGISTRY: ghcr.io
SKAFFOLD_VERSION: v2.13.1
SKAFFOLD_CACHE_ARTIFACTS: "false"
SKAFFOLD_DETECT_MINIKUBE: "false"
SKAFFOLD_INTERACTIVE: "false"
SKAFFOLD_OFFLINE: "true"
SKAFFOLD_UPDATE_CHECK: "false"
permissions:
contents: write
id-token: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: go.mod
cache: true
- name: Set image env vars
run: |
echo IMAGE_REPO=$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
RC_VERSION=${GITHUB_REF#refs/tags/}
echo VERSION=${RC_VERSION%-rc*} >> $GITHUB_ENV
- name: Print env
run: |
echo HOME=$HOME
echo PATH=$PATH
go version
go env
- name: Run unit tests
run: |
go test -v -count=1 -short -timeout=5m -vet=asmdecl,assign,atomic,bools,buildtag,cgocall,composites,copylocks,errorsas,httpresponse,loopclosure,lostcancel,nilfunc,printf,shift,stdmethods,structtag,tests,unmarshal,unreachable,unsafeptr,unusedresult ./...
- name: Create release branch
run: |
git checkout -B release-$VERSION
- name: Populate version number in embedded file
run: |
echo "$VERSION" > pkg/version/version.txt
- name: Commit and push to release branch with new version number
run: |
git add pkg/version/version.txt
git config user.name github-actions
git config user.email [email protected]
git commit -m "Update binary version to $VERSION"
git push --force origin release-$VERSION
- name: Set image label env vars
run: |
echo REVISION=$(git rev-parse HEAD) >> $GITHUB_ENV
echo SOURCE=${{ github.server_url }}/${{ github.repository }}.git >> $GITHUB_ENV
echo URL=${{ github.server_url }}/${{ github.repository }} >> $GITHUB_ENV
- name: Build binaries
run: |
GOOS=darwin GOARCH=amd64 go build -v -trimpath -ldflags="-s -w" -o gatekeeper-securitycenter_Darwin_x86_64 .
GOOS=darwin GOARCH=arm64 go build -v -trimpath -ldflags="-s -w" -o gatekeeper-securitycenter_Darwin_arm64 .
GOOS=linux GOARCH=amd64 go build -v -trimpath -ldflags="-s -w" -o gatekeeper-securitycenter_Linux_x86_64 .
GOOS=linux GOARCH=arm64 go build -v -trimpath -ldflags="-s -w" -o gatekeeper-securitycenter_Linux_aarch64 .
- name: Install Skaffold
run: |
mkdir -p $HOME/.local/bin
curl -sSLo $HOME/.local/bin/skaffold "https://storage.googleapis.com/skaffold/releases/${SKAFFOLD_VERSION}/skaffold-$(go env GOOS)-$(go env GOARCH)"
chmod +x $HOME/.local/bin/skaffold
- name: Build and push container images
run: |
skaffold build \
--default-repo ${{ env.REGISTRY }}/${{ github.repository_owner }} \
--file-output ${{ runner.temp }}/skaffold-artifacts.json \
--profile release \
--push \
--tag $VERSION
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Create checksums file
run: shasum -a 256 gatekeeper-securitycenter_* > SHA256SUMS
- name: Get image name with digest
run: |
echo -n IMAGE_NAME= >> $GITHUB_ENV
echo $(jq -r '.builds[] | select(.imageName=="gatekeeper-securitycenter") | .tag' ${{ runner.temp }}/skaffold-artifacts.json) >> $GITHUB_ENV
- name: Install krane
run: |
mkdir -p $HOME/.local/bin
curl -sSL "https://github.com/google/go-containerregistry/releases/download/${GGCR_VERSION}/go-containerregistry_$(uname -s)_$(uname -m).tar.gz" | tar -xzC $HOME/.local/bin krane
- name: Update latest tag
run: krane tag $IMAGE_NAME latest
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Install Cosign
uses: sigstore/cosign-installer@main
with:
cosign-release: ${{ env.COSIGN_VERSION }}
- name: Sign the images with GitHub OIDC Token
run: cosign sign --k8s-keychain --recursive --upload --yes $IMAGE_NAME
env:
COSIGN_EXPERIMENTAL: 1
GITHUB_TOKEN: ${{ github.token }}
- name: Create release body file
run: |
cat << EOF > ${{ runner.temp }}/body.md
## Images
GitHub Container Registry:
$IMAGE_NAME
EOF
- name: Set image name in deployment manifest
run: |
tmpfile=$(mktemp)
kubectl patch \
--dry-run=client \
--filename deployment.yaml \
--local \
--output yaml \
--patch '{"spec":{"template":{"spec":{"containers":[{"name":"manager","image":"${{ env.IMAGE_NAME }}"}]}}}}' \
> $tmpfile
mv $tmpfile deployment.yaml
working-directory: manifests
- name: Update version in readme
run: |
sed -i "s/VERSION=.*/VERSION=$VERSION/" README.md manifests/README.md
- name: Commit and push to release branch with new version and image ref
run: |
git add README.md manifests
git config user.name github-actions
git config user.email [email protected]
git commit -m "Update image version in manifest to $VERSION"
git push --force origin release-$VERSION
- name: Set release env vars
run: |
echo COMMITISH=$(git rev-parse HEAD) >> $GITHUB_ENV
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
body_path: ${{ runner.temp }}/body.md
commitish: ${{ env.COMMITISH }}
- name: Upload binary darwin amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: gatekeeper-securitycenter_Darwin_x86_64
asset_name: gatekeeper-securitycenter_Darwin_x86_64
asset_content_type: application/octet-stream
- name: Upload binary darwin arm64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: gatekeeper-securitycenter_Darwin_arm64
asset_name: gatekeeper-securitycenter_Darwin_arm64
asset_content_type: application/octet-stream
- name: Upload binary linux amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: gatekeeper-securitycenter_Linux_x86_64
asset_name: gatekeeper-securitycenter_Linux_x86_64
asset_content_type: application/octet-stream
- name: Upload binary linux arm64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: gatekeeper-securitycenter_Linux_aarch64
asset_name: gatekeeper-securitycenter_Linux_aarch64
asset_content_type: application/octet-stream
- name: Upload checksums file
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: SHA256SUMS
asset_name: SHA256SUMS
asset_content_type: text/plain
- name: Update version in readme on main branch
run: |
git config user.name github-actions
git config user.email [email protected]
git reset --hard
git remote update
git checkout main
git pull --no-edit --no-rebase --strategy-option=theirs origin
sed -i "s/VERSION=.*/VERSION=$VERSION/" README.md manifests/README.md
git add README.md manifests/README.md
git commit -m "Update version in readme to $VERSION"
git pull --no-edit --no-rebase --strategy-option=ours origin
git push origin main