Skip to content

Commit 3249337

Browse files
committed
Add github workflows for code checks, build, publish and release.
The workflows are based on the reusable workflows from the glenn20/python-ci repository. The pytest tests are ommitted as they require hardware-in-the-loop. Run the CI tests on your local computer with a serial-attached ESP32 device using tox, eg: `tox -- --port=u0 -xv`, or `uv run -p 3.12 pytest --port c3 -xv`.
1 parent 2a1a62a commit 3249337

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-0
lines changed

.github/workflows/ci-release.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publish and Release
2+
3+
# A github reusable workflow to:
4+
# - Run code checks and tests on multiple python versions and platforms;
5+
# - Publish a python package to test.pypi.org and pypi.org; and
6+
# - Create a GitHub Release.
7+
#
8+
# The workflow is triggered on:
9+
# - push to version tags matching "v*", eg. "v1.0.0", or
10+
# - manual workflow_dispatch (eg. from the github `Actions` tab):
11+
# - will produce a release with a version tag like: "v1.0.1.devN"
12+
#
13+
# Uses reusable workflows from the <https://github.com/glenn20/python-ci>
14+
# repository.
15+
16+
on:
17+
push:
18+
tags: ["v*"] # Publish on tags matching "v*", eg. "v1.0.0"
19+
workflow_dispatch:
20+
21+
jobs:
22+
checks:
23+
name: Code checks
24+
uses: glenn20/python-ci/.github/workflows/check.yaml@v1
25+
26+
build:
27+
name: Build
28+
uses: glenn20/python-ci/.github/workflows/build.yaml@v1
29+
30+
publish-test:
31+
name: Publish to test.pypi
32+
uses: ./.github/workflows/publish.yaml
33+
needs: build
34+
with:
35+
pypi: test.pypi
36+
permissions:
37+
id-token: write # IMPORTANT: mandatory for trusted publishing!
38+
39+
publish-pypi:
40+
name: Publish to pypi
41+
uses: ./.github/workflows/publish.yaml
42+
needs: build
43+
with:
44+
pypi: upload.pypi
45+
permissions:
46+
id-token: write # IMPORTANT: mandatory for trusted publishing!
47+
48+
github-release:
49+
name: Create GitHub release
50+
uses: glenn20/python-ci/.github/workflows/release.yaml@v1
51+
needs: build
52+
permissions:
53+
contents: write # IMPORTANT: mandatory for github release
54+
id-token: write # IMPORTANT: mandatory for github release

.github/workflows/ci-tests.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Test and Build
2+
3+
# Run the code checks and CI pytest workflow on
4+
# - push to `main` or `dev` branches, or
5+
# - manually triggered from github Actions tab.
6+
7+
# Build and publish to test.pypi on
8+
# - push to `main` branch.
9+
10+
on:
11+
push:
12+
branches: [main, dev]
13+
workflow_dispatch:
14+
15+
jobs:
16+
# Can't run pytest tests as they require hardware-in-the-loop
17+
# So, just run check and build tests
18+
19+
checks:
20+
name: Code checks
21+
uses: glenn20/python-ci/.github/workflows/check.yaml@v1
22+
23+
build:
24+
name: Build
25+
uses: glenn20/python-ci/.github/workflows/build.yaml@v1
26+
27+
publish-test:
28+
name: Publish to test.pypi
29+
needs: build
30+
if: |
31+
github.event_name == 'workflow_dispatch' ||
32+
(github.event_name == 'push' && github.ref == 'refs/heads/main')
33+
uses: ./.github/workflows/publish.yaml
34+
with:
35+
pypi: test.pypi
36+
permissions:
37+
id-token: write # IMPORTANT: mandatory for trusted publishing!

.github/workflows/publish.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Publish python package
2+
3+
# description: |- A github reusable workflow to publish a python package to
4+
# pypi.org or test.pypi.org.
5+
#
6+
# Input options:
7+
# - `pypi: test.pypi`: Publish to test.pypi.org (default).
8+
# - `pypi: upload.pypi`: Publish to pypi.org.
9+
#
10+
# The workflow invokes the github composite action
11+
# `glenn20/python-ci/publish@v1` to publish the package.
12+
#
13+
# Requirements:
14+
# 1. For trusted publishing, the publishing workflow must be in the project
15+
# repository, so copy this workflow file to
16+
# `.github/workflows/publish.yaml` in your repository.
17+
# 2. Create the `publish-test.pypi` and `publish-pypi` Environments in your
18+
# github repository (Settings->Environments->New Environment).
19+
# 3. Add this workflow as a "trusted publisher" on your pypi and test.pypi
20+
# project pages (add the name of the relevant Environment for additional
21+
# access control).
22+
# 4. Call this workflow from a parent workflow with the `pypi` input set to
23+
# "upload.pypi" or "test.pypi" (default).
24+
#
25+
# Invoke with `uses: ./.github/workflows/publish@v1`
26+
27+
on:
28+
workflow_call:
29+
inputs:
30+
pypi:
31+
description: 'Publish to `upload.pypi` or `test.pypi`:'
32+
default: 'test.pypi'
33+
required: false
34+
type: string
35+
workflow_dispatch:
36+
inputs:
37+
pypi:
38+
description: 'Set to "upload.pypi" or "test.pypi" (default).'
39+
options: ['test.pypi', 'upload.pypi']
40+
type: choice
41+
42+
jobs:
43+
publish:
44+
name: Publish to ${{ inputs.pypi }}
45+
runs-on: ubuntu-latest
46+
environment:
47+
name: publish-${{ inputs.pypi }}
48+
url: https://${{ inputs.pypi }}.org/p/${{ steps.publish.outputs.package-name }}
49+
permissions:
50+
id-token: write # IMPORTANT: mandatory for trusted publishing
51+
steps:
52+
- uses: glenn20/python-ci/publish@v1
53+
id: publish
54+
with:
55+
pypi: ${{ inputs.pypi }}

0 commit comments

Comments
 (0)