-
Notifications
You must be signed in to change notification settings - Fork 16
220 lines (190 loc) · 7 KB
/
Copy pathpull-request-checks.yml
File metadata and controls
220 lines (190 loc) · 7 KB
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
name: Pull request checks
on:
pull_request:
push:
branches:
- "main"
workflow_dispatch:
# Cancel running pull request checks if another commit is pushed.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Minimise default GITHUB_TOKEN permissions.
permissions: {}
jobs:
tests:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
strategy:
fail-fast: false
matrix:
py-ver: ["py312", "py313", "py314"]
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
- name: Cache conda environment
id: conda-env-cache
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae
with:
key: conda|${{runner.os}}-${{runner.arch}}|${{ hashFiles(format('requirements/locks/{0}-lock-linux-64.txt', matrix.py-ver)) }}
path: |
~/conda-env
~/.local/share/cartopy
- name: Create conda environment
if: steps.conda-env-cache.outputs.cache-hit != 'true'
env:
py_ver: ${{ matrix.py-ver }}
run: |
# Check cache hasn't pulled a partial key match.
test ! -e "${HOME}/conda-env"
conda create --prefix="${HOME}/conda-env" --file=requirements/locks/${py_ver}-lock-linux-64.txt
- name: Add conda environment to PATH
run: echo "${HOME}/conda-env/bin" >> $GITHUB_PATH
- name: Install local package
run: pip install --no-deps .
- name: Run fast tests
env:
PY_COLORS: "1"
py_ver: ${{ matrix.py-ver }}
run: |
make test-fast
mv .coverage ".coverage.${py_ver}"
- name: Upload coverage data as artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: coverage-data-${{ matrix.py-ver }}
path: .coverage.*
retention-days: 1
include-hidden-files: true
coverage-report:
if: github.event_name == 'pull_request'
name: Produce coverage report
runs-on: ubuntu-latest
timeout-minutes: 5
needs: tests
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
- name: Setup python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
with:
python-version: "3.x"
- name: Install coverage
run: pip install coverage
- name: Download coverage artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
with:
pattern: coverage-data-*
merge-multiple: true
- name: Generate coverage report
run: |
coverage combine
coverage html
- name: Add report to PR
env:
GH_TOKEN: ${{ github.token }}
tmpweb_api_key: ${{ secrets.TMPWEB_API_KEY }}
repository: ${{ github.repository }}
head_ref: ${{ github.head_ref }}
run: |
# This links to a hosted version of the HTML report.
tar -czf coverage-report.tar.gz htmlcov/
report_url="$(curl -sSf --user "token:${tmpweb_api_key}" --data-binary @coverage-report.tar.gz https://tmpweb.net || true)"
if [[ -z "${report_url}" ]] ; then
echo "Could not upload report."
else
echo "Report hosted at $report_url"
badge_options="$(coverage json --fail-under=0 -qo - | jq -r .totals.percent_covered_display)%25-blue?style=for-the-badge"
echo "[](${report_url})" >> cov-report.md
# Edit last comment if it exists, else create new one.
if ! gh pr comment --repo "${repository}" --edit-last --create-if-none "${head_ref}" --body-file cov-report.md ; then
echo "Failed to post comment. This is likely due to this being a PR from a fork."
fi
fi
- name: Check 90% minimum coverage
run: coverage report --fail-under=90
pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
with:
python-version: "3.x"
- name: Restore pre-commit cache
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae
with:
key: pre-commit|${{runner.os}}-${{runner.arch}}|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
path: ~/.cache/pre-commit
- name: Set up pre-commit
run: pip install pre-commit
- name: Run pre-commit
env:
RUFF_OUTPUT_FORMAT: github
run: pre-commit run --show-diff-on-failure --color=always --all-files
build-docs:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
- name: Cache conda environment
id: conda-env-cache
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae
with:
key: conda|${{runner.os}}-${{runner.arch}}|${{hashFiles('requirements/locks/latest')}}
path: |
~/conda-env
~/.local/share/cartopy
- name: Create conda environment
if: steps.conda-env-cache.outputs.cache-hit != 'true'
run: |
# Check cache hasn't pulled a partial key match.
test ! -e "${HOME}/conda-env"
conda create --prefix="${HOME}/conda-env" --file=requirements/locks/latest
- name: Add conda environment to PATH
run: echo "${HOME}/conda-env/bin" >> $GITHUB_PATH
- name: Install package so it can be imported during docs generation
run: pip install --no-deps .
- name: Build documentation with Sphinx
run: sphinx-build -b html --color "docs/source" "docs/build/html"
- name: Upload documentation artifact
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9
with:
path: docs/build/html/
retention-days: 1
pages-deploy:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
name: Deploy documentation to GitHub Pages
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-slim
timeout-minutes: 5
needs: build-docs
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128