Skip to content

Commit 2199b9f

Browse files
authored
enh: split out ci jobs and test them for a cleaner build (#139)
* enh: split out ci jobs * enh: Fix linting CI jobs * fix: test ci jobs * fix: docs CI BUILDS * Changelog * fix: broken tests
1 parent 85309bd commit 2199b9f

File tree

9 files changed

+167
-113
lines changed

9 files changed

+167
-113
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [Unreleased]
44

5+
* Fix docs CI builds to to simplify maintenance and feedback on jobs (@lwasser, #127, #138)
6+
57
## [v0.6.7]
68

79
### Fixed
@@ -13,7 +15,7 @@
1315
* bug: ensure sphinx build works by @lwasser in https://github.com/pyOpenSci/pyos-package-template/pull/130
1416
* Move all dependencies to `optional.deps` and use hatch features (@lwasser, #131)
1517

16-
### Added
18+
### Added
1719
* Add and configure Dependabot (@agriyakhetarpal, #79)
1820

1921
### Contributors

template/pyproject.toml.jinja

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ Documentation = "{{ dev_platform_url }}/{{ username }}/{{ project_slug }}/blob/m
7070
Download = "https://pypi.org/project/{{ project_slug }}/#files"
7171

7272
[project.optional-dependencies]
73+
# The groups below should be in the [development-groups] table
74+
# They are here now because hatch hasn't released support for them but plans to
75+
# in Mid November 2025.
7376
dev = [
7477
"hatch",
7578
"pre-commit",
@@ -101,7 +104,6 @@ docs = [
101104

102105
build = [
103106
"pip-audit",
104-
"pip",
105107
"twine",
106108
]
107109

@@ -113,7 +115,7 @@ tests = [
113115
"pytest-randomly",
114116
"pytest-xdist",
115117
]
116-
{% endif %}
118+
{%- endif %}
117119

118120
{%- if use_lint %}
119121
style = [
@@ -140,12 +142,12 @@ types = [
140142
[tool.hatch.build]
141143
only-packages = true
142144

143-
# This tells Hatch to build the package from the src/me directory.
145+
# This tells Hatch to build the package from the src/ directory.
144146
# Read more about src layouts here: https://www.pyopensci.org/python-package-guide/package-structure-code/python-package-structure.html
145147
[tool.hatch.build.targets.wheel]
146148
packages = ["src/{{ package_name }}"]
147149

148-
{%- if use_vcs_version %}
150+
{% if use_vcs_version %}
149151
[tool.hatch.build.hooks.vcs]
150152
version-file = "src/{{ package_name }}/_version.py"
151153

@@ -182,7 +184,7 @@ exclude_lines = ["pragma: no cover"]
182184
precision = 2
183185
{%- endif %}
184186

185-
{%- if use_lint %}
187+
{% if use_lint %}
186188
[tool.ruff]
187189
line-length = 88
188190

@@ -238,7 +240,7 @@ check-yield-types = false
238240
{%- if use_vcs_version %}
239241
exclude = "_version.py"
240242
{%- endif %}
241-
{%- endif %}
243+
{%- endif -%}
242244

243245
{% if use_types %}
244246
# TODO: Adjust mypy configuration.
@@ -261,7 +263,6 @@ exclude = "_version.py"
261263
{%- endif %}
262264

263265
{%- if use_hatch_envs %}
264-
265266
# Use UV to create Hatch environments
266267
[tool.hatch.envs.default]
267268
installer = "uv"
@@ -289,7 +290,7 @@ check = [
289290

290291
#--------------- Run tests ---------------#
291292

292-
{% if use_test %}
293+
{%- if use_test %}
293294
[tool.hatch.envs.test]
294295
description = """Run the test suite."""
295296
features = [
@@ -300,7 +301,7 @@ features = [
300301
python = ["3.10", "3.11", "3.12", "3.13"]
301302

302303
[tool.hatch.envs.test.scripts]
303-
run = "pytest {args:--cov={{ package_name }} --cov-report=term-missing}"
304+
run = "pytest {args:--cov={{ package_name }} --cov-report=term-missing --cov-report=xml}"
304305
{%- endif %}
305306

306307
#--------------- Build and preview your documentation ---------------#
@@ -327,7 +328,7 @@ serve = ["sphinx-apidoc -o docs/api src/{{ package_name}}", "sphinx-autobuild do
327328
{%- endif %}
328329
{%- endif %}
329330

330-
{%- if use_lint %}
331+
{% if use_lint %}
331332
#--------------- Format & style your code ---------------#
332333

333334
[tool.hatch.envs.style]

template/{% if documentation == 'sphinx' %}docs{% endif %}/index.md.jinja

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,46 @@
1-
# {{ project_name }}
1+
# Welcome to {{ project_name }}'s Documentation '
22

33
## Overview
44

5-
{{ package_description }}
5+
:::{toctree}
6+
:maxdepth: 2
7+
:hidden:
8+
:caption: Contents:
9+
10+
Home <self>
11+
Documentation <documentation/index>
12+
:::
13+
14+
This is the landing page of your docs. you can update it as you'd like to.
15+
This documentation example uses myst markdown as the primary documentation syntax.
16+
17+
18+
:::{button-link} <https://www.pyopensci.org/python-package-guide/documentation/hosting-tools/myst-markdown-rst-doc-syntax.html>
19+
:color: primary
20+
:class: sd-rounded-pill float-left
21+
22+
Learn more about myst in our pyOpenSci packaging guide.
23+
24+
:::
25+
26+
Myst is a version of markdown that has more formatting flexibility.
27+
This is what a sphinx directive looks like using myst markdown formatting:
28+
29+
```markdown
30+
:::{toctree}
31+
:maxdepth: 2
32+
:caption: Contents:
33+
:::
34+
35+
```
36+
37+
If you see syntax like the syntax below, you are looking at rst.
38+
39+
```rst
40+
.. toctree::
41+
:maxdepth: 2
42+
:caption: Contents:
43+
```
644

745
[API Documentation](./api/modules.rst)
846

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Build Docs
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build-docs:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4.5.2
15+
{%- raw %}
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v5.1.0
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
{% endraw %}
21+
- name: Install hatch
22+
run: |
23+
python -m pip install --upgrade pip
24+
python -m pip install hatch
25+
26+
- name: Build documentation using Hatch
27+
run: |
28+
hatch run docs:build

template/{% if use_git and dev_platform == 'GitHub' %}.github{% endif %}/workflows/release.yml renamed to template/{% if use_git and dev_platform == 'GitHub' %}.github{% endif %}/workflows/release.yml.jinja

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
name: Publish to PyPI
22

33
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
48
release:
59
types: [published]
610

711
jobs:
8-
prerequisites:
9-
uses: ./.github/workflows/test.yml
1012
# Setup build separate from publish for added security
1113
# See https://github.com/pypa/gh-action-pypi-publish/issues/217#issuecomment-1965727093
1214
build:
13-
needs: [prerequisites]
1415
runs-on: ubuntu-latest
1516
# Environment is encouraged for increased security
1617
steps:
@@ -23,22 +24,26 @@ jobs:
2324
fetch-tags: true
2425

2526
- name: Setup Python
26-
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v5
27+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
2728
with:
2829
# You can modify what version of Python you want to use for your release
2930
python-version: "3.11"
3031

31-
# Security recommends we should pin deps. Should we pin the workflow version?
3232
- name: Install hatch
33-
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc
33+
run: |
34+
python -m pip install --upgrade pip
35+
python -m pip install hatch
3436

3537
- name: Build package using Hatch
3638
run: |
37-
hatch build
38-
echo ""
39-
echo "Generated files:"
40-
ls -lh dist/
41-
39+
{%- if use_hatch_envs %}
40+
hatch run build:check
41+
{% else %}
42+
hatch build
43+
{% endif %}
44+
echo ""
45+
echo "Generated files:"
46+
ls -lh dist/
4247
# Store an artifact of the build to use in the publish step below
4348
- name: Store the distribution packages
4449
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v4
@@ -50,15 +55,15 @@ jobs:
5055
name: >-
5156
Publish Python 🐍 distribution 📦 to PyPI
5257
# Modify the repo name below to be your project's repo name.
53-
if: github.repository_owner == "{{ username }}"
58+
if: github.repository_owner == '{{ username }}'
5459
needs:
5560
- build
5661
runs-on: ubuntu-latest
5762
# Environment required here for trusted publisher
5863
environment:
5964
name: pypi
6065
# Modify the url to be the name of your package
61-
url: https://pypi.org/p/${{ package_name }}
66+
url: https://pypi.org/p/{{ package_name }}
6267
permissions:
6368
id-token: write # this permission is mandatory for PyPI publishing
6469
steps:
@@ -69,6 +74,6 @@ jobs:
6974
path: dist/
7075
merge-multiple: true
7176
- name: Publish package to PyPI
72-
# Only publish to real PyPI on release
77+
# Only publish to real PyPI on release. This action uses sigstore for additional security.
7378
if: github.event_name == 'release' && github.event.action == 'published'
74-
uses: pypa/gh-action-pypi-publish@release/v1
79+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e #v1.13.0
Lines changed: 36 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,14 @@
1-
name: Test Suite
2-
1+
name: Run Tests
2+
# Run the test suite on pull requests and pushes to main branch
33
on:
4-
workflow_dispatch: {}
5-
workflow_call: {}
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
schedule:
9+
- cron: '0 23 * * Sun'
610

711
jobs:
8-
{%- if use_lint %}
9-
{%- raw %}
10-
lint:
11-
runs-on: ${{ matrix.os }}
12-
strategy:
13-
fail-fast: false
14-
matrix:
15-
os: [ubuntu-latest]
16-
python-version: ["3.10"]
17-
18-
steps:
19-
- uses: actions/checkout@v4
20-
21-
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v5
23-
with:
24-
python-version: ${{ matrix.python-version }}
25-
{%- endraw %}
26-
27-
{%- if use_hatch_envs %}
28-
- name: Install hatch
29-
uses: pypa/hatch@install
30-
31-
- name: Check code style
32-
run: hatch run style:code
33-
34-
- name: Check docstrings
35-
run: hatch run style:docstrings
36-
37-
- name: Build documentation
38-
run: hatch run docs:build
39-
{%- endif %}
40-
{%- endif %}
41-
4212
{%- raw %}
4313
test:
4414
runs-on: ${{ matrix.os }}
@@ -49,37 +19,43 @@ jobs:
4919
python-version: ["3.10", "3.13"]
5020

5121
steps:
52-
- uses: actions/checkout@v4
22+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4.5.2
5323

5424
- name: Set up Python ${{ matrix.python-version }}
55-
uses: actions/setup-python@v5
25+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v5.1.0
5626
with:
5727
python-version: ${{ matrix.python-version }}
5828
{%- endraw %}
5929

6030
{%- if use_hatch_envs %}
6131
- name: Install hatch
62-
uses: pypa/hatch@install
63-
64-
- name: Check installation
65-
run: hatch run install:check
66-
67-
- name: Check dependencies
68-
run: hatch run audit:check
69-
70-
{%- if use_types %}
71-
- name: Check types
72-
run: hatch run types:check
73-
{%- endif %}
74-
75-
{%- if use_test %}
32+
run: |
33+
python -m pip install --upgrade pip
34+
python -m pip install hatch
7635
{%- raw %}
77-
- name: Test suite
36+
- name: Run test suite
7837
run: hatch run +py=${{ matrix.python-version }} test:run
79-
80-
- name: Report coverage
81-
shell: bash
82-
run: bash <(curl -s https://codecov.io/bash)
8338
{%- endraw %}
39+
40+
{%- else %}
41+
- name: Install test deps
42+
run: |
43+
python -m pip install --upgrade pip
44+
python -m pip install -e ".[tests]"
45+
46+
- name: Run test suite
47+
run: |
48+
pytest --cov={{ package_name }} --cov-report=term-missing --cov-report=xml
8449
{%- endif %}
85-
{%- endif %}
50+
# If you use this step and have a private repo- then you will need to get a
51+
# token from codecov and
52+
# save it as a github secret called CODECOV_TOKEN
53+
{%- raw %}
54+
- name: Upload to codecov
55+
if: runner.os == 'macOS' && matrix.python-version == '3.13'
56+
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
57+
with:
58+
#token: ${{ secrets.CODECOV_TOKEN }}
59+
verbose: true
60+
files: ./coverage.xml
61+
{% endraw %}

0 commit comments

Comments
 (0)