Skip to content

Refactor github CI workflows #5

Refactor github CI workflows

Refactor github CI workflows #5

Workflow file for this run

name: CI Workflow
# A reusable github workflow to run python CI workflows, including static code
# checks, automated testing (using pytest and tox), package building,
# publishing to test.pypi.org and pypi.org, and creating a GitHub release.
#
# The workflow elements to selected are specified in the `jobs` input. The
# default is to run the `test` and `build` jobs. The CI workflow is
# configured in the tox-gh config (eg. pyproject.toml). See
# https://github.com/tox-dev/tox-gh.
#
# Accepts the following inputs as json strings:
# - `jobs`: the list of jobs to run,
# - `os`: the list of operating systems on which to run tests, and
# - `python-version`: the list of python versions on which to run tests.
#
# Assumes the configurations for all tools (`mypy`, `uv`, `ruff`, `pytest`,
# ...) are fully specified in config files (eg `pyproject.toml`).
#
# These workflows use `tox`, as it can be more easily customised in your
# pyproject.toml so that the same CI process runs on your local computer and
# on github.
#
# All workflows use astral `uv` to execute actions wherever possible.
on:
workflow_call:
inputs:
jobs:
description: >-
A json string containing the list of jobs to run. Available jobs are:
- `check`: Run static code checks (using `mypy`, `ruff`, etc.).
- `test`: Run tests and code checks using `tox`.
- `build`: Build the python package.
- `publish-test`: Publish the package to test.pypi.org.
- `publish`: Publish the package to pypi.org (runs `publish-test`).
- `release`: Create a GitHub release.
The default is `["test", "build"]`.
default: '["test", "build"]'
type: string
required: false
os:
description: >-
A json string containing the list of operating systems on which to
run the test matrix.
default: '["ubuntu-latest", "windows-latest", "macos-latest"]'
type: string
required: false
python-version:
description: >-
A json string containing the list of python versions on
which to run the test matrix.
default: '["3.9", "3.10", "3.11", "3.12", "3.13"]'
type: string
required: false
jobs:
init:
runs-on: ubuntu-latest
steps:
- name: Select the workflow configuration
run: | # Find the matching environment variable based on the event trigger
echo '${{ github.repository }}'
test:
if: ${{ contains(fromJson(inputs.jobs), 'test') }}
name: Tests
uses: glenn20/python-ci/.github/workflows/test-tox.yaml@dev
with:
os: ${{ inputs.os }}
python-version: ${{ inputs.python-version }}
permissions:
id-token: none
contents: none
build:
if: ${{ contains(fromJson(inputs.jobs), 'build') }}
name: Build python package
uses: glenn20/python-ci/.github/workflows/build.yaml@dev
permissions:
id-token: none
contents: none
# The publish workflows must be located in your project repository, not in the
# python-ci repository, so that trusted publishing to pypi.org can be used.
# Copy the `publish.yaml` workflow from
# `https://github.com/glenn20/python-ci/tree/main/examples/publish.yaml` to
# your project's `.github/workflows` directory.
publish:
if: ${{ contains(fromJson(inputs.jobs), 'publish-test') || contains(fromJson(inputs.jobs), 'publish') }}
name: Publish to pypi
uses: ${{ github.repository }}/.github/workflows/publish.yaml@dev

Check failure on line 92 in .github/workflows/ci-workflow.yaml

View workflow run for this annotation

GitHub Actions / .github/workflows/ci-workflow.yaml

Invalid workflow file

invalid value workflow reference: references to workflows must be prefixed with format 'owner/repository/' or './' for local workflows
with:
test-only: ${{ !contains(fromJson(inputs.jobs), 'publish') }}
needs: [test, build]
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing!
contents: none # IMPORTANT: mandatory for github release
release:
if: ${{ contains(fromJson(inputs.jobs), 'release') }}
name: Create GitHub release
uses: glenn20/python-ci/.github/workflows/github-release.yaml@dev
needs: [test, build]
permissions:
id-token: write # IMPORTANT: mandatory for github release
contents: write # IMPORTANT: mandatory for github release