-
-
Notifications
You must be signed in to change notification settings - Fork 0
280 lines (269 loc) · 8.96 KB
/
test.yml
File metadata and controls
280 lines (269 loc) · 8.96 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
name: Test
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_call:
defaults:
run:
shell: bash
permissions:
contents: read
concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true
env:
MIN_COVERAGE: 90
PUB_ENVIRONMENT: bot.github
jobs:
analyze:
name: "Analyze"
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v5
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart;commands:codegen-test"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart
os:ubuntu-latest;pub-cache-hosted;sdk:stable
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1
with:
sdk: stable
- id: checkout
name: Checkout repository
uses: actions/checkout@v6
- id: install
name: Install dependencies
run: dart pub get
- name: Check the formatting of one or more Dart files
run: dart format lib test --output=none --set-exit-if-changed .
- name: Analyze the project's Dart code
run: dart analyze lib test --fatal-infos
minimum_dart_meta:
name: "Read minimum Dart SDK"
needs: analyze
runs-on: ubuntu-latest
outputs:
min_dart: ${{ steps.read_min_dart.outputs.min_dart }}
steps:
- id: checkout
name: Checkout repository
uses: actions/checkout@v6
- id: read_min_dart
name: Read minimum Dart SDK from pubspec.yaml
run: |
set -euo pipefail
min_dart="$(yq -r '.environment.sdk | capture("(?<min>[0-9]+\.[0-9]+\.[0-9]+)").min' pubspec.yaml)"
if [[ -z "${min_dart}" ]]; then
echo 'failed to read minimum Dart SDK from pubspec.yaml' >&2
exit 1
fi
echo "min_dart=${min_dart}" >> "$GITHUB_OUTPUT"
minimum_dart:
name: "Minimum Dart (${{ needs.minimum_dart_meta.outputs.min_dart }}, ${{ matrix.platform }})"
needs: minimum_dart_meta
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- platform: chrome
- platform: vm
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v5
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:${{ needs.minimum_dart_meta.outputs.min_dart }};packages:qs_dart;commands:codegen-test"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:${{ needs.minimum_dart_meta.outputs.min_dart }};packages:qs_dart
os:ubuntu-latest;pub-cache-hosted;sdk:${{ needs.minimum_dart_meta.outputs.min_dart }}
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1
with:
sdk: ${{ needs.minimum_dart_meta.outputs.min_dart }}
- id: checkout
name: Checkout repository
uses: actions/checkout@v6
- id: install
name: Install dependencies
run: dart pub get
- name: Analyze the project's Dart code
if: ${{ matrix.platform == 'vm' }}
run: dart analyze lib test
- name: Run the project's tests in Chrome
if: ${{ matrix.platform == 'chrome' }}
run: dart test --platform chrome
- name: Run the project's tests on the VM
if: ${{ matrix.platform == 'vm' }}
run: dart test --platform vm
test:
name: "Test"
needs: analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- platform: chrome
- platform: vm
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v5
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart;commands:codegen-test"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart
os:ubuntu-latest;pub-cache-hosted;sdk:stable
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1
with:
sdk: stable
- id: checkout
name: Checkout repository
uses: actions/checkout@v6
- id: install
name: Install dependencies
run: dart pub get
- name: Run the project's tests in Chrome
if: ${{ matrix.platform == 'chrome' }}
run: dart test --platform chrome
- name: Install coverage dependencies
if: ${{ matrix.platform == 'vm' }}
run: |
dart pub global activate coverage
dart pub global activate remove_from_coverage
- name: Collect and report coverage
if: ${{ matrix.platform == 'vm' }}
run: |
dart pub global run coverage:test_with_coverage
dart pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '\.g\.dart$'
- name: Upload coverage to Codecov
if: ${{ matrix.platform == 'vm' }}
continue-on-error: true
uses: codecov/codecov-action@v6
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: techouse/qs
files: ./coverage/lcov.info
verbose: true
- name: Check Code Coverage
if: ${{ matrix.platform == 'vm' }}
run: |
set -euo pipefail
awk -F: -v min="$MIN_COVERAGE" '
/^LF:/ { total += $2 }
/^LH:/ { hit += $2 }
END {
if (total == 0) {
print "::error::No executable lines found in coverage/lcov.info"
exit 1
}
coverage = (hit / total) * 100
printf("Line coverage: %.2f%% (%d/%d)\n", coverage, hit, total)
if (coverage < min) {
printf("::error::Coverage %.2f%% is below %.2f%%\n", coverage, min)
exit 1
}
}
' coverage/lcov.info
- name: Upload coverage to Codacy
if: ${{ matrix.platform == 'vm' }}
continue-on-error: true
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage/lcov.info
ensure_compatibility:
name: "Ensure compatibility with qs"
needs: analyze
runs-on: ubuntu-latest
steps:
- name: Cache Pub hosted dependencies
uses: actions/cache@v5
with:
path: "~/.pub-cache/hosted"
key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart;commands:codegen-test"
restore-keys: |
os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart
os:ubuntu-latest;pub-cache-hosted;sdk:stable
os:ubuntu-latest;pub-cache-hosted
os:ubuntu-latest
- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: 24
- id: checkout
name: Checkout repository
uses: actions/checkout@v6
- id: install_dart_dependencies
name: Install Dart dependencies
run: dart pub get
- id: install_node_dependencies
name: Install Node dependencies
working-directory: test/comparison
run: npm install
- name: Run a comparison test between qs_dart and qs for JavaScript
working-directory: test/comparison
run: |
set -e
node_output=$(node qs.js)
dart_output=$(dart run qs.dart)
if [ "$node_output" == "$dart_output" ]; then
echo "The outputs are identical."
else
echo "The outputs are different."
exit 1
fi
ci_required:
name: "CI Required"
if: ${{ always() }}
needs:
- analyze
- minimum_dart
- test
- ensure_compatibility
runs-on: ubuntu-latest
env:
ANALYZE_RESULT: ${{ needs.analyze.result }}
MINIMUM_DART_RESULT: ${{ needs.minimum_dart.result }}
TEST_RESULT: ${{ needs.test.result }}
ENSURE_COMPATIBILITY_RESULT: ${{ needs.ensure_compatibility.result }}
steps:
- name: Verify required job results
run: |
set -euo pipefail
results=(
"analyze:${ANALYZE_RESULT}"
"minimum_dart:${MINIMUM_DART_RESULT}"
"test:${TEST_RESULT}"
"ensure_compatibility:${ENSURE_COMPATIBILITY_RESULT}"
)
failed=0
for entry in "${results[@]}"; do
job="${entry%%:*}"
result="${entry#*:}"
echo "${job}: ${result}"
if [[ "${result}" != "success" ]]; then
echo "::error::${job} finished with result '${result}'"
failed=1
fi
done
exit "${failed}"