Repository navigation
145 lines (130 loc) · 6.22 KB
/
Copy pathtest_cpu.yml
File metadata and controls
145 lines (130 loc) · 6.22 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
name: Test CPU
on:
pull_request:
branches:
- main
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
test:
name: Test ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
environment: "full-cpu"
name: "ubuntu all optional dependencies and doctests"
pytest_args: "-n 2 --dist=loadgroup --doctest-modules"
- os: ubuntu-latest
environment: "test-cpu"
name: "ubuntu no optional dependencies"
pytest_args: "-n 2 --dist=loadgroup"
- os: windows-latest
environment: "full-cpu"
name: "windows all optional dependencies"
pytest_args: "-n 0 --dist=loadgroup" # n = 0 to avoid conflicts with pytest-xdist on windows
env:
DEEPINV_MOCK_TESTS: "True"
DEEPINV_DOWNLOAD_VERBOSE: "False"
# Persist deepinv's URL cache to a workspace-local folder so it can be
# cached across CI runs (see actions/cache steps below). This avoids
# re-downloading example images, models and datasets from HuggingFace
# and prevents 429 rate-limit failures.
DEEPINV_CACHE_DIR: ${{ github.workspace }}/.cache/deepinv
CONDA_OVERRIDE_CUDA: "12.0" # mock cuda to fix non-GPU builds for optional dependencies
steps:
- uses: actions/checkout@v5
# On PRs, restore the pixi.lock + .testmondata + .coverage triple solved on main as a
# SINGLE cache entry, so it is restored atomically (no lock/testmondata
# mismatch). pixi then installs the exact same package set that produced
# .testmondata, keeping testmon's environment fingerprint stable
# (otherwise an unpinned env re-solves every run, drifts, and forces a
# full re-run). Restored *before* Setup Pixi so the action installs from
# this lock. Not restored on push to main: main solves fresh to track
# latest deps (and re-runs the full suite anyway).
- name: Restore pixi.lock + .testmondata + .coverage
if: github.event_name == 'pull_request'
uses: actions/cache/restore@v4
with:
path: |
pixi.lock
.testmondata
.coverage
key: testmon-cpu-main-${{ matrix.environment }}-${{ matrix.os }}-${{ github.run_id }}
restore-keys: |
testmon-cpu-main-${{ matrix.environment }}-${{ matrix.os }}-
- name: Setup Pixi
uses: prefix-dev/setup-pixi@v0.9.3
with:
pixi-version: latest
run-install: false # we drive installation manually below
# Install dependencies with pixi, using the restored lock if available. If the
# lock is unavailable or fails to solve, fall back to a fresh solve.
- name: Install dependencies
shell: bash
run: |
set -x
if ! pixi install -e ${{ matrix.environment }} --locked --manifest-path pyproject.toml --color always; then
echo "pixi install with --locked option failed, run install without lock"
pixi install -e ${{ matrix.environment }} --manifest-path pyproject.toml --color always
fi
pixi list -e ${{ matrix.environment }} --manifest-path pyproject.toml --color always
set +x
- name: Restore deepinv URL cache # shared across matrix environments
uses: actions/cache/restore@v4
with:
path: ${{ env.DEEPINV_CACHE_DIR }}
key: deepinv-url-cache-${{ matrix.os }}-${{ github.run_id }}
restore-keys: |
deepinv-url-cache-${{ matrix.os }}-
# On main, we never restore the cache, so .testmondata and .coverage never exist. We run the full suite to compute a base coverage for the main branch, we also run testmon to compute a base .testmondata for the main branch.
# On PRs, we restore the cache from main, so testmon skips unrelated tests and --cov-append updates coverage with respect to related changes.
# In case .coverage is not restored properly (for any reasons), but .testmondata is restored, we run pytest without testmon to compute full coverage results. This is a corner case that should not happen, but we handle it anyway.
- name: Test with pytest
shell: bash
run: |
TESTMON_FLAG="--testmon"
if [ -f .testmondata ] && [ ! -f .coverage ]; then
TESTMON_FLAG=""
fi
set -x
pixi run -e ${{ matrix.environment }} pytest ${{ matrix.pytest_args }} --cov=deepinv --cov-report=xml:coverage-${{ matrix.environment }}.xml --cov-append $TESTMON_FLAG --durations=30 --junit-xml pytest_report_${{ matrix.environment }}.xml
set +x
# Save the freshly-solved lock + .testmondata + .coverage as a single (atomic) cache
# entry so PRs always restore a matching pair. Only on push to main.
- name: Save pixi.lock + .testmondata + .coverage # only when pushed to main, not for PRs
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/cache/save@v4
with:
path: |
pixi.lock
.testmondata
.coverage
key: testmon-cpu-main-${{ matrix.environment }}-${{ matrix.os }}-${{ github.run_id }}
- name: Save deepinv URL cache # only on push to main, mirrors testmondata
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/cache/save@v4
with:
path: ${{ env.DEEPINV_CACHE_DIR }}
key: deepinv-url-cache-${{ matrix.os }}-${{ github.run_id }}
- name: Upload coverage to Codecov
if: runner.os == 'Linux' && matrix.environment == 'full-cpu'
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage-${{ matrix.environment }}.xml
flags: ${{ matrix.environment }}
name: ${{ matrix.environment }}-coverage
- name: Upload pytest report
id: upload-artifact
uses: actions/upload-artifact@v4
with:
name: pytest-report-${{ matrix.environment }}
path: pytest_report_${{ matrix.environment }}.xml