Files
computer/.github/workflows/pypi.yml
T
2026-06-07 09:01:31 +01:00

97 lines
2.5 KiB
YAML

name: Publish to PyPI
on:
push:
branches: [release]
concurrency:
group: pypi-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Read version
id: pkg
run: |
VERSION=$(python3 -c "
import re, pathlib
text = pathlib.Path('pyproject.toml').read_text()
m = re.search(r'^version\s*=\s*\"([^\"]+)\"', text, re.M)
print(m.group(1))
")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check if version already on PyPI
id: check
run: |
VERSION="${{ steps.pkg.outputs.version }}"
if pip index versions cptr 2>/dev/null | grep -q "$VERSION"; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "Version $VERSION already on PyPI — skipping"
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Set up Node.js
if: steps.check.outputs.skip != 'true'
uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: cptr/frontend/package-lock.json
- name: Build frontend
if: steps.check.outputs.skip != 'true'
working-directory: cptr/frontend
run: |
npm ci
npm run build
- name: Set up Python
if: steps.check.outputs.skip != 'true'
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build tools
if: steps.check.outputs.skip != 'true'
run: pip install hatchling build
- name: Build package
if: steps.check.outputs.skip != 'true'
run: python -m build --wheel
- name: Upload dist artifacts
if: steps.check.outputs.skip != 'true'
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
publish:
needs: build
if: needs.build.outputs.skip != 'true'
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
steps:
- name: Download dist artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# No API token needed - uses OIDC trusted publishing.
# Configure at: https://pypi.org/manage/project/cptr/settings/publishing/