Skip to content

v0.0.216

v0.0.216 #14

Workflow file for this run

name: Publish to PyPI
on:
release:
types: [published]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
name: Build distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch tags
run: git fetch --tags --force
- name: Validate version policy
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
if [ -n "${RELEASE_TAG:-}" ]; then
python3 scripts/check_version_policy.py --enforce-thousandth-bump --release-tag "${RELEASE_TAG}"
else
python3 scripts/check_version_policy.py
fi
- uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Build sdist and wheel
run: uv build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
if-no-files-found: error
publish:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # Required for trusted publishing (PyPI OIDC)
steps:
- uses: astral-sh/setup-uv@v5
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Check if version already exists on PyPI
id: pypi_check
run: |
VERSION="$(ls dist/silicon_refinery-*.tar.gz | head -n1 | sed -E 's#dist/silicon_refinery-(.+)\.tar\.gz#\1#')"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
if curl -fsSL "https://pypi.org/pypi/silicon-refinery/${VERSION}/json" >/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "Version ${VERSION} already exists on PyPI; skipping upload."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
echo "Version ${VERSION} is not on PyPI; publishing."
fi
- name: Publish to PyPI
if: steps.pypi_check.outputs.exists != 'true'
env:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: |
if [ -n "${PYPI_API_TOKEN}" ]; then
uv publish --token "${PYPI_API_TOKEN}" --check-url "https://pypi.org/simple/" dist/*
else
uv publish --trusted-publishing always --check-url "https://pypi.org/simple/" dist/*
fi
tag:
name: Create version tag
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Extract version from pyproject.toml
id: version
run: |
VERSION=$(grep -m1 '^version' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Detected version: $VERSION"
- name: Create and push version tag
run: |
TAG="v${{ steps.version.outputs.version }}"
git fetch --tags --force
if git ls-remote --tags origin "${TAG}" | grep -q "refs/tags/${TAG}$"; then
echo "Tag $TAG already exists, skipping."
else
git tag "$TAG"
git push origin "$TAG"
echo "Created and pushed tag $TAG"
fi