|
1 | 1 | name: PyPI Release
|
2 | 2 |
|
3 | 3 | on:
|
| 4 | + # Manual trigger with version input |
4 | 5 | workflow_dispatch:
|
5 | 6 | inputs:
|
6 | 7 | version:
|
|
10 | 11 | description: "Confirm all tests have passed"
|
11 | 12 | type: boolean
|
12 | 13 | required: true
|
| 14 | + is_prerelease: |
| 15 | + description: "Is this a pre-release?" |
| 16 | + type: boolean |
| 17 | + default: false |
| 18 | + required: false |
| 19 | + # Auto-trigger for beta releases when merged to dev |
| 20 | + push: |
| 21 | + branches: |
| 22 | + - dev |
13 | 23 |
|
14 | 24 | jobs:
|
15 |
| - release: |
| 25 | + # Job for manual releases (stable or pre-release) |
| 26 | + manual_release: |
16 | 27 | runs-on: ubuntu-latest
|
17 |
| - if: github.event.inputs.confirm_tests == 'true' |
| 28 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.confirm_tests == 'true' |
18 | 29 | permissions:
|
19 | 30 | contents: write
|
20 | 31 | steps:
|
21 | 32 | - uses: actions/checkout@v3
|
| 33 | + with: |
| 34 | + fetch-depth: 0 |
22 | 35 | - name: Set up Python
|
23 |
| - uses: actions/setup-python@v4 |
| 36 | + uses: actions/setup-python@v5 |
24 | 37 | with:
|
25 | 38 | python-version: "3.10"
|
26 | 39 | - name: Install dependencies
|
|
37 | 50 | git config user.email github-actions@github.com
|
38 | 51 | git tag v${{ github.event.inputs.version }}
|
39 | 52 | git push origin v${{ github.event.inputs.version }}
|
40 |
| - gh release create v${{ github.event.inputs.version }} --generate-notes |
| 53 | + if [ "${{ github.event.inputs.is_prerelease }}" == "true" ]; then |
| 54 | + gh release create v${{ github.event.inputs.version }} --prerelease --generate-notes |
| 55 | + else |
| 56 | + gh release create v${{ github.event.inputs.version }} --generate-notes |
| 57 | + fi |
41 | 58 | - name: Publish to PyPI
|
42 | 59 | env:
|
43 | 60 | TWINE_USERNAME: __token__
|
44 | 61 | TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
|
45 | 62 | run: twine upload dist/*
|
| 63 | + |
| 64 | + # Job for automatic beta releases on merge to dev |
| 65 | + auto_beta_release: |
| 66 | + runs-on: ubuntu-latest |
| 67 | + if: github.event_name == 'push' && github.ref == 'refs/heads/dev' |
| 68 | + permissions: |
| 69 | + contents: write |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v3 |
| 72 | + with: |
| 73 | + fetch-depth: 0 |
| 74 | + - name: Set up Python |
| 75 | + uses: actions/setup-python@v5 |
| 76 | + with: |
| 77 | + python-version: "3.10" |
| 78 | + - name: Install dependencies |
| 79 | + run: | |
| 80 | + python -m pip install --upgrade pip |
| 81 | + pip install build twine setuptools-scm |
| 82 | + - name: Generate beta version |
| 83 | + id: beta_version |
| 84 | + run: | |
| 85 | + # Get the latest tag |
| 86 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0") |
| 87 | + # Remove the 'v' prefix if present |
| 88 | + LATEST_VERSION=${LATEST_TAG#v} |
| 89 | + # Split version into components |
| 90 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_VERSION" |
| 91 | + # Extract any existing beta suffix |
| 92 | + PATCH_NUM=${PATCH%%b*} |
| 93 | + # Get commit count since last tag for unique beta number |
| 94 | + COMMIT_COUNT=$(git rev-list --count $LATEST_TAG..HEAD 2>/dev/null || echo "1") |
| 95 | + # Generate beta version |
| 96 | + BETA_VERSION="$MAJOR.$MINOR.$(($PATCH_NUM))b$COMMIT_COUNT" |
| 97 | + echo "Generated beta version: $BETA_VERSION" |
| 98 | + echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT |
| 99 | + # Update version in setup.py or pyproject.toml if needed |
| 100 | + # This depends on how your versioning is configured |
| 101 | + - name: Build package |
| 102 | + run: python -m build |
| 103 | + - name: Create GitHub Pre-Release |
| 104 | + env: |
| 105 | + GITHUB_TOKEN: ${{ secrets.pypi }} |
| 106 | + BETA_VERSION: ${{ steps.beta_version.outputs.version }} |
| 107 | + run: | |
| 108 | + git config user.name github-actions |
| 109 | + git config user.email github-actions@github.com |
| 110 | + git tag v$BETA_VERSION |
| 111 | + git push origin v$BETA_VERSION |
| 112 | + gh release create v$BETA_VERSION --prerelease --title "Beta Release v$BETA_VERSION" --notes "Automated beta release from dev branch" |
| 113 | + - name: Publish to PyPI as Beta |
| 114 | + env: |
| 115 | + TWINE_USERNAME: __token__ |
| 116 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 117 | + BETA_VERSION: ${{ steps.beta_version.outputs.version }} |
| 118 | + run: | |
| 119 | + # Ensure package is marked as beta in PyPI |
| 120 | + twine upload --skip-existing dist/* |
0 commit comments