|
| 1 | +name: PyPI release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + branches: [main] |
| 7 | + push: |
| 8 | + branches: [main] |
| 9 | + release: |
| 10 | + types: [published] |
| 11 | + |
| 12 | +permissions: {} |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + name: Build source distribution |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + contents: read |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + persist-credentials: false |
| 25 | + - name: Install uv |
| 26 | + uses: astral-sh/setup-uv@v8.2.0 |
| 27 | + - name: Build the sdist and the wheel |
| 28 | + run: uv build |
| 29 | + - name: Check the sdist installs and imports |
| 30 | + run: | |
| 31 | + uv tool run --from venv --with venv -- python -m venv venv-sdist |
| 32 | + venv-sdist/bin/python -m pip install dist/tidydraws*.tar.gz |
| 33 | + echo "Checking import and version number (on release)" |
| 34 | + venv-sdist/bin/python -c "import tidydraws; assert tidydraws.__version__ == '${REF_NAME}' if '${REF_TYPE}' == 'tag' else tidydraws.__version__; print(tidydraws.__version__)" |
| 35 | + env: |
| 36 | + REF_NAME: ${{ github.ref_name }} |
| 37 | + REF_TYPE: ${{ github.ref_type }} |
| 38 | + - name: Check the bdist installs and imports |
| 39 | + run: | |
| 40 | + python -m venv venv-bdist |
| 41 | + venv-bdist/bin/python -m pip install dist/tidydraws*.whl |
| 42 | + echo "Checking import and version number (on release)" |
| 43 | + venv-bdist/bin/python -c "import tidydraws; assert tidydraws.__version__ == '${REF_NAME}' if '${REF_TYPE}' == 'tag' else tidydraws.__version__; print(tidydraws.__version__)" |
| 44 | + env: |
| 45 | + REF_NAME: ${{ github.ref_name }} |
| 46 | + REF_TYPE: ${{ github.ref_type }} |
| 47 | + - uses: actions/upload-artifact@v4 |
| 48 | + with: |
| 49 | + name: artifact |
| 50 | + path: dist/* |
| 51 | + |
| 52 | + test-publish: |
| 53 | + name: Upload to Test PyPI |
| 54 | + permissions: |
| 55 | + id-token: write |
| 56 | + needs: [build] |
| 57 | + runs-on: ubuntu-latest |
| 58 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 59 | + steps: |
| 60 | + - uses: actions/download-artifact@v4 |
| 61 | + with: |
| 62 | + name: artifact |
| 63 | + path: dist |
| 64 | + - uses: pypa/gh-action-pypi-publish@v1.14.0 |
| 65 | + with: |
| 66 | + skip_existing: true |
| 67 | + repository_url: https://test.pypi.org/legacy/ |
| 68 | + - name: Test pip install from test.pypi |
| 69 | + run: | |
| 70 | + sleep 5s |
| 71 | + python -m venv venv-test-pypi |
| 72 | + venv-test-pypi/bin/python -m pip install \ |
| 73 | + --index-url https://test.pypi.org/simple/ \ |
| 74 | + --extra-index-url https://pypi.org/simple \ |
| 75 | + tidydraws |
| 76 | + echo "Checking import and version number" |
| 77 | + venv-test-pypi/bin/python -c "import tidydraws; print(tidydraws.__version__)" |
| 78 | +
|
| 79 | + publish: |
| 80 | + environment: release |
| 81 | + permissions: |
| 82 | + id-token: write |
| 83 | + name: Upload release to PyPI |
| 84 | + needs: [build, test-publish] |
| 85 | + runs-on: ubuntu-latest |
| 86 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 87 | + steps: |
| 88 | + - uses: actions/download-artifact@v4 |
| 89 | + with: |
| 90 | + name: artifact |
| 91 | + path: dist |
| 92 | + - uses: pypa/gh-action-pypi-publish@v1.14.0 |
0 commit comments