name: Publish Beta to PyPI
on:
# Trigger on push to beta branch with version tags
push:
branches:
- beta
tags:
- 'v*-beta.*'
- 'v*b*' # PEP 440 beta tags like v0.9.0b1
# Also trigger on pre-releases published from GitHub UI
release:
types: [prereleased]
# Manual trigger for testing
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run (skip PyPI publish)'
required: false
default: 'false'
type: boolean
jobs:
validate:
runs-on: ubuntu-latest
outputs:
is_beta: ${{ steps.check.outputs.is_beta }}
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Extract and validate version
id: check
run: |
# Get version from pyproject.toml
VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Check if it's a beta version (PEP 440: contains 'b', 'beta', 'dev', 'a', 'alpha', 'rc')
if [[ "$VERSION" =~ (a|alpha|b|beta|dev|rc)[0-9]* ]]; then
echo "is_beta=true" >> $GITHUB_OUTPUT
echo "✅ Beta version detected: $VERSION"
else
echo "is_beta=false" >> $GITHUB_OUTPUT
echo "⚠️ Not a beta version: $VERSION"
fi
publish:
needs: validate
if: needs.validate.outputs.is_beta == 'true'
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
contents: write # For creating GitHub releases
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install build dependencies
run: pip install hatch
- name: Build package
run: hatch build
- name: Verify build artifacts
run: |
echo "📦 Built packages:"
ls -la dist/
# Verify version in wheel name matches expected
VERSION="${{ needs.validate.outputs.version }}"
if ls dist/*.whl | grep -q "$VERSION"; then
echo "✅ Version $VERSION found in wheel"
else
echo "❌ Version mismatch in wheel"
exit 1
fi
- name: Publish to PyPI
if: ${{ github.event.inputs.dry_run != 'true' }}
uses: pypa/gh-action-pypi-publish@release/v1
- name: Create GitHub Release (if tag push)
if: startsWith(github.ref, 'refs/tags/') && github.event.inputs.dry_run != 'true'
uses: softprops/action-gh-release@v1
with:
prerelease: true
generate_release_notes: true
files: dist/*
body: |
## Beta Release ${{ needs.validate.outputs.version }}
⚠️ **This is a pre-release version.** It may contain bugs or incomplete features.
### Installation
```bash
pip install foundry-mcp==${{ needs.validate.outputs.version }}
```
Or to always get the latest beta:
```bash
pip install --pre foundry-mcp
```
notify-skip:
needs: validate
if: needs.validate.outputs.is_beta != 'true'
runs-on: ubuntu-latest
steps:
- name: Skip notification
run: |
echo "⏭️ Skipping publish - version ${{ needs.validate.outputs.version }} is not a beta version"
echo "Beta versions must contain: a, alpha, b, beta, dev, or rc"
echo "Example: 0.9.0b1, 0.9.0.beta1, 0.9.0a1, 0.9.0rc1"