Skip to content

Commit de3cb5c

Browse files
committed
feat: add CI workflows for testing and publishing Python packages to PyPI
1 parent 7c5fb12 commit de3cb5c

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

.github/workflows/ci-test.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow will upload a Python Package to PyPI when a release is created
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: CI Test
10+
11+
on:
12+
push:
13+
branches: [ "main" ]
14+
pull_request:
15+
branches: [ "main" ]
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- name: Install poetry
28+
run: pipx install poetry
29+
30+
- uses: actions/setup-python@v5
31+
with:
32+
python-version: "3.11"
33+
cache: "poetry"
34+
35+
- name: Install dependencies
36+
run: poetry install --no-interaction --no-root
37+
38+
- name: Run tests
39+
run: poetry run pytest

.github/workflows/publish.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# This workflow will upload a Python Package to PyPI when a release is created
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
11+
on:
12+
release:
13+
types: [published]
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
release-build:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Install poetry
26+
run: pipx install poetry
27+
28+
- uses: actions/setup-python@v5
29+
with:
30+
python-version: "3.11"
31+
cache: "poetry"
32+
33+
- name: Install dependencies
34+
run: poetry install --no-interaction --no-root
35+
36+
- name: Run tests
37+
run: poetry run pytest
38+
39+
- name: Build release distributions
40+
run: poetry build
41+
42+
- name: Upload distributions
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: release-dists
46+
path: dist/
47+
48+
pypi-publish:
49+
runs-on: ubuntu-latest
50+
needs:
51+
- release-build
52+
permissions:
53+
# IMPORTANT: this permission is mandatory for trusted publishing
54+
id-token: write
55+
56+
# Dedicated environments with protections for publishing are strongly recommended.
57+
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
58+
environment:
59+
name: pypi
60+
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
61+
# url: https://pypi.org/p/YOURPROJECT
62+
#
63+
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
64+
# ALTERNATIVE: exactly, uncomment the following line instead:
65+
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
66+
67+
steps:
68+
- name: Retrieve release distributions
69+
uses: actions/download-artifact@v4
70+
with:
71+
name: release-dists
72+
path: dist/
73+
74+
- name: Publish release distributions to PyPI
75+
uses: pypa/gh-action-pypi-publish@release/v1
76+
with:
77+
packages-dir: dist/

0 commit comments

Comments
 (0)