-
-
Notifications
You must be signed in to change notification settings - Fork 6
247 lines (210 loc) · 6.56 KB
/
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
---
name: CI
on:
push:
paths:
- 'src/**'
- 'tests/**'
- '.github/workflows/CI.yml'
- 'pyproject.toml'
- 'poetry.lock'
- 'docs/**'
pull_request:
branches:
- main
- 'release**'
paths:
- 'src/**'
- 'tests/**'
- '.github/workflows/CI.yml'
- 'pyproject.toml'
- 'poetry.lock'
- 'docs/**'
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
python-version: ['3.10', '3.11']
steps:
- uses: actions/checkout@v3
# Set up Python environment
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
# Setup macOS
- name: Setup macOS
if: runner.os == 'macOS'
run: brew install libomp
# Install Poetry
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python -
# Add Poetry to PATH
- name: Add Poetry to PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
# Configure poetry
- name: Configure poetry
run: poetry config virtualenvs.in-project true
# Cache Poetry dependencies
- name: Cache Poetry dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-poetry-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-${{ matrix.python-version }}-
${{ runner.os }}-poetry-
${{ runner.os }}-
# Ensure cache is healthy
- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
shell: bash
run: poetry run pip --version > /dev/null 2>&1 || { echo "Cache is stale, clearing cache and exiting." && rm -rf .venv && exit 1; }
# Upgrade pip
- name: Upgrade pip
shell: bash
run: poetry run python -m pip install --upgrade pip
# Install dependencies
- name: Install dependencies
run: |
poetry install
# Install dtaidistance
- name: Install dtaidistance
run: |
if [ "${{ matrix.python-version }}" != "3.10" ] && \
[ "${{ matrix.python-version }}" != "3.11" ]; then \
poetry run python -m pip install dtaidistance
fi
# Run pre-commit hooks
#- name: Run pre-commit hooks
# uses: pre-commit/[email protected]
# Run tests
- name: Test with pytest
run: |
poetry run python -m pytest tests -vv --cov=src/ \
--cov-report term --junitxml=report.xml
# --cov-fail-under=${{ secrets.TEST_COVERAGE_THRESHOLD }} \
# Generate coverage report
- name: Generate coverage report
run: |
poetry run python -m coverage xml
poetry run pycobertura show coverage.xml --format html --output coverage.html
if: always()
# Convert coverage report to markdown
- name: Install pandoc on macOS
if: runner.os == 'macOS' && always()
run: |
brew install pandoc
- name: Convert coverage report to markdown (macOS)
if: runner.os == 'macOS' && always()
run: |
pandoc coverage.html -t gfm -o coverage.md
- name: Convert coverage report to markdown (Ubuntu)
uses: docker://pandoc/core:3.1
if: runner.os == 'Linux' && always()
with:
args: "coverage.html -t gfm -o coverage.md"
# Generate concise coverage report
- name: Generate concise coverage report
if: always()
run: |
if [[ -f "coverage.md" ]]; then
sed -n '/####/q;p' coverage.md > coverage_concise.md
if grep -q "<div>" coverage_concise.md; then
echo "</div>" >> coverage_concise.md
else
echo "Warning: No opening <div> tag found in coverage_concise.md."
fi
else
echo "Error: coverage.md file not found."
exit 1
fi
# Retrieve PR number to publish coverage report to
- name: Retrieve PR number to publish coverage report to
uses: jwalton/gh-find-current-pr@v1
id: finder
if: always()
with:
state: all
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Add coverage report to PR
- name: Add coverage report to PR
uses: marocchino/sticky-pull-request-comment@v2
if: always()
with:
number: ${{ steps.finder.outputs.pr }}
recreate: true
path: coverage_concise.md
# Upload coverage report
- name: Upload coverage report
uses: actions/upload-artifact@v2
with:
name: coverage
path: coverage.md
# Publish coverage report to PR
- name: Publish coverage to PR
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v4
docs:
name: Test docs build
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python -
# Add Poetry to PATH
- name: Add Poetry to PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
# Cache Poetry dependencies
- name: Cache Poetry dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
${{ runner.os }}-
# Configure poetry
- name: Configure poetry
run: poetry config virtualenvs.in-project true
# Install dependencies using poetry
- name: Install dependencies
run: |
poetry install
# Install Sphinx
- name: Install Sphinx
run: poetry add sphinx
# Build sphinx documentation
- name: Build sphinx documentation
run: |
cd docs
poetry run make clean
poetry run make html --debug --jobs 2 SPHINXOPTS="-W -v"
# Upload built docs
- name: Upload built docs
uses: actions/upload-artifact@v2
with:
name: docs-results-${{ runner.os }}
path: docs/build/html/
# Use always() to always run this step to publish test results when there are test failures
if: success()