-
Notifications
You must be signed in to change notification settings - Fork 35
257 lines (224 loc) · 9.71 KB
/
Copy pathpreview-helm-charts.yml
File metadata and controls
257 lines (224 loc) · 9.71 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
name: Preview Helm Charts
on:
pull_request:
paths:
- 'charts/**'
jobs:
validate-chart-versions:
uses: ./.github/workflows/validate-chart-versions.yml
with:
base_ref: origin/${{ github.event.pull_request.base.ref }}
enforce_version_bump: false
detect-changes:
runs-on: ubuntu-latest
outputs:
runtime-api: ${{ steps.changes.outputs.runtime-api }}
image-loader: ${{ steps.changes.outputs.image-loader }}
openhands: ${{ steps.changes.outputs.openhands }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Detect chart changes
id: changes
run: |
BASE_REF="origin/${{ github.event.pull_request.base.ref }}"
echo "Comparing against: $BASE_REF"
# Get list of changed files
CHANGED_FILES=$(git diff --name-only $BASE_REF...HEAD)
echo "Changed files:"
echo "$CHANGED_FILES"
# Check each chart for changes
for chart in runtime-api image-loader openhands; do
if echo "$CHANGED_FILES" | grep -q "^charts/${chart}/"; then
echo "${chart}=true" >> $GITHUB_OUTPUT
echo "Changes detected in charts/${chart}"
else
echo "${chart}=false" >> $GITHUB_OUTPUT
echo "No changes in charts/${chart}"
fi
done
publish-charts:
runs-on: ubuntu-latest
needs: [validate-chart-versions, detect-changes]
permissions:
contents: read
packages: write
defaults:
run:
shell: bash
strategy:
matrix:
chart:
- name: runtime-api
path: charts/runtime-api
- name: image-loader
path: charts/image-loader
- name: openhands
path: charts/openhands
max-parallel: 1
steps:
- name: Check if chart should be published
id: check
env:
HAS_CHANGES_RUNTIME_API: ${{ needs.detect-changes.outputs.runtime-api }}
HAS_CHANGES_IMAGE_LOADER: ${{ needs.detect-changes.outputs.image-loader }}
HAS_CHANGES_OPENHANDS: ${{ needs.detect-changes.outputs.openhands }}
IS_PUBLISHABLE_RUNTIME_API: ${{ needs.validate-chart-versions.outputs.runtime-api-publishable }}
IS_PUBLISHABLE_IMAGE_LOADER: ${{ needs.validate-chart-versions.outputs.image-loader-publishable }}
IS_PUBLISHABLE_OPENHANDS: ${{ needs.validate-chart-versions.outputs.openhands-publishable }}
run: |
CHART_NAME="${{ matrix.chart.name }}"
case "$CHART_NAME" in
runtime-api)
HAS_CHANGES="$HAS_CHANGES_RUNTIME_API"
IS_PUBLISHABLE="$IS_PUBLISHABLE_RUNTIME_API"
;;
image-loader)
HAS_CHANGES="$HAS_CHANGES_IMAGE_LOADER"
IS_PUBLISHABLE="$IS_PUBLISHABLE_IMAGE_LOADER"
;;
openhands)
HAS_CHANGES="$HAS_CHANGES_OPENHANDS"
IS_PUBLISHABLE="$IS_PUBLISHABLE_OPENHANDS"
;;
esac
# Default IS_PUBLISHABLE to true if not set (assume publishable unless explicitly marked otherwise)
IS_PUBLISHABLE="${IS_PUBLISHABLE:-true}"
echo "Chart $CHART_NAME - has changes: $HAS_CHANGES, is publishable: $IS_PUBLISHABLE"
# Only publish if chart has changes AND version was bumped
if [ "$HAS_CHANGES" = "true" ] && [ "$IS_PUBLISHABLE" = "true" ]; then
echo "should_publish=true" >> $GITHUB_OUTPUT
echo "✅ Chart $CHART_NAME will be published"
else
echo "should_publish=false" >> $GITHUB_OUTPUT
if [ "$HAS_CHANGES" != "true" ]; then
echo "⏭️ Chart $CHART_NAME skipped - no changes"
else
echo "⏭️ Chart $CHART_NAME skipped - version not bumped"
fi
fi
- name: Checkout
if: steps.check.outputs.should_publish == 'true'
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Helm
if: steps.check.outputs.should_publish == 'true'
uses: azure/setup-helm@v3
with:
version: 'latest'
- name: Use PR version suffix
if: steps.check.outputs.should_publish == 'true'
run: |
# Create a preview version like 0.1.0-alpha.123
# This should confirm to SemVer, the last number is the GitHub PR number
CHART_VERSION=$(yq '.version' charts/${{ matrix.chart.name }}/Chart.yaml)
PREVIEW_VERSION="${CHART_VERSION}-alpha.${{ github.event.pull_request.number }}"
# Update Chart.yaml with preview version
yq -i ".version = \"${PREVIEW_VERSION}\"" charts/${{ matrix.chart.name }}/Chart.yaml
- name: Update runtime-api dependency version
if: steps.check.outputs.should_publish == 'true' && matrix.chart.name == 'openhands' && needs.detect-changes.outputs.runtime-api == 'true'
run: |
RUNTIME_API_VERSION=$(yq '.version' charts/runtime-api/Chart.yaml)
RUNTIME_API_PREVIEW="${RUNTIME_API_VERSION}-alpha.${{ github.event.pull_request.number }}"
yq -i "(.dependencies[] | select(.name == \"runtime-api\")).version = \"${RUNTIME_API_PREVIEW}\"" charts/openhands/Chart.yaml
helm dependency update charts/openhands
- name: Test ${{ matrix.chart.name }} chart with default values
if: steps.check.outputs.should_publish == 'true'
run: |
echo "Testing ${{ matrix.chart.name }} chart with default values"
echo "Updating dependencies for ${{ matrix.chart.name }}"
helm dependency update ${{ matrix.chart.path }}
echo "Running helm lint for ${{ matrix.chart.name }}"
helm lint ${{ matrix.chart.path }}
if [ $? -ne 0 ]; then
echo "Helm lint test failed for ${{ matrix.chart.name }}"
exit 1
fi
echo "Helm lint test passed for ${{ matrix.chart.name }}"
echo "Running helm template for ${{ matrix.chart.name }}"
helm template ${{ matrix.chart.path }} --debug
if [ $? -ne 0 ]; then
echo "Helm template test failed for ${{ matrix.chart.name }}"
exit 1
fi
echo "Helm template test passed for ${{ matrix.chart.name }}"
- name: Extract chart version and prepare repository
if: steps.check.outputs.should_publish == 'true'
id: chart_info
run: |
VERSION=$(grep '^version:' ${{ matrix.chart.path }}/Chart.yaml | awk '{print $2}')
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
echo "Using chart version: ${VERSION}"
# Ensure we are publishing to an "alpha" version.
if [[ "$VERSION" != *alpha* ]]; then
echo "Error: Version '$VERSION' does not contain 'alpha'"
exit 1
fi
# Convert repository owner to lowercase for GHCR
REPO_OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
echo "REPO_OWNER=${REPO_OWNER}" >> $GITHUB_OUTPUT
echo "Using repository owner: ${REPO_OWNER}"
- name: Publish ${{ matrix.chart.name }} chart to GHCR
if: steps.check.outputs.should_publish == 'true'
uses: appany/helm-oci-chart-releaser@v0.4.2
with:
name: ${{ matrix.chart.name }}
repository: helm-charts
path: ${{ matrix.chart.path }}
registry: ghcr.io/${{ steps.chart_info.outputs.REPO_OWNER }}
registry_username: ${{ github.actor }}
registry_password: ${{ secrets.GITHUB_TOKEN }}
update_dependencies: 'true'
tag: ${{ steps.chart_info.outputs.VERSION }}
lint-and-test:
runs-on: ubuntu-latest
needs: [publish-charts, detect-changes]
strategy:
matrix:
chart:
- name: runtime-api
path: charts/runtime-api
- name: image-loader
path: charts/image-loader
- name: openhands
path: charts/openhands
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: 'latest'
- name: Update runtime-api dependency version for openhands
if: matrix.chart.name == 'openhands' && needs.detect-changes.outputs.runtime-api == 'true'
run: |
RUNTIME_API_VERSION=$(yq '.version' charts/runtime-api/Chart.yaml)
RUNTIME_API_PREVIEW="${RUNTIME_API_VERSION}-alpha.${{ github.event.pull_request.number }}"
echo "Updating openhands runtime-api dependency to ${RUNTIME_API_PREVIEW}"
yq -i "(.dependencies[] | select(.name == \"runtime-api\")).version = \"${RUNTIME_API_PREVIEW}\"" charts/openhands/Chart.yaml
- name: Lint ${{ matrix.chart.name }} chart
run: |
echo "Testing ${{ matrix.chart.name }} chart"
echo "Updating dependencies for ${{ matrix.chart.name }}"
helm dependency update ${{ matrix.chart.path }}
echo "Running helm lint for ${{ matrix.chart.name }}"
helm lint ${{ matrix.chart.path }}
if [ $? -ne 0 ]; then
echo "Helm lint failed for ${{ matrix.chart.name }}"
exit 1
fi
echo "Helm lint passed for ${{ matrix.chart.name }}"
- name: Template ${{ matrix.chart.name }} chart
run: |
echo "Running helm template for ${{ matrix.chart.name }}"
helm template ${{ matrix.chart.path }} --debug
if [ $? -ne 0 ]; then
echo "Helm template failed for ${{ matrix.chart.name }}"
exit 1
fi
echo "Helm template passed for ${{ matrix.chart.name }}"