-
Notifications
You must be signed in to change notification settings - Fork 5
152 lines (124 loc) · 4.48 KB
/
pr_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
name: Pull request checks
on:
pull_request:
push:
branches:
- "main"
workflow_dispatch:
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Get week number
id: week
run: echo "week=$(date '+W%V')" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
key: tests|${{ runner.os }}-${{ runner.arch}}|${{ steps.week.outputs.week }}|${{ hashFiles('requirements/locks/*') }}
path: |
.tox
~/.cache/pip
- name: Install dependencies
run: python3 -m pip install tox tox-conda
- name: Run tests
env:
PY_COLORS: "1"
TOX_PARALLEL_NO_SPINNER: "1"
run: tox -e py39-linux-tests,py310-linux-tests,py311-linux-tests,py312-linux-tests
- uses: actions/upload-artifact@v4
with:
name: coverage-data
path: .coverage
retention-days: 1
coverage-report:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs: tests
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Get week number for cache
id: week
run: echo "week=$(date '+W%V')" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
key: coverage-report|${{ env.pythonLocation }}|${{ steps.week.outputs.week }}
path: ~/.cache/pip
- name: Install coverage
run: python3 -m pip install coverage
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: coverage-data
- name: Generate coverage report
run: coverage html
- name: Add report to PR
env:
GH_TOKEN: ${{ github.token }}
run: |
# This links to a hosted version of the HTML report.
tar -czf coverage-report.tar.gz htmlcov/
report_url="$(curl --data-binary @coverage-report.tar.gz https://tmpweb.net)"
badge_options="$(coverage json --fail-under=0 -qo - | jq -r .totals.percent_covered_display)%25-blue?style=for-the-badge"
echo "[![Coverage](https://img.shields.io/badge/coverage-${badge_options})](${report_url})" >> ${{ runner.temp }}/cov-report.md
# Edit last comment if it exists, else create new one.
if ! gh pr comment --edit-last ${{ github.head_ref }} --body-file ${{ runner.temp }}/cov-report.md ; then
gh pr comment ${{ github.head_ref }} --body-file ${{ runner.temp }}/cov-report.md
fi
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Get week number for cache
id: week
run: echo "week=$(date '+W%V')" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
key: pre-commit|${{ env.pythonLocation }}|${{ steps.week.outputs.week }}|${{ hashFiles('.pre-commit-config.yaml') }}
path: |
~/.cache/pip
~/.cache/pre-commit
- name: Set up pre-commit
run: python3 -m pip install pre-commit
- uses: actions/checkout@v4
- name: Run pre-commit
run: pre-commit run --show-diff-on-failure --color=always --all-files
build-docs:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache conda environment
uses: actions/cache@v3
with:
key: conda|${{ runner.os }}-${{ runner.arch}}|${{ hashFiles('requirements/locks/*') }}
path: ${{ env.CONDA }}/envs
- name: Create conda environment
if: steps.cache.outputs.cache-hit != 'true'
run: |
conda create --name=cset --file=requirements/locks/py312-lock-linux-64.txt
echo "${CONDA}/envs/cset/bin" >> $GITHUB_PATH
- name: Build documentation with Sphinx
run: |
# Install module so it can be imported during docs generation.
python3 -m pip install .
# Generate the documentation
sphinx-build -d "docs/build/doctree" "docs/source" "docs/build/html" --color -W -bhtml
- name: Upload documentation artifact
uses: actions/upload-artifact@v4
with:
name: html-docs
path: docs/build/html/
retention-days: 10
if-no-files-found: error