v2.8.0 #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: publish-pypi | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| upload: | |
| description: 'Upload to PyPI' | |
| required: false | |
| default: 'true' | |
| jobs: | |
| update-version: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| if: github.event_name == 'release' | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| ref: main | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| VERSION=${{ github.event.release.tag_name }} | |
| VERSION=${VERSION#v} # Remove 'v' prefix if present | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Update pyproject.toml | |
| run: | | |
| sed -i 's/version = "[^"]*"/version = "${{ steps.version.outputs.version }}"/' pyproject.toml | |
| - name: Commit and push version update | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add pyproject.toml | |
| git commit -m "chore: bump version to ${{ steps.version.outputs.version }}" | |
| git push origin main | |
| build: | |
| needs: update-version | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.11' | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build setuptools wheel | |
| - name: Build distribution | |
| run: python -m build | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: distribution | |
| path: dist/ | |
| publish: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.upload == 'true') | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: distribution | |
| path: dist/ | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.11' | |
| - name: Install Twine | |
| run: pip install twine | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: twine upload dist/* --skip-existing | |
| - name: Create release note | |
| if: github.event_name == 'release' | |
| run: | | |
| echo "✅ Package published to PyPI successfully!" | |
| echo "Version: ${{ github.event.release.tag_name }}" | |
| echo "PyPI URL: https://pypi.org/project/struct/" |