generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (173 loc) · 6.4 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
name: Publish artifacts
on:
release:
types: [published]
concurrency: release-${{ github.event.release.tag_name }}
env:
REGCTL_VERSION: v0.4.8
SEMVER_VERSION: 3.4.0
REGISTRY: ghcr.io
# CHART_REPOSITORY:
# CHART_DIRECTORY:
defaults:
run:
shell: bash
jobs:
publish-docker:
name: Publish Docker image
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Prepare repository name
id: prepare-repository-name
run: |
repository=$REGISTRY/${{ github.repository }}
echo "repository=${repository,,}" >> $GITHUB_OUTPUT
- name: Extract metadata (tags, labels) for Docker
id: extract-metadata
uses: docker/metadata-action@v4
with:
images: ${{ steps.prepare-repository-name.outputs.repository }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
context: .
cache-from: |
type=gha,scope=sha-${{ github.sha }}
type=gha,scope=${{ github.ref_name }}
type=gha,scope=${{ github.base_ref || 'main' }}
type=gha,scope=main
cache-to: |
type=gha,scope=sha-${{ github.sha }},mode=max
type=gha,scope=${{ github.ref_name }},mode=max
push: true
tags: ${{ steps.extract-metadata.outputs.tags }}
labels: ${{ steps.extract-metadata.outputs.labels }}
publish-crds:
name: Publish CRD image
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup regctl
uses: regclient/actions/regctl-installer@main
with:
release: ${{ env.REGCTL_VERSION }}
install-dir: ${{ runner.temp }}/bin
- name: Log in to the registry
# regctl-login action is currently broken ...
# uses: regclient/actions/regctl-login@main
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ github.token }}
run: |
regctl registry login $REGISTRY --user ${{ github.actor }} --pass-stdin <<< ${{ github.token }}
- name: Build and push artifact
run: |
cd crds
repository=$REGISTRY/${{ github.repository }}/crds
tar cvz * | regctl artifact put -m application/gzip ${repository,,}:${{ github.event.release.tag_name }}
update-chart:
name: Update Helm chart
runs-on: ubuntu-22.04
needs: [publish-docker,publish-crds]
steps:
- name: Prepare
id: prepare
run: |
chart_repository=$CHART_REPOSITORY
if [ -z "$chart_repository" ]; then
chart_repository=${{ github.repository }}-helm
fi
echo "chart_repository=$chart_repository" >> $GITHUB_OUTPUT
chart_directory=$CHART_DIRECTORY
if [ -z "$chart_directory" ]; then
chart_directory=chart
fi
echo "chart_directory=$chart_directory" >> $GITHUB_OUTPUT
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout chart repository
uses: actions/checkout@v3
with:
repository: ${{ steps.prepare.outputs.chart_repository }}
path: chart-repository
token: ${{ secrets.WORKFLOW_USER_GH_TOKEN }}
- name: Setup semver
uses: ./.github/actions/setup-semver
with:
version: ${{ env.SEMVER_VERSION }}
install-directory: ${{ runner.temp }}/bin
- name: Update chart repository
id: update
run: |
cd chart-repository
chart_directory=${{ steps.prepare.outputs.chart_directory }}
old_version=$(yq .appVersion $chart_directory/Chart.yaml)
if [ "${old_version:0:1}" != v ] || [ "$(semver validate $old_version)" != valid ]; then
>&2 echo "Found invalid current appVersion ($old_version) in $chart_directory/Chart.yaml)."
exit 1
fi
new_version=${{ github.event.release.tag_name }}
if [ "${new_version:0:1}" != v ] || [ "$(semver validate $new_version)" != valid ]; then
>&2 echo "Invalid target appVersion ($new_version)."
exit 1
fi
if [ $(semver compare $new_version $old_version) -lt 0 ]; then
echo "Target appVersion ($new_version) is lower than current appVersion ($old_version); skipping update ..."
exit 0
fi
version_bump=$(semver diff $new_version $old_version)
echo "Found appVersion bump: $version_bump."
if [ "$version_bump" != major ] && [ "$version_bump" != minor ]; then
version_bump=patch
fi
echo "Performing chart version bump: $version_bump ..."
echo "Updating custom resource definitions ($chart_directory/crds) ..."
rm -rf $chart_directory/crds
cp -r ../crds $chart_directory
echo "Updating appVersion in $chart_directory/Chart.yaml (current: $old_version; target: $new_version) ..."
perl -pi -e "s#^appVersion:.*#appVersion: $new_version#g" $chart_directory/Chart.yaml
if [ -z "$(git status --porcelain)" ]; then
echo "Nothing has changed; skipping commit/push ..."
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 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 chart repository
if: steps.update.outputs.version_bump != ''
uses: benc-uk/workflow-dispatch@v1
with:
repo: ${{ steps.prepare.outputs.chart_repository }}
workflow: release.yaml
ref: main
token: ${{ secrets.WORKFLOW_USER_GH_TOKEN }}
inputs: '{ "version-bump": "${{ steps.update.outputs.version_bump }}" }'