Skip to content

Commit 4ec876a

Browse files
committed
Make Github workflows runners cry
1 parent b90b39b commit 4ec876a

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import itertools
2+
from pathlib import Path
3+
import json
4+
import re
5+
6+
7+
def get_test_functions(tests_path):
8+
test_functions_regex = re.compile(r"^def (test_[a-zA-Z_]*)\(")
9+
test_functions = []
10+
for test_file in tests_path.glob("test_*.py"):
11+
12+
for line in test_file.read_text().splitlines():
13+
if match := test_functions_regex.match(line):
14+
test_functions.append(f"{test_file}::{match.group(1)}")
15+
return test_functions
16+
17+
18+
if __name__ == "__main__":
19+
import sys
20+
21+
tests_path = sys.argv[1]
22+
test_functions = get_test_functions(Path(tests_path))
23+
24+
# We split the test functions in 80 different lists because the maximum jobs
25+
# that can be run on Github Workflows generated by the matrix syntax is 256.
26+
# Since we run all tests on Linux, Windows and Mac OS the number of this list
27+
# must be multiplied by 3. 80 * 3 == 240 so we're in the green.
28+
TESTS_SPLIT = 80
29+
cycle = itertools.cycle(range(TESTS_SPLIT))
30+
groups = [[] for _ in range(TESTS_SPLIT)]
31+
for f in test_functions:
32+
index = next(cycle)
33+
groups[index].append(f)
34+
35+
print(json.dumps([" ".join(g) for g in groups]))

.github/workflows/test-go-integration-task.yml

+16-19
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,30 @@ jobs:
5757
5858
echo "::set-output name=result::$RESULT"
5959
60-
test:
60+
tests-collector:
61+
runs-on: ubuntu-latest
6162
needs: run-determination
6263
if: needs.run-determination.outputs.result == 'true'
64+
outputs:
65+
tests-data: ${{ steps.collection.outputs.tests-data }}
66+
steps:
67+
- name: Checkout repository
68+
uses: actions/checkout@v2
69+
70+
- name: Collect tests
71+
id: collection
72+
run: |
73+
echo "::set-output name=tests-data::$(python .github/tools/get_integration_tests.py ./test/)"
6374
75+
test:
76+
needs: tests-collector
6477
strategy:
6578
matrix:
6679
operating-system:
6780
- ubuntu-latest
6881
- windows-latest
6982
- macos-latest
70-
test-file:
71-
- test/test_board.py
72-
- test/test_cache.py
73-
- test/test_compile.py
74-
- test/test_completion.py
75-
- test/test_config.py
76-
- test/test_core.py
77-
- test/test_daemon.py
78-
- test/test_debug.py
79-
- test/test_lib.py
80-
- test/test_main.py
81-
- test/test_outdated.py
82-
- test/test_sketch.py
83-
- test/test_update.py
84-
- test/test_upgrade.py
85-
- test/test_upload_mock.py
86-
- test/test_upload.py
83+
tests: ${{ fromJSON(needs.tests-collector.outputs.tests-data) }}
8784

8885
runs-on: ${{ matrix.operating-system }}
8986

@@ -121,4 +118,4 @@ jobs:
121118
run: task poetry:install-deps
122119

123120
- name: Run integration tests
124-
run: poetry run pytest ${{ matrix.test-file }}
121+
run: poetry run pytest ${{ matrix.tests }}

0 commit comments

Comments
 (0)