This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
273 lines (246 loc) · 9.35 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
261
262
263
264
265
266
267
268
269
270
271
272
273
name: Release CFN Controller
on:
workflow_dispatch: {}
schedule:
- cron: '0 18 * * 2' # Tuesdays at 10 am PST, 11 am PDT
jobs:
stage_release:
name: "Stage a new release"
runs-on: ubuntu-latest
outputs:
staged_version: ${{ steps.versiondetails.outputs.stagedversion }}
staged_version_available: ${{ steps.versiondetails.outputs.stagedversionavailable }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install standard-version
run: |
npm install -g standard-version@^9.5.0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Check for new commits to release
run: |
CURRENT_VERSION=$(cat VERSION)
COMMITS_TO_RELEASE=$(git log --pretty=oneline v$CURRENT_VERSION..HEAD | wc -l)
echo Current version: v$CURRENT_VERSION
echo Commits to release: $COMMITS_TO_RELEASE
echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_ENV
echo "COMMITS_TO_RELEASE=${COMMITS_TO_RELEASE}" >> $GITHUB_ENV
- name: Check if no release needed
if: ${{ env.COMMITS_TO_RELEASE == 0 }}
run: |
echo No changes to release!
echo Current release: $CURRENT_VERSION
- name: Stage new version
if: ${{ env.COMMITS_TO_RELEASE != 0 }}
run: |
standard-version
NEW_VERSION=$(cat VERSION)
RELEASE_COMMIT_ID=$(git rev-parse HEAD)
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
echo "RELEASE_COMMIT_ID=${RELEASE_COMMIT_ID}" >> $GITHUB_ENV
- name: Check if version was bumped
if: ${{ env.COMMITS_TO_RELEASE != 0 && env.NEW_VERSION == env.CURRENT_VERSION }}
run: |
echo No changes to release!
echo Current release: $CURRENT_VERSION
- name: 'Show staged version details'
if: ${{ env.COMMITS_TO_RELEASE != 0 && env.NEW_VERSION != env.CURRENT_VERSION }}
id: versiondetails
shell: bash
run: |
echo New version: v$NEW_VERSION
echo Commit ID: $RELEASE_COMMIT_ID
echo Previous version: v$CURRENT_VERSION
echo Changes to be released:
git log --pretty=oneline v$CURRENT_VERSION..v$NEW_VERSION
echo "stagedversion=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "stagedversionavailable=true" >> $GITHUB_OUTPUT
run_unit_tests:
name: "Run unit tests"
runs-on: ubuntu-latest
needs: stage_release
if: needs.stage_release.outputs.staged_version_available == 'true'
steps:
- uses: actions/checkout@v3
- name: Restore Go cache
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
- run: make test
- name: Check if working tree is dirty
run: |
if [[ $(git diff --stat) != '' ]]; then
git --no-pager diff
echo 'run make test and commit changes'
exit 1
fi
run_integration_tests:
name: "Run integration tests"
runs-on: ubuntu-latest
needs: stage_release
if: needs.stage_release.outputs.staged_version_available == 'true'
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
- name: Configure git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Restore Go cache
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
- name: Setup Kind
uses: engineerd/[email protected]
with:
version: v0.17.0
image: kindest/node:v1.28.0
- name: Setup Kustomize
uses: fluxcd/pkg/actions/kustomize@main
- name: Setup Kubectl
uses: fluxcd/pkg/actions/kubectl@main
- name: Setup Flux CLI
uses: fluxcd/flux2/action@main
- name: Install tools
run: make install-tools
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.INTEG_TEST_ROLE_ARN }}
aws-region: ${{ secrets.INTEG_TEST_REGION }}
- name: Bootstrap local test cluster
run: make bootstrap-local-cluster
- name: Deploy into local test cluster
run: make deploy-local
- name: Run tests
run: make integ-test
- name: Debug failure
if: failure()
run: |
kubectl get all -n flux-system
kubectl describe pods -l app=cfn-controller -n flux-system || true
kubectl describe cfnstack -n flux-system || true
kubectl logs deployment/cfn-controller -n flux-system || true
release_new_version:
name: "Release the new version"
needs: [stage_release, run_unit_tests, run_integration_tests]
if: needs.stage_release.outputs.staged_version_available == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install release tools
run: |
npm install -g standard-version@^9.5.0
- name: Setup Kustomize
uses: fluxcd/pkg/actions/kustomize@main
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Update Kubernetes configuration with new version
env:
NEW_VERSION: ${{needs.stage_release.outputs.staged_version}}
run: |
cd config/manager
kustomize edit set image public.ecr.aws/aws-cloudformation/aws-cloudformation-controller-for-flux=public.ecr.aws/aws-cloudformation/aws-cloudformation-controller-for-flux:v$NEW_VERSION
cd ../..
git add config/manager/kustomization.yaml
git commit -m "chore(release): Bump controller image version to v$NEW_VERSION"
echo "STAGED_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
- name: Tag new version and update changelog
run: |
standard-version
NEW_VERSION=$(cat VERSION)
RELEASE_COMMIT_ID=$(git rev-parse HEAD)
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
echo "RELEASE_COMMIT_ID=${RELEASE_COMMIT_ID}" >> $GITHUB_ENV
- name: Confirm version number
if: ${{ env.STAGED_VERSION != env.NEW_VERSION }}
run: |
echo Staged release and actual release numbers do not match
echo Staged release: $STAGED_VERSION
echo Actual release: $NEW_VERSION
exit 1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.PUBLISHER_ROLE_ARN }}
aws-region: ${{ secrets.PUBLISHER_REGION }}
- name: Login to Amazon ECR Public
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v1
with:
registry-type: public
- name: Configure Docker image tags
id: docker-image-tags
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
REGISTRY_ALIAS: ${{ secrets.PUBLISHER_REGISTRY_ALIAS }}
REPOSITORY: aws-cloudformation-controller-for-flux
run: |
echo "versioned_image=$REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:v$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "latest_image=$REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:latest" >> "$GITHUB_OUTPUT"
- name: Build and push controller Docker image to ECR Public
uses: docker/build-push-action@v4
with:
push: true
no-cache: true
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
build-args: |
BUILD_SHA=${{ github.sha }}
BUILD_VERSION=v${{ env.NEW_VERSION }}
platforms: linux/amd64,linux/arm64
tags: |
${{ steps.docker-image-tags.outputs.versioned_image }}
${{ steps.docker-image-tags.outputs.latest_image }}
- name: Push new version to GitHub
run: |
git push origin HEAD:main
git push origin v$NEW_VERSION
- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
name: v${{ env.NEW_VERSION }}
tag_name: v${{ env.NEW_VERSION }}
target_commitish: ${{ env.RELEASE_COMMIT_ID }}
body: See the [changelog](CHANGELOG.md) for details about the changes included in this release.