-
Notifications
You must be signed in to change notification settings - Fork 57
283 lines (244 loc) · 9.81 KB
/
helm-releaser-testkube-main-chart-only.yaml
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
name: Releasing Testkube main helm chart
concurrency: develop_cluster
on:
push:
paths:
- "charts/testkube**"
- "!charts/testkube/Chart.yaml"
- "!charts/testkube-api/Chart.yaml"
- "!charts/testkube-operator/Chart.yaml"
branches:
- main
env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GKE_CLUSTER_NAME_DEV: ${{ secrets.GKE_CLUSTER_NAME_DEV }} # Add your cluster name here.
GKE_ZONE_DEV: ${{ secrets.GKE_ZONE_DEV }} # Add your cluster zone here.
DEPLOYMENT_NAME: testkube # Add your deployment name here.
jobs:
release_charts:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Update main Chart.yaml
run: |
cd ./scripts
chmod +x main_chart_releaser.sh
./main_chart_releaser.sh --main-chart true
- name: Run chart-releaser
uses: helm/[email protected]
with:
charts_dir: charts
mark_as_latest: true
env:
CR_TOKEN: "${{ secrets.CI_BOT_TOKEN }}"
CR_SKIP_EXISTING: true
notify_slack_if_helm_chart_release_fails:
runs-on: ubuntu-latest
needs: release_charts
if: always() && (needs.release_charts.result == 'failure')
steps:
- name: Slack Notification if Helm Release action failed
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: testkube-logs
SLACK_COLOR: ${{ needs.release_charts.result }} # or a specific color like 'good' or '#ff00ff'
SLACK_ICON: https://github.com/rtCamp.png?size=48
SLACK_TITLE: Helm Chart release action failed :boom:!
SLACK_USERNAME: GitHub
SLACK_LINK_NAMES: true
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_FOOTER: "Kubeshop --> TestKube"
refreshing_gh_pages:
needs: release_charts
runs-on: ubuntu-latest
steps:
- name: Triggering refresh for GH-pages to make just released charts available
run: |
curl -s --fail --request POST \
--url https://api.github.com/repos/kubeshop/helm-charts/pages/builds \
--header "Authorization: Bearer $USER_TOKEN"
env:
# You must create a personal token with repo access as GitHub does
# not yet support server-to-server page builds.
USER_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
checking_that_ghpages_updated:
needs: refreshing_gh_pages
runs-on: ubuntu-latest
steps:
- name: Making sure that they are abvailable now.
run: |
status=""
counter=0
while [[ $status != \"built\" ]]
do
status=$(curl -s \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/kubeshop/helm-charts/pages/builds/latest \
--header "Authorization: Bearer $USER_TOKEN" | jq .status)
echo "Checking latest GH pages build status --> $status"
sleep 5
counter=$(expr $counter + 1)
if [[ $status == \"errored\" ]] || [[ $counter == 120 ]]; then
echo "Something went wrong. Please check GH's pages issues."
exit 1
fi
done
env:
# You must create a personal token with repo access as GitHub does
# not yet support server-to-server page builds.
USER_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
notify_slack_if_release_succeeds:
runs-on: ubuntu-latest
needs: checking_that_ghpages_updated
steps:
- name: Slack Notification if the helm release pipeline succeeded.
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: testkube-logs
SLACK_COLOR: ${{ needs.checking_that_ghpages_updated.result }} # or a specific color like 'good' or '#ff00ff'
SLACK_ICON: https://github.com/rtCamp.png?size=48
SLACK_TITLE: Helm chart release succeed and GH pages got updated :party_blob:!
SLACK_USERNAME: GitHub
SLACK_LINK_NAMES: true
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_FOOTER: "Kubeshop --> TestKube"
notify_slack_if_gh_pages_update_failed:
runs-on: ubuntu-latest
needs: checking_that_ghpages_updated
if: always() && (needs.checking_that_ghpages_updated.result == 'failure')
steps:
- name: Slack Notification if the helm release GH Pages failed.
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: testkube-logs
SLACK_COLOR: ${{ needs.checking_that_ghpages_updated.result }} # or a specific color like 'good' or '#ff00ff'
SLACK_ICON: https://github.com/rtCamp.png?size=48
SLACK_TITLE: Helm chart release failed on GH pages update! :boom:!
SLACK_USERNAME: GitHub
SLACK_LINK_NAMES: true
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_FOOTER: "Kubeshop --> TestKube"
get_agent_version:
name: Pass Testkube OSS chart version to cloud-charts repo
needs: notify_slack_if_release_succeeds
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.10.0
- name: Get charts version
run: echo agent-version=$(helm show chart ./charts/testkube | grep -E "^version:" | awk '{print $2}') >> $GITHUB_ENV
- name: Repository dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.CI_BOT_TOKEN }}
repository: kubeshop/testkube-cloud-charts
event-type: trigger-workflow-testkube-agent-main
client-payload: '{"agentVersion": "${{ env.agent-version }}"}'
update_release_notes:
needs: notify_slack_if_release_succeeds
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Latest Tag
id: get_latest_tag
run: |
latest_tag=$(git tag -l | grep -E "^testkube-[0-9]+\.[0-9]+\.[0-9]+$" | sort -V | tail -n 1)
echo "::set-output name=latest_tag::${latest_tag}"
echo $latest_tag
- name: Get Previous Tag
id: get_previous_tag
run: |
previous_tag=$(git describe --abbrev=0 --tags ${TAG}^)
echo "::set-output name=previous_tag::${previous_tag}"
echo $previous_tag
env:
TAG: ${{ steps.get_latest_tag.outputs.latest_tag }}
- name: Generate Changelog
id: generate_changelog
env:
GH_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
run: |
#!/bin/bash
PREVIOUS_TAG=${{ steps.get_previous_tag.outputs.previous_tag }}
CURRENT_TAG=${{ steps.get_latest_tag.outputs.latest_tag }}
echo $PREVIOUS_TAG
echo $CURRENT_TAG
MERGED_PRS=$(git log --merges --pretty=format:"- %h: %s (#%b) (@%an)" $PREVIOUS_TAG..$CURRENT_TAG)
echo $MERGED_PRS
if [ -n "$MERGED_PRS" ]; then
echo "# Changelog" > CHANGELOG.md
FEATURE_PRS=""
FIX_PRS=""
OTHER_PRS=""
DOCS_PRS=""
while IFS= read -r pr; do
sha=$(echo "$pr" | awk '{print $1 " " $2}')
pr_number=$(echo "$pr" | awk -F'#' '{print "#" $2}' | awk '{print $1}')
pr_title=$(echo "$pr" | awk -F'[(]|[)]' '{sub(/^#/, "", $2); print $2}')
author=$(echo "$pr" | awk -F'[()]' '{print "(" $4 ")"}')
if [[ "$pr_title" == *"feat"* ]]; then
FEATURE_PRS+="\n ${sha} ${pr_title} ${pr_number} ${author}"
echo "New features"
echo $FEATURE_PRS
elif [[ "$pr_title" == *"fix"* ]]; then
FIX_PRS+="\n ${sha} ${pr_title} ${pr_number} ${author}"
echo "Bug fixes"
echo $FIX_PRS
elif [[ "$pr_title" == *"docs"* ]]; then
DOCS_PRS+="\n ${sha} ${pr_title} ${pr_number} ${author}"
echo "Documentation updates"
echo $DOCS_PRS
else
OTHER_PRS+="\n ${sha} ${pr_title} ${pr_number} ${author}"
echo "Other changes"
echo $OTHER_PRS
fi
done < <(echo "$MERGED_PRS")
if [ -n "$FEATURE_PRS" ]; then
echo "## Features" >> CHANGELOG.md
echo -e "$FEATURE_PRS" >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
if [ -n "$FIX_PRS" ]; then
echo "## Bug Fixes" >> CHANGELOG.md
echo -e "$FIX_PRS" >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
if [ -n "$DOCS_PRS" ]; then
echo "## Documentation Updates" >> CHANGELOG.md
echo -e "$DOCS_PRS" >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
if [ -n "$OTHER_PRS" ]; then
echo "## Other Changes" >> CHANGELOG.md
echo -e "$OTHER_PRS" >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
echo "Printing changelog"
cat CHANGELOG.md
echo "Updating release"
gh release edit $CURRENT_TAG --notes-file CHANGELOG.md
else
echo "No merged pull requests found. Adding commits"
COMMIT_CHANGELOG=$(git log --pretty=format:"- %s %h (@%an)" $PREVIOUS_TAG..$CURRENT_TAG)
echo "# Commit Changelog" > CHANGELOG.md
echo "" >> CHANGELOG.md
echo "${COMMIT_CHANGELOG}" >> CHANGELOG.md
gh release edit $CURRENT_TAG --notes-file CHANGELOG.md
fi