-
Notifications
You must be signed in to change notification settings - Fork 11
141 lines (114 loc) · 3.91 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
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
if: always() # Run this step even if the previous one fails
run: |
black --check jaxley tests
- name: Check imports with isort
id: isort
if: always() # Run this step even if the previous one fails
run: |
isort -c jaxley tests
- name: Check license headers
id: license
if: always() # Run this step even if the previous one fails
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
# Extract the first two lines of the file
file_header_1=$(head -n 1 "$file")
file_header_2=$(head -n 2 "$file" | tail -n 1)
# Compare the first line
if [ "$file_header_1" != "$expected_header_1" ]; then
echo "❌ Missing or incorrect license header in $file"
exit 1
fi
# Compare the second line
if [ "$file_header_2" != "$expected_header_2" ]; then
echo "❌ Missing or incorrect license header in $file"
exit 1
fi
done < <(find jaxley tests -name "*.py" -type f)
if [ $exit_code -ne 0 ]; then
exit 1
fi
- name: Ensure that the changelog was updated
id: changelog
if: github.event_name == 'pull_request' # Only run on pull requests
run: |
# Ensure the main branch is up-to-date
git fetch origin main
# Check if CHANGELOG.md was updated
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. Please add your changes if significant. Otherwise, this check can be safely ignored."
exit 1
fi
- name: Final check
if: always() # Run this step even if the previous one fails
run: |
failed_checks=()
if [[ "${{ steps.black.outcome }}" != "success" ]]; then
failed_checks+=("black formatting")
fi
if [[ "${{ steps.isort.outcome }}" != "success" ]]; then
failed_checks+=("isort imports")
fi
if [[ "${{ steps.license.outcome }}" != "success" ]]; then
failed_checks+=("license headers")
fi
if [[ "${{ steps.changelog.outcome }}" != "success" && "${{ github.event_name }}" == "pull_request" ]]; then
failed_checks+=("changelog update")
fi
if (( ${#failed_checks[@]} > 0 )); then
echo "❌ The following checks failed:"
printf '%s\n' "${failed_checks[@]}"
exit 1
fi
echo "✅ All checks passed"
pytest:
name: Pytest
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: Test with pytest
run: |
pip install pytest pytest-cov
pytest tests/ -m "not regression" --cov=jaxley --cov-report=xml