-
Notifications
You must be signed in to change notification settings - Fork 0
338 lines (304 loc) · 13.6 KB
/
chart-bump-appversion.yml
File metadata and controls
338 lines (304 loc) · 13.6 KB
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
name: Chart Bump appVersion
concurrency:
group: cba-${{ github.repository }}
on:
workflow_call:
inputs:
helm_release_namespace:
description: Kubernetes namespace corresponding to a Helm release, e.g. 'staging'.
required: true
type: string
helm_release_prefix:
description: The prefix used for the Helm release, e.g. 'slate-portal', 'slate-api'.
required: true
type: string
helm_working_directory:
description: The relative directory where Helm commands will execute.
required: false
default: "./resources/chart"
type: string
python_packages:
description: The pip packages to use.
required: false
default: |
pyyaml==6.0
semver==2.13.0
type: string
python_version:
description: The version of Python to use, e.g. 3.9.
required: false
default: 3.9
type: string
secrets:
gc_compute_zone:
description: The Google Cloud Compute Zone where the assets reside.
required: true
gc_gke_cluster:
description: The cluster name on the Google Kubernetes Engine (GKE).
required: true
gc_service_account:
description: The Google Cloud Service Account tied to the WIP.
required: true
gc_workload_identity_provider:
description: The Google Cloud Workload Identity Provider (WIP).
required: true
env:
HELM_SECRETS_BACKEND: vals
PRERELEASE_DATETIME_SUFFIX: "%Y%m%d-%H%M%S"
SLATE_GITHUB_ACTIONS_BRANCHORTAG: v16
SLATE_GITHUB_ACTIONS_RAWCONTENT_URL: https://raw.githubusercontent.com/slateci/github-actions
jobs:
bump-appversion:
name: Bump appVersion
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
# Un-comment this block to re-support the DEV environment corresponding to the develop git branch.
#
# - name: "Chosen environment: development"
# if: ${{ inputs.helm_release_namespace == 'development' }}
# run: |-
# echo "GIT_REF=refs/heads/develop" >> $GITHUB_ENV
# echo "HELM_RELEASE_NAMESPACE_SHORTHAND=dev" >> $GITHUB_ENV
- name: "Chosen environment: staging"
if: ${{ inputs.helm_release_namespace == 'staging' }}
run: |-
echo "GIT_REF=refs/heads/master" >> $GITHUB_ENV
echo "HELM_RELEASE_NAMESPACE_SHORTHAND=staging" >> $GITHUB_ENV
- name: "Chosen environment: production"
if: ${{ inputs.helm_release_namespace == 'production' }}
uses: jannekem/run-python-script-action@v1
with:
script: |
message = "This workflow is not appropriate for the production environment."
error(message)
raise Exception(message)
- name: Check out repo
uses: actions/checkout@v5
with:
fetch-depth: 0
path: ./${{ inputs.helm_release_namespace }}
ref: ${{ env.GIT_REF }}
# Un-comment this block to re-support the DEV environment corresponding to the develop git branch.
#
# - name: Check out repo develop branch (Staging)
# if: ${{ inputs.helm_release_namespace == 'staging' }}
# uses: actions/checkout@v5
# with:
# fetch-depth: 0
# path: ./development
# ref: refs/heads/develop
- name: Configure Git
uses: slateci/github-actions/.github/actions/configure-git@v17
- name: Set Up Tools
uses: slateci/github-actions/.github/actions/gcloud-helm-setup@v17
with:
cluster_name: ${{ secrets.gc_gke_cluster }}
location: ${{ secrets.gc_compute_zone }}
service_account: ${{ secrets.gc_service_account }}
workload_identity_provider: ${{ secrets.gc_workload_identity_provider }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}
- name: Install Python packages
uses: BSFishy/pip-action@v1
with:
packages: ${{ inputs.python_packages }}
- name: Download workflow dependencies
run: |-
# Python files
for FILENAME in semver-bump.py semver-compare.py
do
curl -fsSL ${{ env.SLATE_GITHUB_ACTIONS_RAWCONTENT_URL }}/${{ env.SLATE_GITHUB_ACTIONS_BRANCHORTAG }}/scripts/$FILENAME -o $FILENAME
done
# Un-comment this block to re-support the DEV environment corresponding to the develop git branch.
#
# - name: Find Release Version (Dev)
# if: ${{ inputs.helm_release_namespace == 'development' }}
# uses: jannekem/run-python-script-action@v1
# with:
# script: |
# import yaml
#
# with open("./${{ inputs.helm_release_namespace }}/${{ inputs.helm_working_directory }}/Chart.yaml") as stream:
# try:
# data_loaded = yaml.safe_load(stream)
# except yaml.YAMLError as ex:
# raise ex
# app_version = data_loaded["appVersion"]
#
# print(f"Setting RELEASE_VERSION to: {app_version}")
# set_env("RELEASE_VERSION", app_version)
- name: Find Release Version (Staging)
if: ${{ inputs.helm_release_namespace == 'staging' }}
uses: jannekem/run-python-script-action@v1
with:
script: |
import semver
import yaml
with open("./${{ inputs.helm_release_namespace }}/${{ inputs.helm_working_directory }}/Chart.yaml") as stream:
try:
data_loaded = yaml.safe_load(stream)
except yaml.YAMLError as ex:
raise ex
app_version = data_loaded["appVersion"]
new_versioninfo = semver.VersionInfo.parse(app_version).finalize_version()
print(f"Setting RELEASE_VERSION to: {str(new_versioninfo)}")
set_env("RELEASE_VERSION", str(new_versioninfo))
- id: compare-versions
name: Compare Deployed & Source Release Versions
env:
HELM_RELEASE_NAMESPACE: ${{ inputs.helm_release_namespace }}
HELM_RELEASE_PREFIX: ${{ inputs.helm_release_prefix }}
run: |-
python semver-compare.py
- id: bump-version
name: Bump Release Version
if: ${{ steps.compare-versions.outputs.ahead == 'false' }}
env:
HELM_RELEASE_NAMESPACE: ${{ inputs.helm_release_namespace }}
HELM_RELEASE_PREFIX: ${{ inputs.helm_release_prefix }}
run: |-
python semver-bump.py
# Remove this block to re-support the DEV environment corresponding to the develop git branch.
#
- name: Apply Release Version (Staging - ahead)
if: ${{ inputs.helm_release_namespace == 'staging' && steps.compare-versions.outputs.ahead == 'true' }}
working-directory: ./staging/${{ inputs.helm_working_directory }}
run: |-
sed -i "s/^appVersion:.*$/appVersion: '${{ env.RELEASE_VERSION }}'/g" Chart.yaml
git add Chart.yaml
git commit -m "(github-action) Increment appVersion: ${{ env.RELEASE_VERSION }}"
git push
# Remove this block to re-support the DEV environment corresponding to the develop git branch.
#
- name: Apply Release Version (Staging - behind)
if: ${{ inputs.helm_release_namespace == 'staging' && steps.compare-versions.outputs.ahead == 'false' }}
working-directory: ./staging/${{ inputs.helm_working_directory }}
run: |-
sed -i "s/^appVersion:.*$/appVersion: '${{ steps.bump-version.outputs.version }}'/g" Chart.yaml
git add Chart.yaml
git commit -m "(github-action) Increment appVersion: ${{ steps.bump-version.outputs.version }}"
git push
echo "RELEASE_VERSION=${{ steps.bump-version.outputs.version }}" >> $GITHUB_ENV
# Un-comment this block to re-support the DEV environment corresponding to the develop git branch.
#
# - id: apply-dev-behind-version
# name: Apply Release Version (Dev - behind)
# if: ${{ inputs.helm_release_namespace == 'development' && steps.compare-versions.outputs.ahead == 'false' }}
# working-directory: ./${{ inputs.helm_release_namespace }}/${{ inputs.helm_working_directory }}
# run: |-
# git fetch
# sed -i 's/^appVersion:.*$/appVersion: "${{ steps.bump-version.outputs.version }}"/g' Chart.yaml
# git add Chart.yaml
# git commit -m '(github-action) Increment appVersion: ${{ steps.bump-version.outputs.version }}'
# git push
#
# COMMIT_HASH=$(git log -1 --format="%H")
# echo "hash=$COMMIT_HASH" >> $GITHUB_OUTPUT
#
# echo "RELEASE_VERSION=${{ steps.bump-version.outputs.version }}" >> $GITHUB_ENV
# TODO: Better handle "Tag Pre-Release (Dev)" when tag already exists.
# Un-comment this block to re-support the DEV environment corresponding to the develop git branch.
#
# - name: Tag Pre-Release (Dev)
# if: ${{ inputs.helm_release_namespace == 'development' }}
# continue-on-error: true
# working-directory: ./${{ inputs.helm_release_namespace }}
# run: |-
# if [[ '${{ steps.compare-versions.outputs.ahead }}' == 'false' ]]
# then
# COMMIT_HASH=${{ steps.apply-dev-behind-version.outputs.hash }}
# else
# COMMIT_HASH=$(git log -1 --format="%H")
# fi
#
# git fetch
# git tag v${{ env.RELEASE_VERSION }} $COMMIT_HASH
# git push origin v${{ env.RELEASE_VERSION }}
# Un-comment this block to re-support the DEV environment corresponding to the develop git branch.
#
# - name: Apply Release Version (Staging - ahead)
# if: ${{ inputs.helm_release_namespace == 'staging' && steps.compare-versions.outputs.ahead == 'true' }}
# working-directory: ./development/${{ inputs.helm_working_directory }}
# run: |-
# sed -i "s/^appVersion:.*$/appVersion: '${{ env.RELEASE_VERSION }}'/g" Chart.yaml
# git add Chart.yaml
# git commit -m "(github-action) Increment appVersion: ${{ env.RELEASE_VERSION }}"
# git push
# Un-comment this block to re-support the DEV environment corresponding to the develop git branch.
#
# - name: Apply Release Version (Staging - behind)
# if: ${{ inputs.helm_release_namespace == 'staging' && steps.compare-versions.outputs.ahead == 'false' }}
# working-directory: ./development/${{ inputs.helm_working_directory }}
# run: |-
# sed -i "s/^appVersion:.*$/appVersion: '${{ steps.bump-version.outputs.version }}'/g" Chart.yaml
# git add Chart.yaml
# git commit -m "(github-action) Increment appVersion: ${{ steps.bump-version.outputs.version }}"
# git push
#
# echo "RELEASE_VERSION=${{ steps.bump-version.outputs.version }}" >> $GITHUB_ENV
# Un-comment this block to re-support the DEV environment corresponding to the develop git branch.
#
# - id: merge-staging
# name: Merge develop to master branch (Staging)
# if: ${{ inputs.helm_release_namespace == 'staging' }}
# working-directory: ./${{ inputs.helm_release_namespace }}
# run: |-
# git fetch
# git merge origin/develop --commit -m '(github-action) Merge develop with master for: ${{ env.RELEASE_VERSION }}' --no-ff
# git push
#
# COMMIT_HASH=$(git log -1 --format="%H")
# echo "hash=$COMMIT_HASH" >> $GITHUB_OUTPUT
- name: Tag Release Candidate (Staging)
if: ${{ inputs.helm_release_namespace == 'staging' }}
working-directory: ./${{ inputs.helm_release_namespace }}
run: |-
git fetch
git tag v${{ env.RELEASE_VERSION }} ${{ steps.merge-staging.outputs.hash }}
git push origin v${{ env.RELEASE_VERSION }}
# TODO: Only perform force-bump-version-staging if dev is behind staging...
# Un-comment this block to re-support the DEV environment corresponding to the develop git branch.
#
# - id: force-bump-version-staging
# name: Force-bump Release Version on develop branch (Staging)
# if: ${{ inputs.helm_release_namespace == 'staging' }}
# uses: jannekem/run-python-script-action@v1
# with:
# script: |
# import semver
# import yaml
#
# from datetime import datetime
#
# prerelease_datetime_suffix = os.environ.get('PRERELEASE_DATETIME_SUFFIX')
#
# with open("./development//${{ inputs.helm_working_directory }}/Chart.yaml") as stream:
# try:
# data_loaded = yaml.safe_load(stream)
# except yaml.YAMLError as ex:
# raise ex
# app_version = data_loaded["appVersion"]
#
# discovered_versioninfo = semver.VersionInfo.parse(app_version)
# new_versioninfo = discovered_versioninfo.finalize_version().bump_patch()
# now = datetime.now()
# date_time = now.strftime(prerelease_datetime_suffix)
# new_app_version = f"{str(new_versioninfo)}-pre.{date_time}"
# print(f"New appVersion is: {new_app_version}")
# set_output("version", new_app_version)
# Un-comment this block to re-support the DEV environment corresponding to the develop git branch.
#
# - name: Force-apply Release Version on develop branch (Staging)
# if: ${{ inputs.helm_release_namespace == 'staging' }}
# working-directory: ./development/${{ inputs.helm_working_directory }}
# run: |-
# git fetch
# sed -i 's/^appVersion:.*$/appVersion: "${{ steps.force-bump-version-staging.outputs.version }}"/g' Chart.yaml
# git add Chart.yaml
# git commit -m '(github-action) Increment appVersion: ${{ steps.force-bump-version-staging.outputs.version }}'
# git push