Files
computer/.github/workflows/pypi.yml
T
2026-07-06 00:21:38 -05:00

146 lines
4.1 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
outputs:
skip: ${{ steps.check.outputs.skip }}
version: ${{ steps.pkg.outputs.version }}
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: Build Linux wheelhouse
if: steps.check.outputs.skip != 'true'
run: |
VERSION="${{ steps.pkg.outputs.version }}"
WHEEL="dist/cptr-${VERSION}-py3-none-any.whl"
mkdir -p wheelhouse
python -m pip download --dest wheelhouse "${WHEEL}[all]"
tar -czf "cptr-${VERSION}-linux-wheelhouse.tar.gz" -C wheelhouse .
- name: Generate checksums
if: steps.check.outputs.skip != 'true'
run: |
sha256sum dist/*.whl cptr-*-linux-wheelhouse.tar.gz > SHA256SUMS
- name: Upload dist artifacts
if: steps.check.outputs.skip != 'true'
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
- name: Upload release artifacts
if: steps.check.outputs.skip != 'true'
uses: actions/upload-artifact@v4
with:
name: release-assets
path: |
dist/*.whl
cptr-*-linux-wheelhouse.tar.gz
SHA256SUMS
publish:
needs: build
if: needs.build.outputs.skip != 'true'
runs-on: ubuntu-latest
environment: pypi
permissions:
contents: write
id-token: write
steps:
- name: Download dist artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Download release artifacts
uses: actions/download-artifact@v4
with:
name: release-assets
path: release-assets/
- 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/
- name: Upload GitHub release artifacts
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.build.outputs.version }}
run: |
for attempt in {1..12}; do
if gh release view "v${VERSION}" >/dev/null 2>&1; then
gh release upload "v${VERSION}" release-assets/* --clobber
exit 0
fi
sleep 10
done
echo "GitHub release v${VERSION} was not found" >&2
exit 1