Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous Integration Optimization #97

Merged
merged 10 commits into from
Oct 13, 2024
4 changes: 2 additions & 2 deletions .github/workflows/linkcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install hatch
python-version: "3.x"
- run: pipx install hatch
- run: hatch run docs:linkcheck
34 changes: 34 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---

name: Publish delb
on:
push:
tags: ["*"]


jobs:
build-and-test:
uses: ./.github/workflows/quality-checks.yml
with:
ref: ${{ env.GITHUB_REF_NAME }}

upload:
name: Publish to the cheeseshop
if: startsWith(github.ref, 'refs/tags/')
needs: ["build-and-test"]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/delb
permissions:
id-token: write
JKatzwinkel marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: Download package
uses: actions/download-artifact@v4
with:
name: Packages
path: dist
- name: Upload package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

...
54 changes: 44 additions & 10 deletions .github/workflows/quality-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,59 @@ on:

jobs:

build:
runs-on: ubuntu-latest
outputs:
python-versions: ${{ steps.baipp.outputs.supported_python_classifiers_json_array }}

steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- uses: hynek/build-and-inspect-python-package@v2
id: baipp

unit-tests:
needs: ["build"]
runs-on: ubuntu-latest
steps:
- uses: extractions/setup-just@v2
- run: pipx install hatch
- uses: actions/download-artifact@v4
with:
name: Packages
path: dist
- run: tar xf dist/*.tar.gz --strip-components=1
- uses: actions/setup-python@v5
with:
cache: pip
python-version: 3.x
- run: just pytest

compatibility-tests:
needs: ["build", "unit-tests"]
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- 3.8 # 2024-10
- 3.9 # 2025-10
- "3.10" # 2026-10
- "3.11" # 2027-10
- "3.12" # 2028-10
python-version: ${{ fromJson(needs.build.outputs.python-versions) }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- uses: actions/setup-python@v5
with:
cache: pip
python-version: ${{ matrix.python-version }}
- uses: extractions/setup-just@v2
- run: pip install hatch
- run: just pytest
- run: pipx install hatch
- uses: actions/download-artifact@v4
with:
name: Packages
path: dist
- run: |
rm -r _delb delb
test "$(find dist -name 'delb-*.whl' | wc -l)" -eq 1
just test-wheel "$(find dist -name 'delb-*.whl')"

other-quality-checks:
runs-on: ubuntu-latest
Expand All @@ -57,9 +90,10 @@ jobs:
ref: ${{ inputs.ref || github.ref }}
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
python-version: "3.x"
- uses: extractions/setup-just@v2
- run: pip install hatch
- run: pipx install hatch
- run: just ${{ matrix.target }}

...
16 changes: 10 additions & 6 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ default: tests

version := `hatch version`

_assert_no_dev_version:
#!/usr/bin/env python3
if "dev" in "{{version}}":
raise SystemExit(1)

# run benchmarks
benchmarks:
Expand Down Expand Up @@ -38,18 +42,14 @@ mypy:
pytest:
hatch run unit-tests:check

# release the current version on github & the PyPI
release: tests
test "{{trim_end_match(version, '-dev')}}" = "{{version}}" || false
# release the current version on github & (transitively) the PyPI
release: _assert_no_dev_version tests
{{just_executable()}} -f {{justfile()}} update-citation-file
git add CITATION.cff
git commit -m "Updates CITATION.cff"
git tag {{version}}
git push origin main
git push origin {{version}}
hatch clean
hatch build
hatch publish

# watch, build and serve HTML documentation at 0.0.0.0:8000
serve-docs:
Expand All @@ -62,6 +62,10 @@ show-docs: docs
# run all tests on normalized code
tests: black code-lint mypy pytest doctest

# run the testsuite against a wheel (installed from $WHEEL_PATH); intended to run on a CI platform
test-wheel $WHEEL_PATH:
hatch run test-wheel:check

# Generates and validates CITATION.cff
update-citation-file:
hatch run citation-file:cff-from-621
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,12 @@ coverage-report = """
--cov=_delb --cov=delb \
tests
"""

[tool.hatch.envs.test-wheel]
template = "unit-tests"
skip-install = true
extra-dependencies = [
"delb @ {root:uri}/{env:WHEEL_PATH}",
]
[tool.hatch.envs.test-wheel.scripts]
check = "python -m pytest tests"