| 1 |
name: Continuous delivery - PyPI |
| 2 |
|
| 3 |
on: |
| 4 |
pull_request: |
| 5 |
push: |
| 6 |
branches: [main] |
| 7 |
release: |
| 8 |
types: [published] |
| 9 |
workflow_dispatch: |
| 10 |
|
| 11 |
env: |
| 12 |
POETRY_SPEC: poetry >=2, <2.3 |
| 13 |
|
| 14 |
jobs: |
| 15 |
check-package-version: |
| 16 |
name: Check package version |
| 17 |
runs-on: ubuntu-latest |
| 18 |
container: python:3.10-slim |
| 19 |
steps: |
| 20 |
- name: Checkout repository |
| 21 |
uses: actions/checkout@v6 |
| 22 |
- name: Install Poetry |
| 23 |
run: pip install "${POETRY_SPEC}" |
| 24 |
- name: Check package version format |
| 25 |
shell: bash |
| 26 |
run: | |
| 27 |
PACKAGE_VERSION=$(poetry version --short) |
| 28 |
echo "PACKAGE_VERSION = $PACKAGE_VERSION" |
| 29 |
if [[ $PACKAGE_VERSION =~ ^[0-9]+.[0-9]+.[0-9]+(-rc\.[1-9])?$ ]]; then exit 0; else exit 1; fi |
| 30 |
build: |
| 31 |
name: Build |
| 32 |
runs-on: ubuntu-latest |
| 33 |
container: python:3.10-slim |
| 34 |
needs: check-package-version |
| 35 |
steps: |
| 36 |
- name: Checkout repository |
| 37 |
uses: actions/checkout@v6 |
| 38 |
- name: Install Poetry |
| 39 |
run: pip install "${POETRY_SPEC}" |
| 40 |
- name: Build |
| 41 |
run: poetry build |
| 42 |
- name: Upload artifacts |
| 43 |
uses: actions/upload-artifact@v6 |
| 44 |
with: |
| 45 |
name: nitrokey-pypi |
| 46 |
path: dist |
| 47 |
publish-testpypi: |
| 48 |
name: Publish to TestPyPI |
| 49 |
runs-on: ubuntu-latest |
| 50 |
needs: build |
| 51 |
if: github.event_name == 'release' || github.ref == 'refs/heads/main' |
| 52 |
environment: |
| 53 |
name: testpypi |
| 54 |
url: https://test.pypi.org/p/nitrokey |
| 55 |
permissions: |
| 56 |
id-token: write |
| 57 |
steps: |
| 58 |
- name: Checkout repository |
| 59 |
uses: actions/checkout@v6 |
| 60 |
- name: Download artifacts |
| 61 |
uses: actions/download-artifact@v8 |
| 62 |
with: |
| 63 |
name: nitrokey-pypi |
| 64 |
path: dist |
| 65 |
- name: Publish to TestPyPI |
| 66 |
uses: pypa/gh-action-pypi-publish@release/v1 |
| 67 |
with: |
| 68 |
repository-url: https://test.pypi.org/legacy/ |
| 69 |
skip-existing: true |
| 70 |
check-tag-version: |
| 71 |
name: Check tag version |
| 72 |
runs-on: ubuntu-latest |
| 73 |
container: python:3.10-slim |
| 74 |
if: github.event_name == 'release' |
| 75 |
steps: |
| 76 |
- name: Checkout repository |
| 77 |
uses: actions/checkout@v6 |
| 78 |
- name: Install Poetry |
| 79 |
run: pip install "${POETRY_SPEC}" |
| 80 |
- name: Check tag version |
| 81 |
shell: bash |
| 82 |
run: | |
| 83 |
VERSION_TAG="${{ github.event.release.tag_name }}" |
| 84 |
PACKAGE_VERSION="v"$(poetry version --short) |
| 85 |
echo "VERSION_TAG = $VERSION_TAG" |
| 86 |
echo "PACKAGE_VERSION = $PACKAGE_VERSION" |
| 87 |
if [ $VERSION_TAG == $PACKAGE_VERSION ]; then exit 0; else exit 1; fi |
| 88 |
publish-pypi: |
| 89 |
name: Publish to PyPI |
| 90 |
runs-on: ubuntu-latest |
| 91 |
needs: [build, check-tag-version] |
| 92 |
if: github.event_name == 'release' |
| 93 |
environment: |
| 94 |
name: pypi |
| 95 |
url: https://pypi.org/p/nitrokey |
| 96 |
permissions: |
| 97 |
id-token: write |
| 98 |
steps: |
| 99 |
- name: Checkout repository |
| 100 |
uses: actions/checkout@v6 |
| 101 |
- name: Download artifacts |
| 102 |
uses: actions/download-artifact@v8 |
| 103 |
with: |
| 104 |
name: nitrokey-pypi |
| 105 |
path: dist |
| 106 |
- name: Publish to PyPI |
| 107 |
uses: pypa/gh-action-pypi-publish@release/v1 |