Skip to content

PyPI Publish

PyPI Publish #64

Workflow file for this run

name: PyPI Publish
on:
workflow_dispatch:
jobs:
python-ci:
if: github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/tags')
uses: ./.github/workflows/python_ci.yaml
secrets: inherit
build-offline-archives:
if: github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/tags')
needs: python-ci
uses: ./.github/workflows/python_build.yaml
secrets: inherit
publish-to-pypi:
name: Upload release to PyPI
needs: [python-ci, build-offline-archives]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/sift_py
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: sift-stack-py-dist
path: python/dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: python/dist/
create-github-release:
name: Create GitHub Release
needs: [build-offline-archives]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: sift-stack-py-dist
path: python/dist/
- name: Download all platform archives
uses: actions/download-artifact@v4
with:
pattern: sift-py-dist-*-py3-*
path: platform_archives
merge-multiple: false
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ github.ref_name }}
run: |
# Create release notes
cat > release_notes.md << 'EOL'
See [CHANGELOG.md](https://github.com/sift-stack/sift/blob/main/python/CHANGELOG.md) for details.
Offline archives are available for download for multiple platforms. Offline archives include wheels for all dependencies including build extras, e.g. openssl, development, and build.
Use `pip install sift-stack-py --find-links={path/to/archive} --no-index` to install.
EOL
# Create the release
gh release create "$TAG_NAME" \
--title "sift-stack-py $TAG_NAME" \
--notes-file release_notes.md
# Upload Python package distributions
for dist in python/dist/*; do
echo "Uploading distribution: $dist"
gh release upload "$TAG_NAME" "$dist" --clobber
done
# Upload platform archives (both .zip and .tar.gz)
for archive in platform_archives/*/sift-py-dist-*-py3-*.{zip,tar.gz}; do
echo "Uploading archive: $archive"
gh release upload "$TAG_NAME" "$archive" --clobber
done
deploy-docs:
name: Deploy Documentation
needs: publish-to-pypi
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
cd python
pip install -e .[docs,development]
- name: Extract version and check if stable
id: version
run: |
# Extract version from tag (everything after 'python/')
FULL_VERSION=${GITHUB_REF#refs/tags/python/}
echo "Full version from tag: $FULL_VERSION"
# Extract major.minor from version (drop patch)
if [[ "$FULL_VERSION" =~ ^v?([0-9]+)\.([0-9]+)\.[0-9]+(.*)?$ ]]; then
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
SUFFIX=${BASH_REMATCH[3]}
VERSION="v${MAJOR}.${MINOR}"
# Check if this is a stable release (no suffix like -alpha, -beta, -rc)
if [[ -z "$SUFFIX" ]]; then
# Stable release - use 'latest' alias and make visible
ALIAS="latest"
HIDDEN="false"
echo "Stable release detected: $FULL_VERSION -> $VERSION"
else
# Pre-release (alpha, beta, rc) - no 'latest' alias and hide from dropdown
VERSION="${VERSION}${SUFFIX}"
ALIAS=""
HIDDEN="true"
echo "Pre-release detected: $FULL_VERSION -> $VERSION"
fi
else
echo "Error: Could not parse version format: $FULL_VERSION"
exit 1
fi
echo "full_version=$FULL_VERSION" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "alias=$ALIAS" >> $GITHUB_OUTPUT
echo "hidden=$HIDDEN" >> $GITHUB_OUTPUT
echo "Final - Version: $VERSION, Alias: $ALIAS, Hidden: $HIDDEN"
- name: Fetch gh-pages branch
run: git fetch origin gh-pages --depth=1
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Deploy docs with mike
run: |
cd python
FULL_VERSION="${{ steps.version.outputs.full_version }}"
VERSION="${{ steps.version.outputs.version }}"
ALIAS="${{ steps.version.outputs.alias }}"
HIDDEN="${{ steps.version.outputs.hidden }}"
# Always deploy the full version first, but hide it
echo "Deploying full version $FULL_VERSION (hidden)"
mike deploy "$FULL_VERSION" --push --prop-set hidden=true
if [[ "$HIDDEN" == "false" ]]; then
# Stable release: deploy abbreviated version with latest alias, visible in dropdown
echo "Deploying stable release $VERSION with $ALIAS alias"
mike deploy "$VERSION" "$ALIAS" --push --update-aliases
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}