| 1 |
# This workflow will upload a Python Package using Twine 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 |
push: |
| 15 |
pull_request: |
| 16 |
|
| 17 |
permissions: |
| 18 |
contents: read |
| 19 |
|
| 20 |
jobs: |
| 21 |
lint: |
| 22 |
runs-on: ubuntu-latest |
| 23 |
steps: |
| 24 |
- uses: actions/checkout@v3 |
| 25 |
- uses: psf/black@stable |
| 26 |
test: |
| 27 |
needs: |
| 28 |
- lint |
| 29 |
runs-on: ubuntu-latest |
| 30 |
strategy: |
| 31 |
matrix: |
| 32 |
python-version: ["3.11", "3.12", "3.13"] |
| 33 |
|
| 34 |
steps: |
| 35 |
- uses: actions/checkout@v3 |
| 36 |
- name: Set up Python ${{ matrix.python-version }} |
| 37 |
uses: actions/setup-python@v4 |
| 38 |
with: |
| 39 |
python-version: ${{ matrix.python-version }} |
| 40 |
- name: Display Python version |
| 41 |
run: python -c "import sys; print(sys.version)" |
| 42 |
- uses: snok/install-poetry@v1 |
| 43 |
- name: Install dependencies |
| 44 |
run: | |
| 45 |
poetry install --no-interaction --no-root |
| 46 |
- name: Test with pytest |
| 47 |
run: | |
| 48 |
poetry run pytest |
| 49 |
publish: |
| 50 |
needs: |
| 51 |
- test |
| 52 |
runs-on: ubuntu-latest |
| 53 |
permissions: |
| 54 |
id-token: write |
| 55 |
if: ${{ github.event_name == 'release' }} |
| 56 |
steps: |
| 57 |
- uses: actions/checkout@v3 |
| 58 |
with: |
| 59 |
fetch-depth: 0 |
| 60 |
- name: Set up Python |
| 61 |
uses: actions/setup-python@v3 |
| 62 |
with: |
| 63 |
python-version: "3.13" |
| 64 |
- uses: snok/install-poetry@v1 |
| 65 |
- name: Install dependencies |
| 66 |
run: | |
| 67 |
poetry install --no-interaction --no-root |
| 68 |
- name: Build package |
| 69 |
run: poetry build |
| 70 |
- name: Publish package |
| 71 |
uses: pypa/[email protected] |
| 72 |
publish-test: |
| 73 |
needs: |
| 74 |
- test |
| 75 |
runs-on: ubuntu-latest |
| 76 |
permissions: |
| 77 |
id-token: write |
| 78 |
if: ${{ github.event_name == 'push' && github.ref_name == 'test-publish' }} |
| 79 |
steps: |
| 80 |
- uses: actions/checkout@v3 |
| 81 |
with: |
| 82 |
fetch-depth: 0 |
| 83 |
- name: Set up Python |
| 84 |
uses: actions/setup-python@v3 |
| 85 |
with: |
| 86 |
python-version: "3.13" |
| 87 |
- uses: snok/install-poetry@v1 |
| 88 |
- name: Install dependencies |
| 89 |
run: | |
| 90 |
poetry install --no-interaction --no-root |
| 91 |
- name: Build package |
| 92 |
run: poetry build |
| 93 |
- name: Publish package |
| 94 |
uses: pypa/[email protected] |
| 95 |
with: |
| 96 |
repository-url: https://test.pypi.org/legacy/ |