-
Notifications
You must be signed in to change notification settings - Fork 61
242 lines (200 loc) · 7.18 KB
/
helm-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
name: Release Helm Charts
on:
workflow_dispatch:
inputs:
version:
description: "Release version (eg: 2.1.1)"
required: true
type: string
charts_dir:
description: "Charts directory"
required: true
default: 'helm'
type: string
# Prevent this workflow from running concurrently with the docs.yml workflow
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
verify:
name: Verify release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Make sure charts directory exists and contains Helm charts
env:
CHARTS_DIR: ${{ inputs.charts_dir }}
run: find $CHARTS_DIR -maxdepth 2 -mindepth 2 -type f -name "Chart.yaml"
- name: Verify release version is a valid SemVer version string
env:
VERSION: ${{ inputs.version }}
# regex is from the semver.org list of suggested regex strings https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
run: echo $VERSION | grep -qP '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
- name: Ensure a git tag for this version does not already exist
env:
VERSION: v${{ inputs.version }}
run: |
if [ $(git tag -l "$VERSION") ]; then
echo "Git tag matching release version '$VERSION' already exists"
false
else
true
fi
- name: Ensure a Github release for this version does not already exist
env:
VERSION: v${{ inputs.version }}
GH_TOKEN: ${{ github.token }}
run: |
export API_RESULT=$(gh api --silent \
-H "Accept: application/vnd.github+json" \
-H "X-Github-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/releases/tags/${VERSION} 2>&1)
if [[ "$API_RESULT" == *"Not Found"* ]]; then
true
else
echo "Release for version '$VERSION' already exists on Github"
false
fi
docs:
name: Build documentation
needs: verify
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python virtualenv
run: |
pip install --upgrade pip
python -m venv env
source env/bin/activate
pip install -r docs/requirements.txt
- name: Build documentation
run: |
source env/bin/activate
mkdocs build
- name: Store built documentation artifacts
uses: actions/upload-artifact@v4
with:
name: docs
path: site
helm:
name: Package Helm charts
needs: verify
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Helm
env:
GITHUB_TOKEN: ${{ github.token }}
uses: azure/setup-helm@v3
- name: Add chart dependency repositories
env:
CHARTS_DIR: ${{ inputs.charts_dir }}
run: |
charts=($(find $CHARTS_DIR -maxdepth 2 -mindepth 2 -type f -name "Chart.yaml" -printf '%h\n'))
for chart in "${charts[@]}"; do
repos=($(helm dependency list $chart | head -n '-1' | tail -n '+2' | cut -f3))
for repo in "${repos[@]}"; do
name=$(echo $repo | grep -o '[^/]*$')
helm repo add $name $repo
done
done
- name: Create Chart packages
env:
CHARTS_DIR: ${{ inputs.charts_dir }}
run: |
mkdir -p dist
find $CHARTS_DIR -maxdepth 2 -mindepth 2 -type f -name "Chart.yaml" -printf '%h\n' | xargs -I % bash -c "helm package -d dist %"
- name: Pull in previous index.yaml file if it exists
env:
GH_TOKEN: ${{ github.token }}
run: |
PAGES_URL=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/pages \
| jq -r '.html_url')
if [[ "$PAGES_URL" != "null" ]]; then
HTTP_STATUS=$(curl -sL -w '%{http_code}' "${PAGES_URL%/}/index.yaml" -o dist/index.yaml)
if [[ "$HTTP_STATUS" != "200" ]]; then
rm dist/index.yaml
fi
fi
- name: Update Helm repository index.yaml file
env:
CHART_BASE_URL: ${{ github.server_url }}/${{ github.repository }}/releases/download/v${{ inputs.version }}
run: |
if [ -f dist/index.yaml ]; then
helm repo index dist --merge dist/index.yaml --url $CHART_BASE_URL
else
helm repo index dist --url $CHART_BASE_URL
fi
- name: Store Helm chart artifacts
uses: actions/upload-artifact@v4
with:
name: charts
path: dist
release:
name: Publish and release files
needs:
- verify
- docs
- helm
# Provision a Github token with repository and pages write permissions
permissions:
contents: write
pages: write
id-token: write
# Use the github-pages environment. The actions/deploy-pages workflow fails with a
# "Invalid environment node id" error if an environment is not specified.
# https://github.com/actions/deploy-pages/issues/271
environment:
name: github-pages
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Create a git tag for the release
uses: EndBug/add-and-commit@v9
with:
message: "Nemesis v${{ inputs.version }}"
push: true
tag: "v${{ inputs.version }}"
- name: Download documentation site files
uses: actions/download-artifact@v4
with:
name: docs
path: site
- name: Download Helm chart files
uses: actions/download-artifact@v4
with:
name: charts
path: dist
- name: Merge Chart index.yaml file with documentation files
run: mv dist/index.yaml site/index.yaml
- name: Setup Github pages
uses: actions/configure-pages@v4
- name: Create Github pages artifact
uses: actions/upload-pages-artifact@v3
with:
path: site
- name: Deploy Github pages site
uses: actions/deploy-pages@v4
- name: Create Github release with the Helm charts
env:
VERSION: v${{ inputs.version }}
GH_TOKEN: ${{ github.token }}
run: gh release create ${VERSION} -R ${{ github.repository }} -t "Nemesis $VERSION" -n "Nemesis $VERSION release" dist/*.tgz
- name: Remove Github release and tag on failure
continue-on-error: true
if: ${{ failure() }}
env:
VERSION: v${{ inputs.version }}
GH_TOKEN: ${{ github.token }}
run: gh release delete -R ${{ github.repository }} $VERSION -y --cleanup-tag