forked from grafana-community/helm-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
188 lines (162 loc) · 6.24 KB
/
Copy pathdiff.yaml
File metadata and controls
188 lines (162 loc) · 6.24 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
name: Diff
permissions: {}
on:
pull_request:
branches:
- main
jobs:
generate-jobs:
name: generate-jobs
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
changed: ${{ steps.list-changed.outputs.changed }}
changed_list: ${{ steps.list-changed.outputs.changed_list }}
values_files_json: ${{ steps.list-changed.outputs.values_files_json }}
steps:
- name: Checkout Code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Helm
uses: azure/setup-helm@dda3372f752e03dde6b3237bc9431cdc2f7a02a2 # v5.0.0
with:
# renovate: github=helm/helm
version: v4.2.0
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.14'
- name: Set up chart-testing
uses: helm/chart-testing-action@6ec842c01de15ebb84c8627d2744a0c2f2755c9f # v2.8.0
with:
# renovate: github=helm/chart-testing
version: v3.14.0
- name: Run chart-testing (list-changed)
id: list-changed
#language=bash
run: |
set -euo pipefail
# get changed charts (one per line)
changed=$(ct list-changed --config .github/linters/ct.yaml)
# normalize and count changed charts
changed_trimmed=$(echo "$changed" | sed '/^\s*$/d')
num_changed=$(echo "$changed_trimmed" | sed '/^\s*$/d' | wc -l | tr -d ' ')
if [[ -z "$changed_trimmed" ]]; then
# nothing changed
{
echo "changed=false"
echo "changed_list="
echo "values_files_json=[]"
} >> "$GITHUB_OUTPUT"
exit 0
fi
if [ "$num_changed" -gt 1 ]; then
echo "More than one chart changed (count=$num_changed). Failing."
echo "$changed_trimmed"
exit 1
fi
# single chart changed: compute ci/*-values.yaml files for that chart
chart_path=$(echo "$changed_trimmed" | head -n1 | tr -d '"')
# extract chart name (basename)
chart_name=$(basename "$chart_path")
values_json="[]"
# look for ci/*-values.yaml under the chart directory
# enable nullglob so the glob expands to empty array when no match
shopt -s nullglob
files=(charts/"$chart_name"/ci/*-values.yaml)
if [ ${#files[@]} -gt 0 ]; then
values_json="["
sep=""
for f in "${files[@]}"; do
# ensure we only include files
if [ -f "$f" ]; then
# make path relative to workspace root
relpath="$f"
values_json+="$sep\"$relpath\""
sep=","
fi
done
values_json+="]"
fi
shopt -u nullglob
{
echo "changed=true"
echo "changed_list=\"$chart_path\""
echo "values_files_json=$values_json"
} >> "$GITHUB_OUTPUT"
# The following steps are only used to detect changes and produce the
# list of values files. The per-values-file diff runs are executed in a
# separate matrix job below.
diff:
name: diff
needs: generate-jobs
runs-on: ubuntu-latest
if: needs.generate-jobs.outputs.changed == 'true'
strategy:
fail-fast: false
matrix:
valuefile: ${{ fromJson(needs.generate-jobs.outputs.values_files_json) }}
steps:
- name: Checkout Code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Helm
uses: azure/setup-helm@dda3372f752e03dde6b3237bc9431cdc2f7a02a2 # v5.0.0
with:
# renovate: github=helm/helm
version: v4.2.0
- name: install helm diff plugin
run: helm plugin install https://github.com/databus23/helm-diff --version 3.15.4 --verify=false
- name: Create kind cluster
uses: helm/kind-action@ef37e7f390d99f746eb8b610417061a60e82a6cc # v1.14.0
- name: Checkout Target of PR
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
path: target
ref: ${{ github.event.pull_request.base.ref }}
persist-credentials: false
- name: Apply Gateway API CRDs
run: kubectl apply -k https://github.com/kubernetes-sigs/gateway-api/config/crd
- name: Apply KEDA CRDs
run: kubectl apply --server-side -f "https://github.com/kedacore/keda/releases/download/v${KEDA_VERSION}/keda-${KEDA_VERSION}-crds.yaml"
env:
#renovate: github=kedacore/keda
KEDA_VERSION: 2.19.0
- name: Run diff for value file
env:
value_file: "${{ matrix.valuefile }}"
#language=bash
run: |
set -euo pipefail
IFS=$'\n\t'
echo "Running diff for value file: $value_file"
# extract chart name from path like charts/<chart>/ci/<file>
# dirname twice: charts/<chart>/ci -> charts/<chart>, basename -> <chart>
chart="$(basename "$(dirname "$(dirname "$value_file")")")"
helm dependency update "./target/charts/$chart"
helm dependency update "./charts/$chart"
# install current target chart into cluster so helm diff has a baseline
helm upgrade -i "$chart" "./target/charts/$chart" \
--create-namespace \
--namespace "$chart" \
--wait \
--values "$value_file"
{
printf '```diff\n'
helm diff upgrade "$chart" "./charts/$chart" \
--namespace "$chart" \
--suppress=CustomResourceDefinition \
--normalize-manifests \
--reset-values \
--no-color \
-C 5 \
--suppress-output-line-regex="helm.sh/chart:" \
--suppress-output-line-regex="chart:" \
--suppress-output-line-regex="app.kubernetes.io/version:" \
--values "$value_file" | tee /dev/stderr
printf '\n```'
} > "$GITHUB_STEP_SUMMARY"