generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 4
172 lines (147 loc) · 5.12 KB
/
publish-helm.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
name: Publish Helm
on:
workflow_dispatch
env:
HELM_VERSION: v3.11.3
REGISTRY: ghcr.io
CHART_DIRECTORY: chart
RELEASE_TAG_PREFIX: helm
jobs:
create_release_tag:
name: Create release tag
runs-on: ubuntu-22.04
outputs:
tag: ${{ steps.get_tag.outputs.tag }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: azure/setup-helm@v3
with:
version: ${{ env.HELM_VERSION }}
- name: Determine target commit
id: get_target_commit
run: |
sha=$(git rev-parse HEAD)
echo "Target commit: $sha"
echo "sha=$sha" >> $GITHUB_OUTPUT
- name: Get tag
id: get_tag
run: |
chart_version=$(yq .version $CHART_DIRECTORY/Chart.yaml)
echo "tag=$RELEASE_TAG_PREFIX/$chart_version" >> $GITHUB_OUTPUT
- name: Wait for check suites to complete
uses: sap-contributions/await-check-suites@master
with:
ref: ${{ steps.get_target_commit.outputs.sha }}
intervalSeconds: 10
timeoutSeconds: 1800
failStepIfUnsuccessful: true
appSlugFilter: github-actions
- name: Create release
id: create_release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.get_tag.outputs.tag }}
commit: ${{ steps.get_target_commit.outputs.sha }}
makeLatest: true
prerelease: false
allowUpdates: false
publish-to-pages:
name: Publish chart to github pages
runs-on: ubuntu-22.04
needs: create_release_tag
permissions:
contents: write
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.publish-index.outputs.page_url }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
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
fi
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: helm-index
path: index
- uses: azure/setup-helm@v3
with:
version: ${{ env.HELM_VERSION }}
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Create package
run: |
chart_version=$(yq .version $CHART_DIRECTORY/Chart.yaml)
helm package --version $chart_version $CHART_DIRECTORY
- name: Create index
run: |
chart_version=$(yq .version $CHART_DIRECTORY/Chart.yaml)
helm repo index --url ${{ github.server_url }}/${{ github.repository }}/releases/download/${{ needs.create_release_tag.outputs.tag }} --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 ${{ needs.create_release_tag.outputs.tag }}"
git push
- name: Upload package
run: |
upload_url="${{ needs.create_release_tag.outputs.upload_url }}"
upload_url=${upload_url%%\{*\}}
chart_name=$(yq .name $CHART_DIRECTORY/Chart.yaml)
chart_version=$(yq .version $CHART_DIRECTORY/Chart.yaml)
file=$chart_name-$chart_version.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@v2
with:
path: index
- name: Publish index
id: publish-index
uses: actions/deploy-pages@v2
publish-to-packages:
name: Publish chart to github packages
needs: create_release_tag
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: azure/setup-helm@v3
with:
version: ${{ env.HELM_VERSION }}
- name: Create package
run: |
chart_version=$(yq .version $CHART_DIRECTORY/Chart.yaml)
helm package --version $chart_version $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)
chart_version=$(yq .version $CHART_DIRECTORY/Chart.yaml)
file=$chart_name-$chart_version.tgz
repository=$REGISTRY/${{ github.repository }}/$RELEASE_TAG_PREFIX
helm --registry-config $RUNNER_TEMP/helm-config.json push $file oci://${repository,,}