-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (175 loc) · 5.82 KB
/
test-ci.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
linter-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python "3.10"
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Black setup
shell: bash
run: pip install black ruff mypy
- name: Black Check
shell: bash
run: black . --diff --color --check
test-cpu:
runs-on: ubuntu-latest
needs: linter-check
strategy:
fail-fast: true
matrix:
python-version: ["3.12", "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
shell: bash
run: |
python --version
python -m pip install --upgrade pip
python -m pip install .[test]
- name: Run Tests
shell: bash
run: |
export COVERAGE_FILE=coverage_${{ matrix.python-version }}
pytest -n auto --ignore=tests/phantoms/test_brainweb.py --ignore=tests/phantoms/test_osf.py --cov --disable-pytest-warnings --cov-branch --cov-report=term
- name: Upload coverage
if: success()
uses: actions/upload-artifact@v4
with:
name: coverage_${{ matrix.python-version }}
path: coverage_${{ matrix.python-version }}
get-commit-message:
runs-on: ubuntu-latest
outputs:
message: ${{ steps.get_commit_message.outputs.message }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get commit message
id: get_commit_message
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
echo "Commit message $COMMIT_MESSAGE"
echo "::set-output name=message::$COMMIT_MESSAGE"
coverage:
runs-on: ubuntu-latest
needs: [test-cpu, get-commit-message]
if: ${{ always() }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Collect Coverages
uses: actions/download-artifact@v4
with:
path: coverage_data
pattern: coverage_*
merge-multiple: true
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: add the coverage tool
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install coverage[toml]
python -m pip install -e .
- name: Combine coverage
run: |
export COVERAGE_FILE=coverage_combined
coverage combine -a coverage_data/*
- name: Upload Combined coverage
uses: actions/upload-artifact@v4
with:
name: coverage_combined
path: coverage_combined
- name: Reports
run: |
export COVERAGE_FILE=coverage_combined
coverage xml
coverage report
echo COVERAGE_PERC=$(coverage report | tail -n 1 | grep -oE [0-9\.]*?% | cut -d '%' -f1) >> $GITHUB_ENV
- name: Create a Coverage Badge
if: ${{github.event_name == 'push'}}
run: |
wget https://img.shields.io/badge/coverage-${{env.COVERAGE_PERC}}%25-green -O coverage_badge.svg
- name: Upload badge as artifact
if: ${{github.event_name == 'push'}}
uses: actions/upload-artifact@v4
with:
name: coverage_badge
path: coverage_badge.svg
BuildDocs:
name: Build API Documentation
runs-on: ubuntu-latest
needs: get-commit-message
if: ${{ contains(needs.get-commit-message.outputs.message, '!docs_build') || github.ref == 'refs/heads/main' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get history and tags for SCM versioning to work
run: |
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
shell: bash -l {0}
run: |
python -m pip install --upgrade pip
python -m pip install .[doc]
python -m pip install -r docs/requirements.txt
- name: Build API documentation
run: |
python -m sphinx docs docs_build
- name: Display data
run: ls -R
working-directory: docs_build/_static
- name: Upload artifact
id: artifact-upload-step
uses: actions/upload-artifact@v4
with:
# Upload the docs
name: docs
path: 'docs_build'
retention-days: 5
CompileDocs:
name: Compile the coverage badge in docs
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
needs: [BuildDocs, coverage]
steps:
- name: Get the docs_build artifact
uses: actions/download-artifact@v4
with:
name: docs
path: docs_build
overwrite: true
- name: Get the badge from CI
uses: actions/download-artifact@v4
with:
name: coverage_badge
path: docs_build/_static
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: ReUpload artifacts
uses: actions/upload-artifact@v4
with:
name: docs_final
retention-days: 20
path: docs_build