-
Notifications
You must be signed in to change notification settings - Fork 21
205 lines (187 loc) · 7.08 KB
/
application-test.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
name: Application Specific Test Suite
on:
workflow_dispatch:
inputs:
scenario:
description: 'The scenario to run, e.g., install or upgrade'
required: true
default: 'install'
type: string
version_ref:
description: 'The NKP version(git branch or tag) to run install/upgrade test. Using latest version by default e.g., v2.8.0-dev'
default: 'main'
type: string
pull_request:
types: [synchronize, labeled, opened, reopened]
push:
branches:
- main
jobs:
setup-pr:
name: Extract app names from PR Labels
runs-on:
- ubuntu-latest
if: github.event_name == 'pull_request' && contains(join(github.event.pull_request.labels.*.name, ' '), 'services/')
outputs:
apps: ${{ steps.pr-labels.outputs.apps }}
steps:
- name: Collect apps to run tests from PR labels
id: pr-labels
run: |
# Extract labels from the pull request event payload
PR_LABELS=$(echo "${{ join(github.event.pull_request.labels.*.name, ' ') }}")
KAPP_NAMES=()
for label in $PR_LABELS; do
echo $label
if [[ "$label" == "services/"* ]]; then
KAPP_NAMES+=("$(echo "$label" | cut -d '/' -f 2)")
fi
done
json_array=$(printf '%s\n' "${KAPP_NAMES[@]}" | jq -R . | jq -c -s .)
echo "apps=${json_array}" >> $GITHUB_OUTPUT
setup-all-apps:
name: Extract app names from local repo
runs-on:
- ubuntu-latest
if: contains(fromJSON('["workflow_dispatch", "push"]'), github.event_name)
outputs:
apps: ${{ steps.local-apps.outputs.apps }}
steps:
# manually trigger ALL scenarios for ALL apps
- name: Checkout code
uses: actions/checkout@v4
- name: Collect apps from local directory
id: local-apps
working-directory: services
run: |
json_array=$(find . -type d -maxdepth 1 -mindepth 1 -exec basename {} \; | jq -R . | jq -c -s .)
echo "apps=${json_array}" >> $GITHUB_OUTPUT
generate-upgrade-versions:
name: Generate upgrade versions
runs-on:
- ubuntu-latest
if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.scenario == 'install') }}
outputs:
upgrade-versions: ${{ steps.get-matrix.outputs.result }}
to_version: ${{ steps.prepare-upgrade-versions.outputs.to_version }}
from_versions: ${{ steps.prepare-upgrade-versions.outputs.from_versions }}
steps:
- name: checkout upgrade matrix
uses: actions/checkout@v4
with:
sparse-checkout: |
upgrade-matrix.yaml
sparse-checkout-cone-mode: false
- uses: chrisdickinson/setup-yq@latest
with:
yq-version: v4.25.3
- name: Set output
id: prepare-upgrade-versions
run: |
upgrade_matrix=$(yq '.upgrades' -I0 -o json upgrade-matrix.yaml)
latest=$(echo $upgrade_matrix | jq -r 'map(.to) | max')
from_versions=''
to_version=''
to_version_gh_dkp=''
if [[ "${{ github.event_name }}" == "push" ]]; then
to_version_gh_dkp=$latest
to_version="main"
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
if [[ "${{ github.base_ref }}" == 'main' ]]; then
to_version_gh_dkp=$latest
to_version="main"
else
if [[ "${{ github.base_ref }}" == "release-*" ]]; then
dkp_ver_majorminor=$(echo ${{ github.base_ref }} | cut -d '-' -f 2)
to_version_gh_dkp="v$dkp_ver_majorminor"
else
# TODO: handle stacked PRs
echo "triggering app test in stacked PRs are not supported yet"
exit 1
fi
fi
to_version=${{ github.head_ref }}
else
# workflow_dispatch event
if [[ "${{ inputs.version_ref }}" == "main" ]]; then
to_version_gh_dkp=$latest
to_version="main"
else
if [[ "${{ inputs.version_ref }}" == release-* ]]; then
dkp_ver_majorminor=$(echo ${{ inputs.version_ref }} | cut -d '-' -f 2)
to_version_gh_dkp="v$dkp_ver_majorminor"
else
to_version_gh_dkp=${{ inputs.version_ref }}
fi
to_version=${{ inputs.version_ref }}
fi
fi
from_versions=$(echo $upgrade_matrix | jq -c --arg to "$to_version_gh_dkp" 'map(select(.to | startswith($to))) | map(. | .from)')
echo "from_versions=${from_versions}"
echo "to_version=${to_version}"
echo "from_versions=${from_versions}" >> $GITHUB_OUTPUT
echo "to_version=${to_version}" >> $GITHUB_OUTPUT
trigger-install-tests-pr:
needs: setup-pr
uses: ./.github/workflows/application-test-scenario-install.yaml
strategy:
fail-fast: false
matrix:
apps: ${{ fromJson(needs.setup-pr.outputs.apps) }}
with:
version_ref: ${{ github.head_ref }}
apps: ${{ matrix.apps }}
secrets: inherit
trigger-tests-all-apps-install-ondemand:
needs: setup-all-apps
if: ${{ github.event_name == 'workflow_dispatch' && inputs.scenario == 'install' || github.event_name == 'push' }}
uses: ./.github/workflows/application-test-scenario-install.yaml
strategy:
fail-fast: false
matrix:
apps: ${{ fromJson(needs.setup-all-apps.outputs.apps) }}
with:
version_ref: ${{ github.event.inputs.version_ref }}
apps: ${{ matrix.apps }}
trigger-tests-all-apps-install-push:
needs: setup-all-apps
if: ${{ github.event_name == 'push' }}
uses: ./.github/workflows/application-test-scenario-install.yaml
strategy:
fail-fast: false
matrix:
apps: ${{ fromJson(needs.setup-all-apps.outputs.apps) }}
with:
version_ref: "main"
apps: ${{ matrix.apps }}
trigger-upgrade-tests-pr:
needs:
- generate-upgrade-versions
- setup-pr
uses: ./.github/workflows/application-test-scenario-upgrade.yaml
strategy:
fail-fast: false
matrix:
from: ${{ fromJson(needs.generate-upgrade-versions.outputs.from_versions) }}
apps: ${{ fromJson(needs.setup-pr.outputs.apps) }}
with:
apps: ${{ matrix.apps }}
from_version_ref: ${{ matrix.from }}
to_version_ref: ${{ needs.generate-upgrade-versions.outputs.to_version }}
secrets: inherit
trigger-tests-all-apps-upgrade:
needs:
- generate-upgrade-versions
- setup-all-apps
if: ${{ github.event_name == 'workflow_dispatch' && inputs.scenario == 'upgrade' || github.event_name == 'push' }}
uses: ./.github/workflows/application-test-scenario-upgrade.yaml
strategy:
fail-fast: false
matrix:
from: ${{ fromJson(needs.generate-upgrade-versions.outputs.from_versions) }}
apps: ${{ fromJson(needs.setup-all-apps.outputs.apps) }}
with:
apps: ${{ matrix.apps }}
from_version_ref: ${{ matrix.from }}
to_version_ref: ${{ needs.generate-upgrade-versions.outputs.to_version }}
secrets: inherit