Skip to content

Commit 87f7771

Browse files
committed
WIP
1 parent ab861ab commit 87f7771

File tree

2 files changed

+34
-105
lines changed

2 files changed

+34
-105
lines changed

.github/workflows/ci-workflow.yaml

Lines changed: 0 additions & 68 deletions
This file was deleted.

.github/workflows/ci.yaml

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
name: CI workflow for python projects
22

33
# Run the CI test workflow of jobs which includes:
4-
# - `check`: Run static code checks (using `mypy`, `ruff`, etc.).
5-
# - `test`: Run tests (and code checks) using `tox`.
4+
# - `test`: Run tests (including code checks) using `tox`.
65
# - `build`: Build the python package.
76
# - `publish-test`: Publish the package to test.pypi.org.
87
# - `publish`: Publish the package to pypi.org (runs `publish-test`).
98
# - `release`: Create a GitHub release.
109

11-
on:
12-
push:
13-
branches: ["**"] # Push commits to any branch
14-
tags: ["v[0-9]*"] # Publish on tags matching "v*", eg. "v1.0.0"
15-
1610
# Configure the workflows here. Each environment variable name should be a
1711
# wildcard matching the
1812
# `on-<github.event_name>-<github.ref_type>-<github.ref_name>` format. For
@@ -30,65 +24,68 @@ env:
3024
python-version=["3.9", "3.10", "3.11", "3.12", "3.13"]
3125
os=["ubuntu-latest"]
3226
on-push-branch-*: | # Push commits to other branches
33-
jobs=["test", "build", "publish-test"]
27+
jobs=["test", "build"]
3428
python-version=["3.9", "3.13"]
3529
os=["ubuntu-latest"]
30+
on-workflow_dispatch-*: | # Manual trigger of the workflow
31+
jobs=["test", "build"]
32+
python-version=["3.9", "3.13"]
33+
os=["ubuntu-latest"]
34+
35+
on:
36+
push:
37+
branches: ["**"] # Push commits to any branch
38+
tags: ["v[0-9]*"] # Publish on tags matching "v*", eg. "v1.0.0"
39+
workflow_dispatch: # Allow manual triggering of the workflow
3640

3741
jobs:
38-
config:
39-
# Select the workflow config based on the event trigger.
40-
runs-on: ubuntu-latest
42+
config: # Select the workflow config based on the event trigger.
43+
name: Configure workflow
4144
outputs:
4245
jobs: ${{ steps.config.outputs.jobs }}
43-
python-version: ${{ steps.config.outputs.python-version }}
4446
os: ${{ steps.config.outputs.os }}
47+
python-version: ${{ steps.config.outputs.python-version }}
48+
runs-on: ubuntu-latest
4549
steps:
46-
- name: Select the workflow configuration
47-
id: config
48-
run: | # Find the matching environment variable based on the event trigger
49-
tag="on-${{ github.event_name }}-${{ github.ref_type }}-${{ github.ref_name }}"
50-
for key in $(echo '${{ toJson(env) }}' | jq -r 'keys_unsorted[]'); do
51-
if [[ "$tag" == $key ]]; then
52-
# Write value of the matching environment variable to $GITHUB_OUTPUT
53-
echo '${{ toJson(env) }}' | jq -r ".[\"$key\"]" >> $GITHUB_OUTPUT
54-
exit 0 # Stop after the first match
55-
fi
56-
done
57-
echo "No matching environment variable found for '$tag'."
50+
- id: config
51+
uses: glenn20/python-ci/actions/config@dev
52+
with:
53+
config: ${{ toJson(env) }}
5854

59-
ci-workflow:
55+
ci-workflow: # Run the CI workflow based on the config.
6056
name: CI workflow
6157
needs: config
62-
uses: ./.github/workflows/ci-workflow.yaml
58+
uses: glenn20/python-ci/.github/workflows/ci-workflow-tox.yaml@dev
6359
with:
6460
jobs: ${{ needs.config.outputs.jobs }}
6561
os: ${{ needs.config.outputs.os }}
6662
python-version: ${{ needs.config.outputs.python-version }}
6763

6864
# We can't use trusted publishing from a reusable workflow in another
69-
# repository, so the publish workflows must be run from here, not in the
70-
# ci-workflow.yaml.
65+
# repository, so the publish workflows must be run from here.
7166
publish:
72-
if: ${{ contains(needs.config.outputs.jobs, '"publish') }}
7367
name: Publish to pypi.org
74-
runs-on: ubuntu-latest
7568
needs: [config, ci-workflow]
69+
runs-on: ubuntu-latest
70+
if: ${{ contains(needs.config.outputs.jobs, 'publish') }}
7671
environment:
7772
name: publish-pypi
7873
url: ${{ steps.publish.outputs.url }}
7974
permissions:
8075
id-token: write # Required for trusted publishing
8176
steps:
8277
- id: publish
83-
uses: glenn20/python-ci/publish@dev
78+
uses: glenn20/python-ci/actions/publish@v2
8479
with:
85-
test-only: ${{ contains(needs.config.outputs.jobs, '"publish"') && 'true' || 'false' }}
80+
test-only: ${{ contains(fromJson(needs.config.outputs.jobs), 'publish') && 'false' || 'true' }}
8681

82+
# We run the github release job here instead of in ci-workflow, as it requires
83+
# permissions to sign the release and to simplify the workflow dependency
84+
# graph on the github UI.
8785
release:
88-
if: ${{ contains(fromJson(needs.config.outputs.jobs), 'release') }}
89-
name: Create GitHub release
9086
needs: [config, ci-workflow]
87+
uses: glenn20/python-ci/.github/workflows/github-release.yaml@v2
9188
permissions:
92-
id-token: write # IMPORTANT: mandatory for github release
93-
contents: write # IMPORTANT: mandatory for github release
94-
uses: glenn20/python-ci/.github/workflows/github-release.yaml@dev
89+
id-token: write # Required for signing the release
90+
contents: write # Required for github release
91+
if: ${{ contains(fromJson(needs.config.outputs.jobs), 'release') }}

0 commit comments

Comments
 (0)