generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
255 lines (212 loc) · 7.93 KB
/
publish.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
name: Publish artifacts
on:
release:
types: [published]
concurrency: release-${{ github.event.release.tag_name }}
env:
HELM_VERSION: v3.11.3
SEMVER_VERSION: 3.4.0
REGISTRY: ghcr.io
CHART_DIRECTORY: chart
# COP_REPOSITORY:
# COP_CHART_BASE_DIRECTORY:
defaults:
run:
shell: bash
jobs:
validate:
name: Run validations
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Validate chart version
run: |
chart_version=$(yq .version $CHART_DIRECTORY/Chart.yaml)
if [ "$chart_version" != "${{ github.event.release.tag_name }}" ]; then
>&2 echo "Version in $CHART_DIRECTORY/Chart.yaml ($chart_version) does not match release version (${{ github.event.release.tag_name }})."
exit 1
fi
publish-to-pages:
name: Publish chart to github pages
runs-on: ubuntu-24.04
needs: validate
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: false
environment:
name: github-pages
url: ${{ steps.publish-index.outputs.page_url }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create helm-index branch if missing
run: |
if ! git rev-parse --verify remotes/origin/helm-index &>/dev/null; then
git switch --orphan helm-index
git config user.name "${{ vars.WORKFLOW_USER_NAME }}"
git config user.email "${{ vars.WORKFLOW_USER_EMAIL }}"
git commit --allow-empty -m "Initial commit"
git push --set-upstream origin helm-index
git checkout main
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: helm-index
path: index
- uses: azure/setup-helm@v4
with:
version: ${{ env.HELM_VERSION }}
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Create package
run: |
helm package --version ${{ github.event.release.tag_name }} $CHART_DIRECTORY
- name: Create index
run: |
helm repo index --url ${{ github.server_url }}/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }} --merge ./index/index.yaml .
mv index.yaml index
cd index
git config user.name "${{ vars.WORKFLOW_USER_NAME }}"
git config user.email "${{ vars.WORKFLOW_USER_EMAIL }}"
git add index.yaml
git commit -m "Release ${{ github.event.release.tag_name }}"
git push
- name: Upload package
run: |
upload_url="${{ github.event.release.upload_url }}"
upload_url=${upload_url%%\{*\}}
chart_name=$(yq .name $CHART_DIRECTORY/Chart.yaml)
file=$chart_name-${{ github.event.release.tag_name }}.tgz
echo "Uploading $file to $upload_url ..."
curl -sSf \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "Content-Type: $(file -b --mime-type $file)" \
--data-binary @$file \
"$upload_url?name=$(basename $file)"
- name: Upload index
uses: actions/upload-pages-artifact@v3
with:
path: index
- name: Publish index
id: publish-index
uses: actions/deploy-pages@v4
publish-to-packages:
name: Publish chart to github packages
runs-on: ubuntu-24.04
needs: validate
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: azure/setup-helm@v4
with:
version: ${{ env.HELM_VERSION }}
- name: Create package
run: |
helm package --version ${{ github.event.release.tag_name }} $CHART_DIRECTORY
- name: Login to the OCI registry
run: |
helm --registry-config $RUNNER_TEMP/helm-config.json registry login $REGISTRY -u ${{ github.actor }} --password-stdin <<< ${{ github.token }}
- name: Upload package
run: |
chart_name=$(yq .name $CHART_DIRECTORY/Chart.yaml)
file=$chart_name-${{ github.event.release.tag_name }}.tgz
repository=$REGISTRY/${{ github.repository }}
helm --registry-config $RUNNER_TEMP/helm-config.json push $file oci://${repository,,}
update-cop:
name: Update component operator
runs-on: ubuntu-24.04
needs: validate
steps:
- name: Prepare
id: prepare
run: |
cop_repository=$COP_REPOSITORY
if [ -z "$cop_repository" ]; then
cop_repository=${GITHUB_REPOSITORY/-helm/-cop}
fi
echo "cop_repository=$cop_repository" >> $GITHUB_OUTPUT
cop_chart_base_directory=$COP_CHART_BASE_DIRECTORY
if [ -z "$cop_chart_base_directory" ]; then
cop_chart_base_directory=pkg/operator/data/charts
fi
echo "cop_chart_base_directory=$cop_chart_base_directory" >> $GITHUB_OUTPUT
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout component operator repository
uses: actions/checkout@v4
with:
repository: ${{ steps.prepare.outputs.cop_repository }}
path: cop-repository
token: ${{ secrets.WORKFLOW_USER_GH_TOKEN }}
- name: Setup semver
uses: sap/cs-actions/setup-semver@main
with:
version: ${{ env.SEMVER_VERSION }}
install-directory: ${{ runner.temp }}/bin
- name: Update component operator repository
id: update
run: |
chart_name=$(yq .name $CHART_DIRECTORY/Chart.yaml)
cd cop-repository
cop_chart_base_directory=${{ steps.prepare.outputs.cop_chart_base_directory }}
old_version=$(yq .version $cop_chart_base_directory/$chart_name/Chart.yaml)
if [ "$(semver validate ${old_version/#[vV]/_})" != valid ]; then
>&2 echo "Found invalid current chart version ($old_version) in $cop_chart_base_directory/$chart_name/Chart.yaml)."
exit 1
fi
new_version=${{ github.event.release.tag_name }}
if [ "$(semver validate ${new_version/#[vV]/_})" != valid ]; then
>&2 echo "Invalid target chart version ($new_version)."
exit 1
fi
if [ $(semver compare $new_version $old_version) -lt 0 ]; then
echo "Target chart version ($new_version) is lower than current chart version ($old_version); skipping update."
exit 0
fi
version_bump=$(semver diff $new_version $old_version)
echo "Found chart version bump: $version_bump."
if [ "$version_bump" != major ] && [ "$version_bump" != minor ]; then
version_bump=patch
fi
echo "Performing component operator version bump: $version_bump ..."
echo "Updating chart ($cop_chart_base_directory/$chart_name) ..."
rm -rf $cop_chart_base_directory/$chart_name
cp -r ../$CHART_DIRECTORY $cop_chart_base_directory/$chart_name
if [ -z "$(git status --porcelain)" ]; then
echo "Nothing has changed; skipping update ..."
exit 0
fi
git config user.name "${{ vars.WORKFLOW_USER_NAME }}"
git config user.email "${{ vars.WORKFLOW_USER_EMAIL }}"
git add -A
git commit -F- <<END
Update chart (triggered by operator helm release $new_version)
Repository: ${{ github.repository }}
Release: ${{ github.event.release.tag_name }}
Commit: ${{ github.sha }}
END
git push
echo "version_bump=$version_bump" >> $GITHUB_OUTPUT
# add some safety sleep to overcome github race conditions
sleep 10s
- name: Release component operator repository
if: steps.update.outputs.version_bump != ''
uses: benc-uk/workflow-dispatch@v1
with:
repo: ${{ steps.prepare.outputs.cop_repository }}
workflow: release.yaml
ref: main
token: ${{ secrets.WORKFLOW_USER_GH_TOKEN }}
inputs: '{ "version-bump": "${{ steps.update.outputs.version_bump }}" }'