Publish distribution to Test PyPI #3
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 distribution to Test PyPI | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| test_version: | |
| description: 'Version to use for testing (e.g., 0.5.1.dev1)' | |
| required: true | |
| type: string | |
| jobs: | |
| build-and-publish: | |
| name: Build and publish to Test PyPI | |
| runs-on: ubuntu-latest | |
| environment: test-release | |
| permissions: | |
| id-token: write # mandatory for trusted publishing | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install build dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install build tomli tomli-w | |
| - name: Set test version | |
| run: | | |
| python - <<EOF | |
| import tomli | |
| import tomli_w | |
| # Read the current pyproject.toml | |
| with open('pyproject.toml', 'rb') as f: | |
| data = tomli.load(f) | |
| # Store the original version and set the test version | |
| data['project']['version'] = '${{ github.event.inputs.test_version }}' | |
| # Write back to pyproject.toml | |
| with open('pyproject.toml', 'wb') as f: | |
| tomli_w.dump(data, f) | |
| EOF | |
| - name: Build distribution packages | |
| run: python -m build | |
| - name: Publish distribution to Test PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ |