name: Publish Development Release
on:
workflow_run:
workflows: ["Test Suite"]
types: [completed]
branches: [main, develop]
workflow_dispatch:
inputs:
force_publish:
description: 'Force publish even if tests are not run'
required: false
default: 'false'
jobs:
publish-testpypi:
name: Publish to TestPyPI
runs-on: ubuntu-latest
if: |
github.repository == 'teknologika/deckbuilder' &&
(github.event.workflow_run.conclusion == 'success' ||
github.event_name == 'workflow_dispatch')
steps:
- uses: actions/checkout@v4
with:
# Get the commit that triggered the workflow_run
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Cache pip dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-publish-${{ hashFiles('**/requirements.txt', '**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-publish-
${{ runner.os }}-pip-
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Generate development version
run: |
# Extract current version from pyproject.toml and increment for dev version
CURRENT_VERSION=$(grep "version = " pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "π Current version: ${CURRENT_VERSION}"
# Generate dev version using current version (e.g., 1.3.0 -> 1.3.0.dev123)
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
# Ensure PATCH is a valid number, default to 0 if empty
if [[ -z "$PATCH" || ! "$PATCH" =~ ^[0-9]+$ ]]; then
PATCH=0
fi
DEV_NUMBER=$GITHUB_RUN_NUMBER
DEV_VERSION="${MAJOR}.${MINOR}.${PATCH}.dev${DEV_NUMBER}"
echo "DEV_VERSION=${DEV_VERSION}" >> $GITHUB_ENV
echo "π¦ Development version: ${DEV_VERSION}"
# Validate the generated version format
if [[ ! "$DEV_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.dev[0-9]+$ ]]; then
echo "β ERROR: Generated version '$DEV_VERSION' is not PEP 440 compliant"
exit 1
fi
echo "β
Version format is PEP 440 compliant"
# Update pyproject.toml version dynamically
sed -i "s/version = \".*\"/version = \"${DEV_VERSION}\"/" pyproject.toml
echo "β
Updated pyproject.toml with development version"
- name: Verify version update
run: |
echo "π Verifying version in pyproject.toml:"
grep "version = " pyproject.toml
- name: Build package
run: |
echo "π¨ Building package..."
python -m build
echo "π Package contents:"
ls -la dist/
- name: Verify package integrity
run: |
echo "π Checking package integrity..."
twine check dist/*
- name: Publish to TestPyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: |
echo "π Publishing to TestPyPI..."
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
echo "β
Successfully published ${DEV_VERSION} to TestPyPI"
- name: Generate installation instructions
run: |
echo "π TestPyPI Installation Instructions:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "To test this development release:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "pip install -i https://test.pypi.org/simple/ deckbuilder==${DEV_VERSION}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Or install latest development version:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ deckbuilder" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "π [View on TestPyPI](https://test.pypi.org/project/deckbuilder/)" >> $GITHUB_STEP_SUMMARY
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: testpypi-dist-${{ env.DEV_VERSION }}
path: dist/
retention-days: 30
- name: Notify development release
run: |
echo "π Development release published successfully!"
echo "π¦ Version: ${DEV_VERSION}"
echo "π TestPyPI: https://test.pypi.org/project/deckbuilder/${DEV_VERSION}/"
echo "π₯ Install: pip install -i https://test.pypi.org/simple/ deckbuilder==${DEV_VERSION}"