-
Notifications
You must be signed in to change notification settings - Fork 12
160 lines (137 loc) · 4.57 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
name: Tests
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
chores:
name: Chores
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
lfs: true
- uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Check formatting with black
id: black
run: |
black --check jaxley tests || exit 1
continue-on-error: true
- name: Check imports with isort
id: isort
run: |
isort -c jaxley tests || exit 1
continue-on-error: true
- name: Check license headers
id: license
run: |
expected_header_1="# This file is part of Jaxley, a differentiable neuroscience simulator. Jaxley is"
expected_header_2="# licensed under the Apache License Version 2.0, see <https://www.apache.org/licenses/>"
exit_code=0
while IFS= read -r file; do
file_header_1=$(head -n 1 "$file")
file_header_2=$(head -n 2 "$file" | tail -n 1)
if [ "$file_header_1" != "$expected_header_1" ]; then
echo "❌ Incorrect first line in $file"
exit_code=1
fi
if [ "$file_header_2" != "$expected_header_2" ]; then
echo "❌ Incorrect second line in $file"
exit_code=1
fi
done < <(find jaxley tests -name "*.py" -type f)
if [ $exit_code -ne 0 ]; then
exit 1
fi
- name: Ensure that the changelog reflects the changes
id: changelog
run: |
git fetch origin main
changed_files=$(git diff --name-only origin/main)
if echo "$changed_files" | grep -q 'CHANGELOG.md'; then
echo "CHANGELOG.md was updated"
else
echo "CHANGELOG.md was not updated"
exit 1
fi
- name: Set success flags
id: success_flags
run: |
if [[ "${{ steps.black.outcome }}" == "success" &&
"${{ steps.isort.outcome }}" == "success" &&
"${{ steps.license.outcome }}" == "success" ]]; then
echo "chores_success=true" >> $GITHUB_ENV
else
echo "chores_success=false" >> $GITHUB_ENV
fi
- name: Final check
id: final_check
run: |
# Check if black, isort, license, and changelog steps passed
if [[ "${{ steps.black.outcome }}" != "success" ||
"${{ steps.isort.outcome }}" != "success" ||
"${{ steps.license.outcome }}" != "success" ||
"${{ steps.changelog.outcome }}" != "success" ]]; then
echo "❌ Some checks failed!"
exit 1
fi
echo "✅ All checks passed"
pytest:
name: Pytest
runs-on: ubuntu-20.04
needs: chores # Ensure pytest only runs if chores finishes
# Run pytest only if chores steps (except changelog) were successful
if: ${{ needs.chores.result == 'success' && env.chores_success == 'true' }}
steps:
- uses: actions/checkout@v3
with:
lfs: true
- uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Test with pytest
run: |
pip install pytest pytest-cov
pytest tests/ -m "not regression" --cov=jaxley --cov-report=xml
regression_tests:
name: Regression Tests
runs-on: ubuntu-20.04
needs: pytest # Ensure regression tests are only run if pytest job passes
steps:
- uses: actions/checkout@v3
with:
lfs: true
fetch-depth: 0 # This ensures we can checkout the main branch too
- uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run benchmarks and compare to baseline
if: github.event.pull_request.base.ref == 'main' # Run only for PRs targeting the 'main' branch
run: |
# Check if regression test results exist in main branch
if git cat-file -e main:tests/regression_test_baselines.json; then
git checkout main tests/regression_test_baselines.json
else
echo "No regression test results found in main branch"
fi
pytest -m regression