-
Notifications
You must be signed in to change notification settings - Fork 0
347 lines (306 loc) · 12.8 KB
/
helm-publish.yml
File metadata and controls
347 lines (306 loc) · 12.8 KB
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
name: 'Helm Package & Publish'
on:
workflow_call:
inputs:
chart-path:
description: 'Path to Helm chart directory'
required: true
type: string
registry:
description: 'OCI registry (ghcr.io, docker.io, etc.)'
required: false
type: string
default: 'ghcr.io'
repository:
description: 'Chart repository path (e.g., owner/charts)'
required: false
type: string
default: ''
sign-chart:
description: 'Sign chart with Cosign'
required: false
type: boolean
default: true
create-release:
description: 'Create GitHub release'
required: false
type: boolean
default: true
multi-registry:
description: 'Comma-separated list of additional registries'
required: false
type: string
default: ''
update-index:
description: 'Update Helm repository index (for traditional repos)'
required: false
type: boolean
default: false
provenance:
description: 'Generate chart provenance file'
required: false
type: boolean
default: true
runs-on:
description: 'Runner label to execute the job on'
required: false
type: string
default: 'homelab-runners'
secrets:
registry-username:
description: 'Registry username (defaults to github.actor)'
required: false
registry-password:
description: 'Registry password/token (defaults to GITHUB_TOKEN)'
required: false
gpg-private-key:
description: 'GPG private key for chart signing'
required: false
gpg-passphrase:
description: 'GPG key passphrase'
required: false
outputs:
chart-version:
description: 'Published chart version'
value: ${{ jobs.publish.outputs.version }}
chart-digest:
description: 'OCI digest of published chart'
value: ${{ jobs.publish.outputs.digest }}
release-url:
description: 'GitHub release URL'
value: ${{ jobs.publish.outputs.release-url }}
permissions:
contents: write
packages: write
id-token: write
jobs:
publish:
name: Package & Publish Chart
runs-on: ${{ inputs.runs-on }}
timeout-minutes: 15
outputs:
version: ${{ steps.chart-info.outputs.version }}
digest: ${{ steps.push.outputs.digest }}
release-url: ${{ steps.release.outputs.url }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v4.2.0
with:
version: v3.16.3
- name: Install yq
run: |
YQ_VERSION="v4.44.6"
wget -q "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" -O /tmp/yq
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
yq --version
- name: Install Cosign
if: inputs.sign-chart
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0
- name: Get chart information
id: chart-info
working-directory: ${{ inputs.chart-path }}
run: |
CHART_NAME=$(yq eval '.name' Chart.yaml)
CHART_VERSION=$(yq eval '.version' Chart.yaml)
CHART_APP_VERSION=$(yq eval '.appVersion' Chart.yaml)
echo "name=$CHART_NAME" >> $GITHUB_OUTPUT
echo "version=$CHART_VERSION" >> $GITHUB_OUTPUT
echo "app-version=$CHART_APP_VERSION" >> $GITHUB_OUTPUT
echo "Chart: $CHART_NAME v$CHART_VERSION (app: $CHART_APP_VERSION)"
- name: Set repository path
id: repo-path
run: |
if [ -n "${{ inputs.repository }}" ]; then
REPO_PATH="${{ inputs.repository }}"
else
REPO_PATH="${{ github.repository_owner }}/charts"
fi
echo "path=$REPO_PATH" >> $GITHUB_OUTPUT
echo "Repository path: $REPO_PATH"
# Login early to enable pulling OCI dependencies
- name: Log in to OCI registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ inputs.registry }}
username: ${{ secrets.registry-username || github.actor }}
password: ${{ secrets.registry-password || secrets.GITHUB_TOKEN }}
- name: Log in to Helm OCI registry
run: |
echo "${{ secrets.registry-password || secrets.GITHUB_TOKEN }}" | \
helm registry login ${{ inputs.registry }} \
--username "${{ secrets.registry-username || github.actor }}" \
--password-stdin
- name: Add Helm repositories
working-directory: ${{ inputs.chart-path }}
run: |
if [ -f "Chart.yaml" ]; then
yq eval '.dependencies[].repository' Chart.yaml | grep -v "^null$" | while read -r repo; do
if [[ "$repo" == http* ]]; then
repo_name=$(echo "$repo" | sed 's|https://||;s|http://||;s|/|-|g')
echo "Adding repository: $repo_name ($repo)"
helm repo add "$repo_name" "$repo" || true
fi
done
fi
helm repo update || true
- name: Update chart dependencies
working-directory: ${{ inputs.chart-path }}
run: |
if [ -f "Chart.yaml" ] && yq eval '.dependencies' Chart.yaml | grep -q "name:"; then
echo "Updating chart dependencies..."
helm dependency update
else
echo "No dependencies to update"
fi
- name: Package Helm chart
id: package
working-directory: ${{ inputs.chart-path }}
run: |
echo "Packaging chart..."
helm package . --destination /tmp/charts
CHART_FILE="${{ steps.chart-info.outputs.name }}-${{ steps.chart-info.outputs.version }}.tgz"
echo "package-path=/tmp/charts/$CHART_FILE" >> $GITHUB_OUTPUT
echo "Packaged: $CHART_FILE"
- name: Generate chart provenance
if: inputs.provenance
working-directory: /tmp/charts
run: |
CHART_FILE="${{ steps.chart-info.outputs.name }}-${{ steps.chart-info.outputs.version }}.tgz"
echo "Generating provenance file..."
helm provenance "$CHART_FILE" || echo "⚠️ Provenance generation failed (GPG key may not be configured)"
- name: Import GPG key
if: inputs.sign-chart
env:
GPG_KEY: ${{ secrets.gpg-private-key }}
run: |
if [ -n "$GPG_KEY" ]; then
echo "$GPG_KEY" | gpg --batch --import
gpg --list-secret-keys
else
echo "⚠️ No GPG key provided, skipping import"
fi
- name: Push chart to OCI registry
id: push
working-directory: /tmp/charts
run: |
CHART_FILE="${{ steps.chart-info.outputs.name }}-${{ steps.chart-info.outputs.version }}.tgz"
OCI_URL="oci://${{ inputs.registry }}/${{ steps.repo-path.outputs.path }}"
echo "Pushing chart to $OCI_URL..."
helm push "$CHART_FILE" "$OCI_URL" | tee push-output.log
# Extract digest from push output
DIGEST=$(grep -oP 'Digest: \K[a-f0-9]+' push-output.log || echo "")
if [ -n "$DIGEST" ]; then
echo "digest=sha256:$DIGEST" >> $GITHUB_OUTPUT
echo "Chart digest: sha256:$DIGEST"
fi
- name: Sign chart with Cosign
if: inputs.sign-chart && steps.push.outputs.digest != ''
env:
COSIGN_EXPERIMENTAL: "true"
run: |
CHART_REF="${{ inputs.registry }}/${{ steps.repo-path.outputs.path }}/${{ steps.chart-info.outputs.name }}:${{ steps.chart-info.outputs.version }}"
echo "Signing chart: $CHART_REF"
cosign sign --yes "$CHART_REF@${{ steps.push.outputs.digest }}"
echo "✅ Chart signed with keyless signature"
- name: Push to additional registries
if: inputs.multi-registry != ''
working-directory: /tmp/charts
run: |
CHART_FILE="${{ steps.chart-info.outputs.name }}-${{ steps.chart-info.outputs.version }}.tgz"
IFS=',' read -ra REGISTRIES <<< "${{ inputs.multi-registry }}"
for registry in "${REGISTRIES[@]}"; do
registry=$(echo "$registry" | xargs) # Trim whitespace
echo "Pushing to additional registry: $registry"
# Login to registry (assumes same credentials)
echo "${{ secrets.registry-password || secrets.GITHUB_TOKEN }}" | \
helm registry login "$registry" \
--username "${{ secrets.registry-username || github.actor }}" \
--password-stdin
OCI_URL="oci://$registry/${{ steps.repo-path.outputs.path }}"
helm push "$CHART_FILE" "$OCI_URL" || echo "⚠️ Push to $registry failed"
done
- name: Update Helm repository index
if: inputs.update-index
working-directory: /tmp/charts
run: |
echo "Generating Helm repository index..."
helm repo index . --url "https://${{ inputs.registry }}/${{ steps.repo-path.outputs.path }}"
if [ -f "index.yaml" ]; then
echo "✅ Repository index generated"
else
echo "⚠️ Index generation failed"
fi
- name: Create GitHub Release
if: inputs.create-release
id: release
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # v2.2.0
with:
tag_name: ${{ steps.chart-info.outputs.name }}-${{ steps.chart-info.outputs.version }}
name: ${{ steps.chart-info.outputs.name }} v${{ steps.chart-info.outputs.version }}
body: |
## 📦 Helm Chart Release
**Chart:** `${{ steps.chart-info.outputs.name }}`
**Version:** `${{ steps.chart-info.outputs.version }}`
**App Version:** `${{ steps.chart-info.outputs.app-version }}`
### Installation
```bash
# OCI Registry (recommended)
helm install my-release oci://${{ inputs.registry }}/${{ steps.repo-path.outputs.path }}/${{ steps.chart-info.outputs.name }} --version ${{ steps.chart-info.outputs.version }}
# Or from GitHub Release
helm install my-release ./${{ steps.chart-info.outputs.name }}-${{ steps.chart-info.outputs.version }}.tgz
```
### Verification
```bash
# Verify signature (if signed)
cosign verify ${{ inputs.registry }}/${{ steps.repo-path.outputs.path }}/${{ steps.chart-info.outputs.name }}:${{ steps.chart-info.outputs.version }}
```
---
*Published from commit ${{ github.sha }}*
files: |
/tmp/charts/${{ steps.chart-info.outputs.name }}-${{ steps.chart-info.outputs.version }}.tgz
/tmp/charts/${{ steps.chart-info.outputs.name }}-${{ steps.chart-info.outputs.version }}.tgz.prov
/tmp/charts/index.yaml
draft: false
prerelease: false
- name: Upload chart artifacts
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: helm-chart-${{ steps.chart-info.outputs.name }}-${{ steps.chart-info.outputs.version }}
path: |
/tmp/charts/*.tgz
/tmp/charts/*.prov
/tmp/charts/index.yaml
retention-days: 90
- name: Generate publish summary
run: |
{
echo "## 📦 Helm Chart Published"
echo ""
echo "**Chart:** \`${{ steps.chart-info.outputs.name }}\`"
echo "**Version:** \`${{ steps.chart-info.outputs.version }}\`"
echo "**App Version:** \`${{ steps.chart-info.outputs.app-version }}\`"
echo ""
echo "### Registry"
echo "- **Primary:** \`${{ inputs.registry }}/${{ steps.repo-path.outputs.path }}\`"
if [ -n "${{ inputs.multi-registry }}" ]; then
echo "- **Additional:** \`${{ inputs.multi-registry }}\`"
fi
echo ""
echo "### Installation"
echo "\`\`\`bash"
echo "helm install my-release oci://${{ inputs.registry }}/${{ steps.repo-path.outputs.path }}/${{ steps.chart-info.outputs.name }} --version ${{ steps.chart-info.outputs.version }}"
echo "\`\`\`"
if [ "${{ inputs.sign-chart }}" == "true" ]; then
echo ""
echo "✅ **Chart signed with Cosign**"
fi
if [ "${{ inputs.create-release }}" == "true" ]; then
echo ""
echo "✅ **GitHub Release created**"
fi
} >> "$GITHUB_STEP_SUMMARY"