Skip to content

Commit

Permalink
Merge pull request #88 from ImperialCollegeLondon/ci
Browse files Browse the repository at this point in the history
Use more rational workflows for testing and publishing
  • Loading branch information
dalonsoa authored Oct 1, 2024
2 parents e127d92 + 1c3ecd2 commit b81f299
Show file tree
Hide file tree
Showing 7 changed files with 866 additions and 673 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Check links in Markdown files

on:
push:
branches:
- main
pull_request:
schedule:
- cron: "0 0 * * 1" # midnight every Monday

Expand Down
78 changes: 6 additions & 72 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,75 +1,9 @@
name: Test and build

on: [push, pull_request, release]
on:
push:
branches:
- main
pull_request:

jobs:
qa:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pre-commit/[email protected]

check-links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: gaurav-nelson/github-action-markdown-link-check@v1
name: Check links in markdown files
with:
use-quiet-mode: 'yes'
use-verbose-mode: 'yes'

test:
needs: qa
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ windows-latest, ubuntu-latest, macos-latest ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: abatilo/[email protected]
with:
poetry-version: 1.5.1

- name: Install dependencies
run: poetry install --with dev

- name: Run tests
run: poetry run pytest

- name: Upload coverage to Codecov
if: success() && (matrix.os == 'ubuntu-latest' && matrix.python-version == 3.9)
uses: codecov/codecov-action@v3


deploy-docs:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install Poetry
uses: abatilo/[email protected]
with:
poetry-version: 1.5.1

- name: Install dependencies
run: poetry install --with docs

- name: Deploy Docs
run: poetry run mkdocs gh-deploy --force
uses: ./.github/workflows/ci_template.yml
43 changes: 43 additions & 0 deletions .github/workflows/ci_template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Test

on:
workflow_call:
inputs:
os:
description: 'Operating system'
default: '["ubuntu-latest", "windows-latest"]'
type: string
python-version:
description: 'Python version'
default: '["3.12"]'
type: string

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ${{fromJson(inputs.os)}}
python-version: ${{fromJson(inputs.python-version)}}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: abatilo/[email protected]
with:
poetry-version: 1.8.3

- name: Install dependencies
run: poetry install --with dev

- name: Run tests
run: poetry run pytest

- name: Upload coverage to Codecov
if: success() && (matrix.os == 'ubuntu-latest' && matrix.python-version == 3.9)
uses: codecov/codecov-action@v3

94 changes: 94 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
on:
release:
types: [published]

permissions:
contents: write
attestations: write
id-token: write

jobs:
test:
uses: ./.github/workflows/ci_template.yml
with:
os: '["ubuntu-latest", "windows-latest", "macos-latest"]'
python-version: '["3.9", "3.10", "3.11", "3.12"]'

build-wheel:
needs: test
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: hynek/build-and-inspect-python-package@v2
with:
attest-build-provenance-github: true
skip-wheel: true

publish-docs:
needs: build-wheel
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install Poetry
uses: abatilo/[email protected]
with:
poetry-version: 1.8.3

- name: Install dependencies
run: poetry install --with docs

- name: Deploy Docs
run: poetry run mkdocs gh-deploy --force

publish-TestPyPI:
needs: publish-docs
name: Publish to TestPyPI
runs-on: ubuntu-latest

steps:
- name: Download packages built by build-and-inspect-python-package
uses: actions/download-artifact@v4
with:
name: Packages
path: dist

- name: Generate artifact attestation for sdist and wheel
uses: actions/attest-build-provenance@v1
with:
subject-path: dist

- name: Publish package distributions to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true

publish-PyPI:
needs: publish-TestPyPI
name: Publish to PyPI
runs-on: ubuntu-latest

steps:
- name: Download packages built by build-and-inspect-python-package
uses: actions/download-artifact@v4
with:
name: Packages
path: dist

- name: Generate artifact attestation for sdist and wheel
uses: actions/attest-build-provenance@v1
with:
subject-path: dist

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ repos:
rev: "23.1.0"
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
# - repo: https://github.com/PyCQA/flake8
# rev: 6.0.0
# hooks:
# - id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v0.991"
hooks:
Expand Down
Loading

0 comments on commit b81f299

Please sign in to comment.