Skip to content

Commit d313210

Browse files
author
Eric Swanson
authored
chore: read directory to determine tests (#3)
1 parent d5a333f commit d313210

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

.github/scripts/test-matrix.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
import json
3+
4+
TEST_DIR = "bin/icp-cli/tests"
5+
6+
MACOS_TESTS = ["hello_tests"]
7+
8+
def test_names():
9+
all_files = os.listdir(TEST_DIR)
10+
rust_files = filter(lambda f: f.endswith(".rs"), all_files)
11+
return [f"{filename[:-3]}" for filename in rust_files]
12+
13+
include = []
14+
for test in test_names():
15+
# Ubuntu: run everything
16+
include.append({
17+
"test": test,
18+
"os": "ubuntu-22.04"
19+
})
20+
21+
# macOS: only run selected tests
22+
if test in MACOS_TESTS:
23+
include.append({
24+
"test": test,
25+
"os": "macos-13"
26+
})
27+
28+
29+
matrix = {
30+
"include": include,
31+
}
32+
33+
print(json.dumps(matrix))

.github/workflows/test.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@ on:
77
pull_request:
88

99
jobs:
10+
discover:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
matrix: ${{ steps.set-matrix.outputs.matrix }}
14+
steps:
15+
- uses: actions/checkout@v4
16+
- id: set-matrix
17+
run: echo "matrix=$(python3 .github/scripts/test-matrix.py)" >> $GITHUB_OUTPUT
18+
1019
test:
1120
name: ${{ matrix.test }} on ${{ matrix.os }}
21+
needs: discover
1222
runs-on: ${{ matrix.os }}
1323
strategy:
1424
fail-fast: false
15-
matrix:
16-
os: [ubuntu-latest, macos-latest]
17-
test:
18-
- hello_tests
25+
matrix: ${{fromJson(needs.discover.outputs.matrix)}}
1926

2027
steps:
2128
- uses: actions/checkout@v4

0 commit comments

Comments
 (0)