Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7d7b3f4

Browse files
committedOct 25, 2021
Make Github workflows runners cry
1 parent eb7c96d commit 7d7b3f4

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed
 
Lines changed: 35 additions & 0 deletions
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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,31 @@ 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+
RESULT="fooo"
74+
echo "::set-output name=tests-data::$RESULT"
6375
76+
test:
77+
needs: tests-collector
6478
strategy:
6579
matrix:
6680
operating-system:
6781
- ubuntu-latest
6882
- windows-latest
6983
- 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
84+
tests: ${{ fromJSON(needs.tests-collector.outputs.tests-data) }}
8785

8886
runs-on: ${{ matrix.operating-system }}
8987

@@ -121,4 +119,4 @@ jobs:
121119
run: task poetry:install-deps
122120

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

0 commit comments

Comments
 (0)
Please sign in to comment.