-
Notifications
You must be signed in to change notification settings - Fork 18
180 lines (159 loc) · 4.88 KB
/
tests.yml
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: Tests
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
style:
name: Check the code style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: pre-commit/[email protected]
tests:
name: Run python tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set up test environment
run: |
python -m pip install --upgrade pip
pip install -e .[test]
- name: Create matrix id
id: matrix-id
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: |
echo $MATRIX_CONTEXT
export MATRIX_ID=`echo $MATRIX_CONTEXT | md5sum | cut -c 1-32`
echo $MATRIX_ID
echo "::set-output name=id::$MATRIX_ID"
- name: Run tests
run: |
pytest --cov=outlines_core -vv
env:
COVERAGE_FILE: .coverage.${{ steps.matrix-id.outputs.id }}
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: coverage-data
path: .coverage.*
if-no-files-found: ignore
include-hidden-files: true
# TODO FIXME: This is only using the last run
overwrite: true
coverage:
name: Check combined coverage
needs: [tests, cargo-test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
cache: pip
python-version: "3.11"
- name: Set up environment
run: |
pip install --upgrade "coverage[toml]>=5.1" diff-cover
- name: Install lcov
run: sudo apt-get update && sudo apt-get install -yqq lcov
- name: Download python coverage data
uses: actions/download-artifact@v4
with:
name: coverage-data
- name: Download rust coverage data
uses: actions/download-artifact@v4
with:
name: rust-coverage-data
- name: Fetch main for coverage diff
run: |
git fetch --no-tags --prune origin main
- name: Combine coverage & fail if it's <100%.
run: |
python -m coverage combine
python -m coverage lcov
lcov -a coverage.lcov -a lcov.info -o combined_coverage
genhtml combined_coverage --output-directory htmlcov
diff-cover combined_coverage --markdown-report=coverage.md --fail-under=100 || (cat coverage.md >> $GITHUB_STEP_SUMMARY && exit 1)
- name: Upload HTML report if check failed.
uses: actions/upload-artifact@v4
with:
name: html-report
path: htmlcov
# TODO FIXME: This is only using the last run
overwrite: true
if: ${{ failure() }}
build-wheel:
name: Build Wheel and Test SDist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build SDist and Wheel
run: ./.github/scripts/build_sdist_and_wheel.sh
cargo-test:
name: Run Cargo tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# toolchain choice needs to happen before cache: rustc version used as its cache key
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install cargo tarpaulin if not cached
run: |
if ! command -v cargo-tarpaulin &> /dev/null; then
echo "cargo-tarpaulin is not found, installing..."
cargo install cargo-tarpaulin
else
echo "cargo-tarpaulin is cached"
fi
- name: Generate rust code coverage
run: >
cargo tarpaulin
--out=Lcov
--output-dir=rust-coverage
--engine=llvm
--exclude-files=src/python_bindings/*
--no-dead-code
--workspace
--verbose
env:
RUSTFLAGS: -C instrument-coverage
- name: Upload rust coverage data
uses: actions/upload-artifact@v4
with:
name: rust-coverage-data
path: rust-coverage/
if-no-files-found: ignore
include-hidden-files: true
overwrite: true
cargo-audit:
name: Run Cargo audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# toolchain choice needs to happen before cache: rustc version used as its cache key
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Install cargo audit if not cached
run: |
if ! command -v cargo-audit &> /dev/null; then
echo "cargo-audit is not found, installing..."
cargo install cargo-audit
else
echo "cargo-audit is cached"
fi
- name: Run cargo audit
run: cargo audit