v1.30.0 #56
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: Release to PyPI | |
| on: | |
| release: | |
| types: [published] | |
| permissions: | |
| id-token: write | |
| contents: write # Required for posting release updates | |
| jobs: | |
| # ========================= | |
| # PRE-RELEASE VALIDATION | |
| # ========================= | |
| validate-release: | |
| name: Validate Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Verify version matches tag | |
| run: | | |
| TAG_VERSION="${{ github.event.release.tag_name }}" | |
| TAG_VERSION="${TAG_VERSION#v}" # Remove 'v' prefix if present | |
| # Extract version from pyproject.toml | |
| PKG_VERSION=$(python -c " | |
| import tomllib | |
| with open('pyproject.toml', 'rb') as f: | |
| data = tomllib.load(f) | |
| print(data['project']['version']) | |
| ") | |
| if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then | |
| echo "❌ Version mismatch!" | |
| echo " Git tag: v$TAG_VERSION" | |
| echo " pyproject.toml: $PKG_VERSION" | |
| exit 1 | |
| fi | |
| echo "✅ Version matches: $TAG_VERSION" | |
| # ========================= | |
| # BUILD & PUBLISH | |
| # ========================= | |
| build-and-publish: | |
| name: Build and Publish to PyPI | |
| runs-on: ubuntu-latest | |
| needs: validate-release | |
| environment: pypi | |
| permissions: | |
| id-token: write # Required for trusted publishing | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install build tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install build twine | |
| - name: Build package | |
| run: python -m build | |
| - name: Check package | |
| run: twine check dist/* | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| skip-existing: true | |
| - name: Update release with PyPI info | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const tag = context.payload.release.tag_name; | |
| const releaseUrl = context.payload.release.html_url; | |
| const pypiUrl = `https://pypi.org/project/cleancloud/${tag.replace('v', '')}/`; | |
| const currentBody = context.payload.release.body || ''; | |
| const pypiInfo = `\n\n---\n\n✅ **Published to PyPI**\n\n📦 Install: \`pipx install cleancloud==${tag.replace('v', '')}\`\n🔗 PyPI: ${pypiUrl}`; | |
| await github.rest.repos.updateRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: context.payload.release.id, | |
| body: currentBody + pypiInfo | |
| }); |