-
Notifications
You must be signed in to change notification settings - Fork 1
219 lines (174 loc) · 6.07 KB
/
test.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
name: Test
# Run only one unique workflow at a time on a pr
# https://docs.github.com/en/actions/using-jobs/using-concurrency#example-using-a-fallback-value
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
on:
pull_request:
paths:
- ".github/workflows/test.yml"
- "bin/**"
- "functions/**"
- "lib/**"
- "test/**"
- "pubspec.yaml"
workflow_dispatch:
jobs:
build-executables:
name: Build executables
uses: ./.github/workflows/build_alfa_cli.yml
test-functions-schema:
name: Test functions schema
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
matrix:
sdk: [stable, 3.0, 3.1, 3.2, 3.3, 3.4]
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}
- name: Install dependencies
run: dart pub get
- name: Run tests
run: dart test -n 'function schema'
- name: Verify alfa help works
run: dart run alfa -h
find-functions:
name: Find functions that changed
runs-on: ubuntu-latest
timeout-minutes: 15
outputs:
matrix: ${{ env.matrix }}
length: ${{ env.length }}
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Install dependencies
run: dart pub get
- name: Get available functions
run: dart run test/bin/get_functions.dart -f /tmp/filters.yml -m /tmp/matrix.json
- name: Print filters
run: cat /tmp/filters.yml
- name: Print matrix
run: jq . /tmp/matrix.json
- uses: dorny/paths-filter@v3
id: changes
with:
filters: /tmp/filters.yml
- name: Output changes to json
run: |
echo '${{ steps.changes.outputs.changes }}' > /tmp/changes.json
jq . /tmp/changes.json
- name: Create filtered matrix
run: |
# filters matrix with only changes
jq -c --argfile names /tmp/changes.json '{include: .include | map(select(.name | IN($names[])))}' /tmp/matrix.json > /tmp/filtered_matrix.json
# prints json file for debugging
jq . /tmp/filtered_matrix.json
# sets matrix output
echo "matrix=$(cat /tmp/filtered_matrix.json)" >> $GITHUB_ENV
echo "length=$(jq 'length' /tmp/changes.json)" >> $GITHUB_ENV
test-installing-functions:
name: Test installing functions
runs-on: ${{ matrix.os }}
timeout-minutes: 15
needs:
- build-executables
- test-functions-schema
- find-functions
if: ${{ needs.find-functions.outputs.length != '0' }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.find-functions.outputs.matrix) }}
env:
ALFA_TEST_CONTAINER_NAME: ${{ matrix.image && 'alfa-test' }}
ALFA_INSTALL_LOG_FILEPATH: alfa-install.log
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Set alfa permissions
run: chmod +x alfa_*
- name: Add setup to install list file
if: ${{ matrix.setup-tag }}
env:
INSTALL_ITEM: ${{ matrix.setup-tag }}
run: echo "$INSTALL_ITEM" >> test_install_list.txt
- name: Add install tag to install list file
if: ${{ matrix.install-tag }}
env:
INSTALL_ITEM: ${{ matrix.install-tag }}
run: echo "$INSTALL_ITEM" >> test_install_list.txt
- name: Add name to install list file
if: ${{ !matrix.install-tag }}
env:
INSTALL_ITEM: ${{ matrix.name }}
run: echo "$INSTALL_ITEM" >> test_install_list.txt
- name: Add teardown to install list file
if: ${{ matrix.teardown-tag }}
env:
INSTALL_ITEM: ${{ matrix.teardown-tag }}
run: echo "$INSTALL_ITEM" >> test_install_list.txt
- name: Print install list
run: cat test_install_list.txt
- name: Print help message
if: ${{ !matrix.image }}
run: |
sudo ./install.sh -h
- name: Test install
if: ${{ !matrix.image }}
run: |
set -euo pipefail
sudo ./install.sh -e -c test/resources/functions/${{ matrix.name }}/test_config.toml -f test_install_list.txt 2>&1 | tee $ALFA_INSTALL_LOG_FILEPATH
- name: Create docker command script
if: ${{ matrix.image }}
run: |
SCRIPT=$(cat << EOF
#!/bin/bash
set -euo pipefail
./install.sh -h
./install.sh -e -c test/resources/functions/${{ matrix.name }}/test_config.toml -f test_install_list.txt 2>&1 | tee $ALFA_INSTALL_LOG_FILEPATH
EOF
)
echo "$SCRIPT" > run.sh
chmod +x run.sh
- name: Setup arm emulation with qemu
if: ${{ matrix.image && matrix.platform == 'linux/arm64' }}
run: |
sudo apt-get update -q -y
sudo apt-get -qq install -y qemu qemu-user-static
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes --credential yes
- name: Test install with docker
if: ${{ matrix.image }}
run: |
docker run \
--name "$ALFA_TEST_CONTAINER_NAME" \
-d \
-t \
--workdir "$GITHUB_WORKSPACE" \
-v "${GITHUB_WORKSPACE}:${GITHUB_WORKSPACE}" \
${{ matrix.platform && format('--platform {0}', matrix.platform) }} \
--entrypoint bash \
'${{ matrix.image }}'
docker exec "$ALFA_TEST_CONTAINER_NAME" "${GITHUB_WORKSPACE}/run.sh"
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Install dependencies
run: dart pub get
- name: Start docker container
if: ${{ matrix.image }}
run: |
docker start "$ALFA_TEST_CONTAINER_NAME"
- name: Run tests
env:
ALFA_TEST_FUNCTION_NAME: ${{ matrix.name }}
ALFA_TEST_CASE_NAME: ${{ matrix.runner-name }}
run: |
dart test -n 'install logs'