|
| 1 | +name: Publish Release (v5) |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + environment: |
| 7 | + description: 'Target environment' |
| 8 | + type: choice |
| 9 | + required: true |
| 10 | + options: |
| 11 | + - testpypi |
| 12 | + - pypi |
| 13 | + default: 'testpypi' |
| 14 | + pull_request: |
| 15 | + branches: |
| 16 | + - v5 |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + id-token: write |
| 21 | + |
| 22 | +jobs: |
| 23 | + publish-pypi: |
| 24 | + name: "PyPI" |
| 25 | + runs-on: ubuntu-latest |
| 26 | + environment: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'testpypi' }} |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Checkout code |
| 30 | + uses: actions/checkout@v5 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + fetch-tags: true |
| 34 | + |
| 35 | + - id: get_version |
| 36 | + name: Get version from pyproject.toml |
| 37 | + run: | |
| 38 | + VERSION=$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/') |
| 39 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 40 | + echo "Version: $VERSION" |
| 41 | +
|
| 42 | + - id: get_prerelease |
| 43 | + name: Determine if pre-release |
| 44 | + run: | |
| 45 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 46 | + if [[ "$VERSION" =~ (a|alpha|b|beta|rc)[0-9]* ]]; then |
| 47 | + echo "prerelease=true" >> $GITHUB_OUTPUT |
| 48 | + echo "Pre-release: true" |
| 49 | + else |
| 50 | + echo "prerelease=false" >> $GITHUB_OUTPUT |
| 51 | + echo "Stable release" |
| 52 | + fi |
| 53 | +
|
| 54 | + - name: Create GitHub Release |
| 55 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'pypi' |
| 56 | + id: create_release |
| 57 | + uses: actions/create-release@v1 |
| 58 | + env: |
| 59 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + with: |
| 61 | + tag_name: v${{ steps.get_version.outputs.version }} |
| 62 | + release_name: v${{ steps.get_version.outputs.version }} |
| 63 | + body: | |
| 64 | + See [v5_MIGRATION_GUIDE.md](https://github.com/${{ github.repository }}/blob/main/v5_MIGRATION_GUIDE.md) for migration instructions. |
| 65 | + draft: false |
| 66 | + prerelease: ${{ steps.get_prerelease.outputs.prerelease }} |
| 67 | + |
| 68 | + - name: Configure Python |
| 69 | + uses: actions/setup-python@v6 |
| 70 | + with: |
| 71 | + python-version: "3.10" |
| 72 | + |
| 73 | + - name: Configure dependencies |
| 74 | + run: | |
| 75 | + pip install --user --upgrade pip |
| 76 | + pip install --user pipx |
| 77 | + pipx ensurepath |
| 78 | + pipx install poetry |
| 79 | + poetry config virtualenvs.in-project true |
| 80 | + poetry install |
| 81 | +
|
| 82 | + - name: Build release |
| 83 | + run: | |
| 84 | + poetry build |
| 85 | + ls -lh dist/ |
| 86 | + echo "Build successful! Artifacts created:" |
| 87 | + ls -lh dist/ |
| 88 | +
|
| 89 | + - name: Publish to Test PyPI |
| 90 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'testpypi' |
| 91 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 92 | + with: |
| 93 | + repository-url: https://test.pypi.org/legacy/ |
| 94 | + skip-existing: true |
| 95 | + print-hash: true |
| 96 | + |
| 97 | + - name: Publish to PyPI |
| 98 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'pypi' |
| 99 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 100 | + with: |
| 101 | + print-hash: true |
| 102 | + |
| 103 | + - name: Summary |
| 104 | + run: | |
| 105 | + echo "### Release Summary" >> $GITHUB_STEP_SUMMARY |
| 106 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 107 | + echo "- Version: ${{ steps.get_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 108 | + echo "- Environment: ${{ github.event.inputs.environment }}" >> $GITHUB_STEP_SUMMARY |
| 109 | + echo "- Pre-release: ${{ steps.get_prerelease.outputs.prerelease }}" >> $GITHUB_STEP_SUMMARY |
0 commit comments