v0.2.10 #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 to PyPI | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Version to build (e.g., 0.2.1)" | |
| required: true | |
| type: string | |
| publish_to_pypi: | |
| description: "Actually publish to PyPI?" | |
| required: true | |
| default: false | |
| type: boolean | |
| jobs: | |
| build: | |
| name: Build distribution | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Extract version | |
| id: get_version | |
| run: | | |
| if [ "${{ github.event_name }}" = "release" ]; then | |
| # Strip 'v' prefix from tag (v0.2.1 -> 0.2.1) | |
| VERSION=${GITHUB_REF_NAME#v} | |
| else | |
| # Use manual input | |
| VERSION="${{ github.event.inputs.version }}" | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Extracted version: $VERSION" | |
| - name: Update version in pyproject.toml | |
| run: | | |
| sed -i "s/^version = .*/version = \"${{ steps.get_version.outputs.VERSION }}\"/" pyproject.toml | |
| echo "Updated pyproject.toml:" | |
| grep "^version" pyproject.toml | |
| - name: Commit version update to repo | |
| if: github.event_name == 'release' | |
| 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 "Bump version to ${{ steps.get_version.outputs.VERSION }}" | |
| git push origin HEAD:main | |
| - name: Install uv | |
| run: | | |
| curl -LsSf https://astral.sh/uv/install.sh | sh | |
| echo "$HOME/.local/bin" >> $GITHUB_PATH | |
| - name: Build package | |
| run: | | |
| uv build | |
| - name: Store the distribution packages | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| - name: Upload assets to GitHub Release | |
| if: github.event_name == 'release' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| gh release upload ${{ github.ref_name }} dist/* --clobber | |
| publish-to-pypi: | |
| name: Publish to PyPI | |
| needs: build | |
| if: github.event_name == 'release' || github.event.inputs.publish_to_pypi == 'true' | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/codeplain | |
| steps: | |
| - name: Download distribution packages | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| - name: Install uv | |
| run: | | |
| curl -LsSf https://astral.sh/uv/install.sh | sh | |
| echo "$HOME/.local/bin" >> $GITHUB_PATH | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: | | |
| uv tool run twine upload dist/* |