-
-
Notifications
You must be signed in to change notification settings - Fork 258
242 lines (227 loc) · 8.06 KB
/
ci.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
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
name: CI
on:
create:
push:
branches:
- "master"
tags:
- "v*"
pull_request:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
dependencies:
name: Prepare Dependencies
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Setup dependencies
uses: ./.github/actions/deps-setup
detect-repo-changes:
name: Detected Repo Changes
runs-on: ubuntu-22.04
outputs:
helms-changed: ${{ steps.changed_charts.outputs.matrix }}
no-changes: ${{ steps.changed_charts.outputs.no_changes }}
cicd-definition-changed: ${{ steps.filter.outputs.cicd-definitions }}
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
base: master
#`-helm` suffix aims that we can easily filter helm charts
filters: |
example-idp-helm:
- 'helm/charts/example-idp/**'
- 'hacks/values/example-idp.yaml'
hydra-helm:
- 'helm/charts/hydra/**'
- 'hacks/values/hydra-maester.yaml'
hydra-maester-helm:
- 'helm/charts/hydra-maester/**'
- 'hacks/values/hydra-maester.yaml'
keto-helm:
- 'helm/charts/keto/**'
- 'hacks/values/keto.yaml'
kratos-helm:
- 'helm/charts/kratos/**'
- 'hacks/values/kratos.yaml'
kratos-selfservice-ui-node-helm:
- 'helm/charts/kratos-selfservice-ui-node/**'
- 'hacks/values/kratos-selfservice-ui-node.yaml'
oathkeeper-helm:
- 'helm/charts/oathkeeper/**'
- 'hacks/values/oathkeeper.yaml'
oathkeeper-maester-helm:
- 'helm/charts/oathkeeper-maester/**'
- 'hacks/values/oathkeeper-maester.yaml'
cicd-definitions:
- '.github/workflows/**'
- '.github/actions/**'
# This step will take output from paths-filter and then process it in order to get what helm charts have been updated
# It allows us to do matrix in validating & testing process
- name: Generate helm chart matrix to be validated
id: changed_charts
env:
FILTER_OUTPUT: ${{ toJson(steps.filter.outputs) }}
FORCE_FULL_RUN:
${{ github.ref_type == 'tag' ||
steps.filter.outputs['cicd-definitions'] == 'true' }}
shell: bash
run: |
updated_charts=$(echo "$FILTER_OUTPUT" | jq -r 'to_entries | map(select((.key | endswith("-helm")) and .value == "true")) | map(.key)')
# shellcheck disable=SC2001
updated_charts=$(echo "$updated_charts" | sed "s/-helm//g")
echo "ForceFullRun: ${FORCE_FULL_RUN}"
if [[ "$FORCE_FULL_RUN" == "true" ]]; then
echo "Forcing tests to be running on every charts as CI running in release context"
# shellcheck disable=SC2012
updated_charts=$(ls ${{ github.workspace }}/helm/charts/ -I "ory-commons" | tr -d " " | jq --raw-input --slurp 'split("\n") | map(select(. != ""))')
fi
if [[ "$updated_charts" == "[]" ]]; then
echo "no_changes=true" >> "$GITHUB_OUTPUT"
fi
# shellcheck disable=SC2116,SC2086
echo "matrix={\"chart\":$(echo $updated_charts)}\"" >> "$GITHUB_OUTPUT"
echo "Charts array to run CI on: $updated_charts"
check:
name: Check Helm Chart '${{ matrix.chart }}'
if:
${{ needs.detect-repo-changes.outputs.no-changes != 'true' && github.ref
!= 'ref/heads/master' }}
needs: [dependencies, detect-repo-changes]
runs-on: ubuntu-22.04
env:
HELM_PLUGINS: ${{ github.workspace }}/.bin/plugins
HELM_CHART: ${{ matrix.chart }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout dependencies
uses: ./.github/actions/deps-setup
- name: Lint helm chart
run: make helm-lint
- name: Validate helm chart
run: make helm-validate
- uses: kubescape/github-action@main
with:
format: json
outputFile: results
files: "helm/charts/${{ matrix.chart }}"
verbose: true
severityThreshold: high
controlsConfig: ".github/kubescape-control.json"
exceptions: ".github/kubescape-exceptions.json"
frameworks: |
AllControls,ArmoBest,DevOpsBest,mitre,nsa,SOC2
strategy:
matrix: ${{ fromJson(needs.detect-repo-changes.outputs.helms-changed) }}
test-upgrade:
name: Upgrade Helm Chart '${{ matrix.chart }}'
if:
${{ needs.detect-repo-changes.outputs.no-changes != 'true' && github.ref
!= 'ref/heads/master' }}
needs: [check, detect-repo-changes, dependencies]
runs-on: ubuntu-22.04
env:
HELM_PLUGINS: ${{ github.workspace }}/.bin/plugins
HELM_CHART: ${{ matrix.chart }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout dependencies
uses: ./.github/actions/deps-setup
- name: Test upgrade for helm chart
run: make helm-upgrade
strategy:
matrix: ${{ fromJson(needs.detect-repo-changes.outputs.helms-changed) }}
test-install:
name: Install Helm Chart '${{ matrix.chart }}'
if:
${{ needs.detect-repo-changes.outputs.no-changes != 'true' && github.ref
!= 'ref/heads/master' }}
needs: [check, detect-repo-changes, dependencies]
runs-on: ubuntu-22.04
env:
HELM_PLUGINS: ${{ github.workspace }}/.bin/plugins
HELM_CHART: ${{ matrix.chart }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout dependencies
uses: ./.github/actions/deps-setup
- name: Test install for helm chart
run: make helm-test
strategy:
matrix: ${{ fromJson(needs.detect-repo-changes.outputs.helms-changed) }}
helm-docs:
name: Generate documentation
runs-on: ubuntu-22.04
if: ${{ always() && github.ref == 'refs/heads/master' }}
env:
HELM_DOCS_VERSION: "1.11.0"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.ORY_BOT_PAT }}
- name: Checkout dependencies
uses: ./.github/actions/deps-setup
- name: Push commit
shell: bash
run: |
git config --global user.email "[email protected]"
git config --global user.name "ory-bot"
git checkout -b dirty HEAD
git add -A
git commit -m "Regenerate helm docs
[skip ci]" || echo "No changes to commit"
git push origin HEAD:master
release:
name: Release
if: ${{ github.ref_type == 'tag' }}
needs: [test-install, test-upgrade]
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.ORY_BOT_PAT }}
- name: Checkout dependencies
uses: ./.github/actions/deps-setup
- name: Define current tag version
shell: bash
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> "$GITHUB_ENV"
- name: Release helm charts
run: make release
- name: Push commit for release
shell: bash
run: |
git config --global user.email "[email protected]"
git config --global user.name "ory-bot"
git checkout -b make-release HEAD
git add -A
git commit -a -m "Release ${RELEASE_VERSION}
[skip ci]" || echo "No changes to commit"
git push origin HEAD:master
gha-lint:
name: Lint GithubAction files
if:
${{ needs.detect-repo-changes.outputs.cicd-definition-changed == 'true' }}
needs: [detect-repo-changes]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: actionlint
id: actionlint
uses: raven-actions/actionlint@v1
with:
fail-on-error: true