-
Notifications
You must be signed in to change notification settings - Fork 16
186 lines (176 loc) · 6.81 KB
/
Copy pathpull-request-checks.yml
File metadata and controls
186 lines (176 loc) · 6.81 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
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
jobs:
tests:
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
py-ver: ["py311", "py312", "py313"]
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Cache conda environment
id: conda-env-cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
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'
run: |
# Check cache hasn't pulled a partial key match.
test ! -e "${HOME}/conda-env"
conda create --prefix="${HOME}/conda-env" --file=requirements/locks/${{ matrix.py-ver }}-lock-linux-64.txt
- name: Add conda environment to PATH
run: echo "${HOME}/conda-env/bin" >> $GITHUB_PATH
- name: Run tests
env:
PY_COLORS: "1"
run: |
# Install package and run pytest.
echo '::group::Installing local package'
pip install --no-deps .
echo '::endgroup::'
echo '::group::Running unit tests'
pytest -n logical --verbose --cov --cov-append --cov-config=pyproject.toml
echo '::endgroup::'
mv .coverage ".coverage.${{ matrix.py-ver }}"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: coverage-data-${{ matrix.py-ver }}
path: .coverage.*
retention-days: 1
include-hidden-files: true
coverage-report:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 20
needs: tests
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Setup python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
with:
python-version: "3.x"
- name: Install coverage
run: pip install coverage
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
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 }}
run: |
# This links to a hosted version of the HTML report.
tar -czf coverage-report.tar.gz htmlcov/
report_url="$(curl -sSf --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 "[](${report_url})" >> ${{ runner.temp }}/cov-report.md
# Edit last comment if it exists, else create new one.
if ! gh pr comment --repo "${{ github.repository }}" --edit-last --create-if-none "${{ github.head_ref }}" --body-file "${{ runner.temp }}/cov-report.md" ; then
echo "Failed to post comment. This is likely due to this being a PR from a fork."
fi
- name: Check 95% minimum coverage
run: coverage report --fail-under=95
pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
with:
python-version: "3.x"
- uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
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: 20
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Cache conda environment
id: conda-env-cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
with:
key: conda|${{runner.os}}-${{runner.arch}}|${{hashFiles('requirements/locks/py313-lock-linux-64.txt')}}
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/py313-lock-linux-64.txt
- name: Add conda environment to PATH
run: echo "${HOME}/conda-env/bin" >> $GITHUB_PATH
- name: Build documentation with Sphinx
run: |
# Install module so it can be imported during docs generation.
echo '::group::Installing local package'
pip install --no-deps .
echo '::endgroup::'
# Generate the documentation
echo '::group::Building the documentation'
sphinx-build -b html --color --fail-on-warning "docs/source" "docs/build/html"
echo '::endgroup::'
- name: Upload documentation artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: html-docs
path: docs/build/html/
retention-days: 7
if-no-files-found: error
pages-deploy:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
timeout-minutes: 20
needs: build-docs
steps:
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
name: html-docs
- uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa
with:
path: "."
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e