Skip to content

Commit 97130d5

Browse files
committed
ci: speed up environment setup and C++ builds
1 parent c4af821 commit 97130d5

3 files changed

Lines changed: 52 additions & 19 deletions

File tree

‎.github/scripts/configure-matrix.py‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
"""Configure SCons and CxxTest for the CI matrix."""
22

3+
import json
34
from pathlib import Path
45

5-
test_requirements = Path("requirements/tests.txt").read_text().splitlines()
6+
requirements = ["python"]
7+
for filename in ("build.txt", "conda.txt", "tests.txt"):
8+
for line in (Path("requirements") / filename).read_text().splitlines():
9+
spec = line.split("#", 1)[0].strip()
10+
if spec and spec != "cxxtest":
11+
requirements.append(spec)
12+
613
Path("build").mkdir(exist_ok=True)
7-
Path("build/matrix-tests.txt").write_text(
8-
"\n".join(line for line in test_requirements if line.strip() != "cxxtest")
14+
Path("build/matrix-environment.yml").write_text(
15+
json.dumps(
16+
{
17+
"name": "test",
18+
"channels": ["conda-forge"],
19+
"dependencies": requirements,
20+
},
21+
indent=2,
22+
)
923
+ "\n"
1024
)
1125

@@ -19,7 +33,16 @@
1933
env.Replace(CXXTEST=os.path.join(cxxtest, 'bin', 'cxxtestgen'),
2034
CXXTEST_INSTALL_DIR=cxxtest, CXXTEST_PYTHON=sys.executable)
2135
22-
if env['PLATFORM'] != 'win32':
36+
if env['PLATFORM'] == 'win32':
37+
from SCons.Platform.win32 import exec_spawn
38+
39+
# The outer CI shell already activates conda and SCons configures MSVC.
40+
# /D stops each compiler/test-generator child from repeating cmd AutoRun.
41+
def spawn_without_autorun(sh, escape, cmd, args, child_env):
42+
return exec_spawn([sh, '/D', '/C', escape(' '.join(args))], child_env)
43+
44+
env['SPAWN'] = spawn_without_autorun
45+
else:
2346
env.Replace(CXX=os.environ.get('CXX', os.path.join(prefix, 'bin', 'c++')))
2447
env.Prepend(CCFLAGS=['-isystem' + os.path.join(prefix, 'include')])
2548
env.Append(LIBPATH=os.path.join(prefix, 'lib'))

‎.github/workflows/matrix-and-codecov.yml‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
- published
1111
workflow_dispatch:
1212

13+
concurrency:
14+
group: matrix-${{ github.ref }}
15+
cancel-in-progress: ${{ github.event_name != 'release' }}
16+
1317
jobs:
1418
matrix-coverage:
1519
name: C++ tests (${{ matrix.os }}, Python ${{ matrix.python-version }})
@@ -24,15 +28,19 @@ jobs:
2428
- os: ubuntu-latest
2529
shell: bash -l {0}
2630
build: coverage
31+
jobs: 4
2732
- os: windows-latest
2833
shell: cmd /C CALL {0}
2934
build: fast
35+
jobs: 4
3036
- os: macos-latest
3137
shell: bash -l {0}
3238
build: fast
39+
jobs: 2
3340
- os: macos-15-intel
3441
shell: bash -l {0}
3542
build: fast
43+
jobs: 4
3644
defaults:
3745
run:
3846
shell: ${{ matrix.shell }}
@@ -55,28 +63,26 @@ jobs:
5563
ref: 191adddb3876ab389c0c856e1c03874bf70f8ee4
5664
path: build/cxxtest
5765

58-
- name: Initialize miniconda
66+
- name: Prepare C++ test configuration
67+
shell: python {0}
68+
run: |
69+
import runpy
70+
runpy.run_path('.github/scripts/configure-matrix.py')
71+
72+
- name: Create build environment
5973
uses: conda-incubator/setup-miniconda@v3
6074
with:
6175
activate-environment: test
6276
channels: conda-forge
6377
conda-remove-defaults: "true"
64-
auto-update-conda: true
78+
auto-update-conda: false
6579
auto-activate-base: false
6680
python-version: ${{ matrix.python-version }}
67-
68-
- name: Prepare C++ test configuration
69-
run: python .github/scripts/configure-matrix.py
70-
71-
- name: Install requirements
72-
run: >-
73-
conda install --yes --override-channels -c conda-forge
74-
--file requirements/build.txt
75-
--file requirements/conda.txt
76-
--file build/matrix-tests.txt
81+
environment-file: build/matrix-environment.yml
82+
channel-priority: strict
7783

7884
- name: Build and run C++ tests
79-
run: scons -j2 build=${{ matrix.build }} test
85+
run: scons -j${{ matrix.jobs }} build=${{ matrix.build }} test
8086

8187
- name: Generate coverage report
8288
if: runner.os == 'Linux' && matrix.python-version == '3.14'

‎.github/workflows/tests-on-pr.yml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
pull_request:
55
workflow_dispatch:
66

7+
concurrency:
8+
group: tests-on-pr-${{ github.event.pull_request.number || github.ref }}
9+
cancel-in-progress: true
10+
711
jobs:
812
tests-on-pr:
913
runs-on: ubuntu-latest
@@ -23,7 +27,7 @@ jobs:
2327
activate-environment: test
2428
channels: conda-forge
2529
conda-remove-defaults: "true"
26-
auto-update-conda: true
30+
auto-update-conda: false
2731
auto-activate-base: false
2832

2933
- name: Conda config
@@ -53,7 +57,7 @@ jobs:
5357
- name: Build and run C++ tests with coverage
5458
run: |
5559
"$CONDA_PREFIX/bin/c++" --version
56-
scons build=coverage test
60+
scons -j4 build=coverage test
5761
5862
- name: Generate coverage report
5963
run: >-

0 commit comments

Comments
 (0)