Skip to content

Commit eb5d52e

Browse files
committed
Isolate package build and publish
1 parent 5bb6232 commit eb5d52e

1 file changed

Lines changed: 73 additions & 38 deletions

File tree

.github/workflows/publish.yml

Lines changed: 73 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This workflow is triggered two ways:
22
#
3-
# 1. When a tag is created, the workflow will upload the package to
3+
# 1. When a commit is made, the workflow will upload the package to
44
# test.pypi.org.
55
# 2. When a release is made, the workflow will upload the package to pypi.org.
66
#
@@ -9,49 +9,84 @@
99
name: Upload package
1010

1111
on:
12-
release:
13-
types: [created]
1412
push:
15-
tags:
16-
- '*'
13+
pull_request:
14+
release:
15+
types:
16+
- published
17+
workflow_dispatch:
18+
19+
permissions:
20+
contents: read
21+
22+
env:
23+
FORCE_COLOR: 1
1724

1825
jobs:
19-
deploy:
26+
# Always build & lint package.
27+
build-package:
28+
name: Build & verify package
2029
runs-on: ubuntu-latest
30+
31+
steps:
32+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
33+
with:
34+
fetch-depth: 0
35+
persist-credentials: false
36+
37+
- uses: hynek/build-and-inspect-python-package@fe0a0fb1925ca263d076ca4f2c13e93a6e92a33e # v2.17.0
38+
39+
# Publish to Test PyPI on every commit on main.
40+
release-test-pypi:
41+
name: Publish in-dev package to test.pypi.org
42+
if: |
43+
github.repository_owner == 'python'
44+
&& github.event_name == 'push'
45+
&& github.ref == 'refs/heads/main'
46+
runs-on: ubuntu-latest
47+
needs: build-package
48+
49+
permissions:
50+
id-token: write
51+
52+
steps:
53+
- name: Download packages built by build-and-inspect-python-package
54+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
55+
with:
56+
name: Packages
57+
path: dist
58+
59+
- name: Publish to Test PyPI
60+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
61+
with:
62+
repository-url: https://test.pypi.org/legacy/
63+
64+
# Publish to PyPI on GitHub Releases.
65+
release-pypi:
66+
name: Publish to PyPI
67+
# Only run for published releases.
68+
if: |
69+
github.repository_owner == 'python'
70+
&& github.event.action == 'published'
71+
runs-on: ubuntu-latest
72+
needs: build-package
73+
2174
environment:
2275
name: release
23-
url: https://pypi.org/p/tzdata
76+
url: >-
77+
https://pypi.org/project/tzdata/${{
78+
github.event.release.tag_name
79+
}}
80+
2481
permissions:
2582
id-token: write
83+
2684
steps:
27-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
28-
with:
29-
persist-credentials: false
30-
- name: Set up Python
31-
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
32-
with:
33-
python-version: '3.x'
34-
- name: Install dependencies
35-
run: |
36-
python -m pip install --upgrade pip
37-
pip install -U tox
38-
- name: Create tox environments
39-
run: |
40-
tox -p -e py,build --notest
41-
- name: Run tests
42-
run: |
43-
tox -e py
44-
- name: Build package
45-
run: |
46-
tox -e build
47-
- name: Publish package (TestPyPI)
48-
if: github.event_name == 'push'
49-
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
50-
with:
51-
repository-url: https://test.pypi.org/legacy/
52-
verbose: true
53-
- name: Publish package
54-
if: github.event_name == 'release'
55-
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
56-
with:
57-
verbose: true
85+
- name: Download packages built by build-and-inspect-python-package
86+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
87+
with:
88+
name: Packages
89+
path: dist
90+
91+
- name: Publish to PyPI
92+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0

0 commit comments

Comments
 (0)