77 workflow_dispatch :
88
99jobs :
10- dist :
10+ publish :
1111 runs-on : ubuntu-latest
1212
1313 steps :
1414 - name : Checkout repository
1515 uses : actions/checkout@v4
16- with :
17- fetch-depth : 0
1816
19- - name : Build and inspect package
20- uses : hynek/build-and-inspect-python-package@v2
17+ - name : Set up Python
18+ uses : actions/setup-python@v5
19+ with :
20+ python-version : " 3.11"
2121
22- publish :
23- needs : dist
24- runs-on : ubuntu-latest
25- if : github.event_name == 'release' && github.event.action == 'published'
22+ - name : Install build tooling
23+ run : |
24+ python -m pip install --upgrade pip
25+ python -m pip install build twine
2626
27- steps :
28- - name : Download built artifacts
29- uses : actions/download-artifact@v4
30- with :
31- name : Packages
32- path : dist
27+ - name : Build artifacts
28+ run : python -m build
3329
3430 - name : Configure publish credentials
3531 id : publish-config
3632 env :
33+ EVENT_NAME : ${{ github.event_name }}
3734 RELEASE_NAME : ${{ github.event.release.name }}
3835 DEFAULT_USERNAME : ${{ secrets.twine_username }}
3936 DEFAULT_PASSWORD : ${{ secrets.twine_password }}
@@ -46,14 +43,16 @@ jobs:
4643 username="$DEFAULT_USERNAME"
4744 password="$DEFAULT_PASSWORD"
4845
49- if [[ -n "${RELEASE_NAME}" && "${RELEASE_NAME}" =~ ^[Tt]est ]]; then
50- if [[ -z "${TEST_USERNAME}" || -z "${TEST_PASSWORD}" ]]; then
51- echo "::error::Test PyPI credentials are required for releases starting with 'Test'"
52- exit 1
46+ if [[ "${EVENT_NAME}" == "release" && -n "${RELEASE_NAME}" ]]; then
47+ if [[ "${RELEASE_NAME}" =~ ^[Tt]est ]]; then
48+ if [[ -z "${TEST_USERNAME}" || -z "${TEST_PASSWORD}" ]]; then
49+ echo "::error::Test PyPI credentials are required for releases starting with 'Test'"
50+ exit 1
51+ fi
52+ repository="testpypi"
53+ username="$TEST_USERNAME"
54+ password="$TEST_PASSWORD"
5355 fi
54- repository="testpypi"
55- username="$TEST_USERNAME"
56- password="$TEST_PASSWORD"
5756 fi
5857
5958 if [[ -z "${username}" || -z "${password}" ]]; then
@@ -67,12 +66,10 @@ jobs:
6766 echo "password=${password}"
6867 } >> "$GITHUB_OUTPUT"
6968
70- - name : Publish distribution
69+ - name : Publish distribution to PyPI
7170 env :
7271 TWINE_USERNAME : ${{ steps.publish-config.outputs.username }}
7372 TWINE_PASSWORD : ${{ steps.publish-config.outputs.password }}
7473 TWINE_REPOSITORY : ${{ steps.publish-config.outputs.repository }}
7574 run : |
76- python -m pip install --upgrade pip
77- python -m pip install twine
7875 twine upload --repository "${TWINE_REPOSITORY}" dist/*
0 commit comments