-
Notifications
You must be signed in to change notification settings - Fork 1.4k
225 lines (199 loc) · 8.42 KB
/
kubernetes-ci.yml
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
name: WildFly Quickstarts Kubernetes CI
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
push:
# kubernetes-testing is a temporary entry
#branches: [main, kubernetes-testing]
branches: [main]
env:
KUBERNETES_CORE_DIRECTORY: .github/workflows/scripts/kubernetes/core
KUBERNETES_QS_OVERRIDES_DIRECTORY: .github/workflows/scripts/kubernetes/overrides
# Only run the latest job
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
jobs:
calculate-changed-quickstarts:
name: Matrix for Kubernetes
runs-on: ubuntu-latest
outputs:
quickstart-matrix: ${{ steps.calculate-matrix.outputs.matrix }}
steps:
# - name: Output event
# run: echo "${{ toJSON(github.event) }}"
- uses: actions/checkout@v4
- name: Get all directories
id: get-top-level-directories
run: |
declare -a test_directories
for file in ./*; do
fileName=$(basename "${file}")
if [ ! -d "${file}" ]; then
# echo "${fileName} is not a directory!"
continue
fi
test_directories+=(${fileName})
done
echo "top_dirs=${test_directories[*]}" >> $GITHUB_OUTPUT
- name: Find Changed Files
id: changed-files
uses: tj-actions/changed-files@v44
# To compare changes between the current commit and the last pushed remote commit set `since_last_remote_commit: true`. e.g
# with:
# since_last_remote_commit: true
- name: Determine changed directories
id: quickstarts-to-test
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
ALL_BASE_DIRECTORIES: ${{ steps.get-top-level-directories.outputs.top_dirs }}
run: |
# set -x
##################################################
# Look for all the changed quickstarts
echo "Checking for changed files...."
declare -a quickstarts_to_test
for file in ${ALL_CHANGED_FILES}; do
echo "Checking file ${file}"
# Changes to the .adoc and the soon-to-be retired .ci directory do not count
# Don't use quotes for the wildcard values or filtering will not work!
if [[ "${file}" == *.adoc ]] || [[ "${file}" == *.html ]] || [[ "${file}" == .ci.* ]]; then
echo "Skipping .adoc and .ci/ files!"
continue
fi
# Changes to the Kubernetes CI setup files should trigger all tests
# Don't use quotes for the wildcard values or filtering will not work!
if [[ "${file}" == ".github/workflows/kubernetes-ci.yml" ]] || [[ "${file}" == ${{ env.KUBERNETES_CORE_DIRECTORY }}/* ]]; then
echo "Detected changes in the Kubernetes CI setup file ${file}. All tests will need to be run."
root_dir_file_changed=1
break
fi
# Don't use quotes for the wildcard values or filtering will not work!
if [[ "${file}" == ${{ env.KUBERNETES_CORE_DIRECTORY }}/qs_overrides/.* ]]; then
# Work out the name of the quickstarts
IFS='/' read -ra parts <<< "${file}"
IFS='/' read -ra core_dir_parts <<< "${{ env.KUBERNETES_CORE_DIRECTORY }}/qs_overrides"
qs_dir_index=${#core_dir_parts[@]}
qs_dir_index=$((qs_dir_index + 1))
echo "Adding '${parts[$qs_dir_index]}' to the list of quickstarts since ${file} was changed"
quickstarts_to_test+=(${parts[$qs_dir_index]})
fi
# All changes to files in the root folder apply to all quickstarts
IFS='/' read -ra parts <<< "${file}"
if [ "${#parts[@]}" == 1 ] && [ "${parts[0]}" != '.gitignore' ] ; then
echo "Changed detected in ${file} which is in the root directory. All tests will need to be run."
root_dir_file_changed=1
break
else
echo "Adding (${parts[0]}) to the list of quickstarts"
quickstarts_to_test+=(${parts[0]})
fi
done
if [ "${root_dir_file_changed}" == "1" ]; then
quickstarts_to_test=(${ALL_BASE_DIRECTORIES[@]})
fi
echo "Got initial list of quickstarts. Deduping..."
# Dedupe
declare -a tmp
output_dirs=$(printf "%s\n" "${quickstarts_to_test[@]}" | sort -u)
for dir in ${output_dirs}; do
tmp+=(${dir})
done
quickstarts_to_test=(${tmp[@]})
echo "Current list of quickstarts before checking whether they can be run"
echo "${quickstarts_to_test[*]})"
############################################################
# Now filter the quickstarts we found depending on if they have been enhanced
echo "Checking which quickstarts can be run...."
declare -a tmp2
for fileName in "${quickstarts_to_test[@]}"; do
echo "Checking ${fileName}"
# Quickstarts that have not been migrated yet
grep -q "^${fileName}$" ${{ env.KUBERNETES_CORE_DIRECTORY }}/excluded-directories.txt && is_in_excluded=1 || is_in_excluded=0
if [ "${is_in_excluded}" = "1" ]; then
echo "Skipping ${fileName} since it is excluded!"
continue
fi
if [ ! -f "./.github/workflows/quickstart_${fileName}_ci.yml" ]; then
echo "Skipping ${fileName} since it has no ./.github/workflows/quickstart_${fileName}_ci.yml!"
continue
fi
if [ ! -d "./${fileName}/charts" ]; then
echo "Skipping ${fileName} since it has no ./${fileName}/charts!"
continue
fi
echo "Adding ${fileName} to the list"
tmp2+=(${fileName})
done
quickstarts_to_test=(${tmp2[@]})
echo "quickstarts_to_test=${quickstarts_to_test[*]}" >> $GITHUB_OUTPUT
- name: Calculate Matrix and Output Quickstart List
id: calculate-matrix
env:
QUICKSTARTS_TO_TEST: ${{ steps.quickstarts-to-test.outputs.quickstarts_to_test }}
run: |
set -x
matrix="{\"quickstart\":["
first=1
echo "The list of quickstarts has been determined to:"
for qs_dir in ${QUICKSTARTS_TO_TEST}; do
echo "${qs_dir}"
if [ "${first}" = "0" ]; then
matrix="${matrix}, "
fi
matrix="${matrix}\"${qs_dir}\""
first=0
done
matrix="${matrix}]}"
echo "Calculated Matrix JSON: ${matrix}"
echo "matrix=${matrix}" >> $GITHUB_OUTPUT
run-tests-on-kubernetes:
name: Test on Kubernetes
runs-on: ubuntu-latest
needs: calculate-changed-quickstarts
if: ${{ needs.calculate-changed-quickstarts.outputs.quickstart-matrix != null }}
strategy:
matrix: ${{fromJSON(needs.calculate-changed-quickstarts.outputs.quickstart-matrix)}}
steps:
- name: Setup Minikube
id: minikube
uses: manusa/[email protected]
with:
driver: docker
container runtime: containerd
minikube version: 'v1.33.0'
kubernetes version: 'v1.30.0'
github token: ${{ secrets.GITHUB_TOKEN }}
start args: "--memory='4gb' --cpus='2'"
- name: Enable minikube registry
run: |
minikube addons enable registry
kubectl port-forward --namespace kube-system service/registry 5000:80 &
- uses: azure/[email protected]
with:
version: v3.14.2
- name: Add WildFly Helm Chart
run: |
helm repo add wildfly https://docs.wildfly.org/wildfly-charts/
helm repo update wildfly
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21.3
- uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
cache: 'maven'
cache-dependency-path: '${{ matrix.quickstart }}/**/pom.xml'
- name: Run the Quickstart tests
shell: bash
run: |
${{ env.KUBERNETES_CORE_DIRECTORY }}/run-quickstart-test-on-kubernetes.sh ${{ matrix.quickstart }} && passed=1 || passed=0
if [ "${passed}" = "1" ]; then
echo "Tests for ${qs_dir} PASSED!"
else
echo "Tests for ${qs_dir} FAILED!"
exit 1
fi