Skip to content

Commit 40be0cb

Browse files
simplify PyPI publihsing
1 parent ef05b87 commit 40be0cb

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

.github/workflows/publish-to-pypi.yml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
publish:
10+
dist:
1111
runs-on: ubuntu-latest
12-
permissions:
13-
contents: read
14-
id-token: write
1512

1613
steps:
1714
- name: Checkout repository
1815
uses: actions/checkout@v4
19-
20-
- name: Set up Python
21-
uses: actions/setup-python@v5
2216
with:
23-
python-version: "3.11"
17+
fetch-depth: 0
2418

25-
- name: Install build tooling
26-
run: |
27-
python -m pip install --upgrade pip
28-
python -m pip install build twine
19+
- name: Build and inspect package
20+
uses: hynek/build-and-inspect-python-package@v2
21+
22+
publish:
23+
needs: dist
24+
runs-on: ubuntu-latest
25+
if: github.event_name == 'release' && github.event.action == 'published'
2926

30-
- name: Build artifacts
31-
run: python -m build
27+
steps:
28+
- name: Download built artifacts
29+
uses: actions/download-artifact@v4
30+
with:
31+
name: Packages
32+
path: dist
3233

3334
- name: Configure publish credentials
3435
id: publish-config
3536
env:
36-
EVENT_NAME: ${{ github.event_name }}
3737
RELEASE_NAME: ${{ github.event.release.name }}
3838
DEFAULT_USERNAME: ${{ secrets.twine_username }}
3939
DEFAULT_PASSWORD: ${{ secrets.twine_password }}
@@ -46,16 +46,14 @@ jobs:
4646
username="$DEFAULT_USERNAME"
4747
password="$DEFAULT_PASSWORD"
4848
49-
if [[ "${EVENT_NAME}" == "release" && -n "${RELEASE_NAME}" ]]; then
50-
if [[ "${RELEASE_NAME}" =~ ^[Tt]est ]]; then
51-
if [[ -z "${TEST_USERNAME}" || -z "${TEST_PASSWORD}" ]]; then
52-
echo "::error::Test PyPI credentials are required for releases starting with 'Test'"
53-
exit 1
54-
fi
55-
repository="testpypi"
56-
username="$TEST_USERNAME"
57-
password="$TEST_PASSWORD"
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
5853
fi
54+
repository="testpypi"
55+
username="$TEST_USERNAME"
56+
password="$TEST_PASSWORD"
5957
fi
6058
6159
if [[ -z "${username}" || -z "${password}" ]]; then
@@ -69,10 +67,12 @@ jobs:
6967
echo "password=${password}"
7068
} >> "$GITHUB_OUTPUT"
7169
72-
- name: Publish distribution to PyPI
70+
- name: Publish distribution
7371
env:
7472
TWINE_USERNAME: ${{ steps.publish-config.outputs.username }}
7573
TWINE_PASSWORD: ${{ steps.publish-config.outputs.password }}
7674
TWINE_REPOSITORY: ${{ steps.publish-config.outputs.repository }}
7775
run: |
76+
python -m pip install --upgrade pip
77+
python -m pip install twine
7878
twine upload --repository "${TWINE_REPOSITORY}" dist/*

0 commit comments

Comments
 (0)