Skip to content

Commit 68d4d51

Browse files
Isolate package build and publish (#137)
Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 5bb6232 commit 68d4d51

4 files changed

Lines changed: 88 additions & 50 deletions

File tree

.github/workflows/publish.yml

Lines changed: 80 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,92 @@
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+
build-package:
27+
name: Build & verify package
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
32+
with:
33+
persist-credentials: false
34+
35+
- uses: hynek/build-and-inspect-python-package@fe0a0fb1925ca263d076ca4f2c13e93a6e92a33e # v2.17.0
36+
37+
test-package:
38+
name: Test package
39+
if: |
40+
github.event.repository.fork == false
41+
&& (
42+
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
43+
|| github.event.action == 'published'
44+
)
45+
needs: build-package
46+
uses: ./.github/workflows/tests.yml
47+
48+
# Publish to TestPyPI for every tag.
49+
release-test-pypi:
50+
name: Publish to TestPyPI
51+
if: |
52+
github.event.repository.fork == false
53+
&& github.event_name == 'push'
54+
&& startsWith(github.ref, 'refs/tags/')
55+
runs-on: ubuntu-latest
56+
needs: test-package
57+
58+
permissions:
59+
id-token: write
60+
61+
steps:
62+
- name: Download packages built by build-and-inspect-python-package
63+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
64+
with:
65+
name: Packages
66+
path: dist
67+
68+
- name: Publish to Test PyPI
69+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
70+
with:
71+
repository-url: https://test.pypi.org/legacy/
72+
73+
release-pypi:
74+
name: Publish to PyPI
75+
# Only run for published releases.
76+
if: |
77+
github.event.repository.fork == false
78+
&& github.event.action == 'published'
2079
runs-on: ubuntu-latest
80+
needs: test-package
81+
2182
environment:
2283
name: release
23-
url: https://pypi.org/p/tzdata
84+
url: >-
85+
https://pypi.org/project/tzdata/${{
86+
github.event.release.tag_name
87+
}}
88+
2489
permissions:
2590
id-token: write
91+
2692
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
93+
- name: Download packages built by build-and-inspect-python-package
94+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
95+
with:
96+
name: Packages
97+
path: dist
98+
99+
- name: Publish to PyPI
100+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0

.github/workflows/tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- master
77
pull_request:
8+
workflow_call:
89
workflow_dispatch:
910

1011
permissions: {}
@@ -50,7 +51,7 @@ jobs:
5051
runs-on: "ubuntu-latest"
5152
strategy:
5253
matrix:
53-
toxenv: ["build", "precommit", "typing", "docs"]
54+
toxenv: ["precommit", "typing", "docs"]
5455
env:
5556
TOXENV: ${{ matrix.toxenv }}
5657

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
requires = ["setuptools>=40.8.0", "wheel"]
33
build-backend = "setuptools.build_meta"
44

5+
[tool.check-wheel-contents]
6+
# The wheel contains duplicate files.
7+
# This is by design, see https://github.com/eggert/tz/blob/main/backward
8+
# Let's ignore the warning:
9+
ignore = ["W002"]
10+
511
[tool.isort]
612
atomic=true
713
force_grid_wrap=0

tox.ini

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,3 @@ deps =
7070
commands =
7171
sphinx-build -d "{toxworkdir}/docs_doctree" "{toxinidir}/docs" \
7272
"{toxinidir}/docs/_output" {posargs: -j auto --color -bhtml}
73-
74-
[testenv:build]
75-
description = Build a wheel and source distribution
76-
skip_install = True
77-
deps =
78-
build
79-
twine
80-
commands =
81-
python -c "from pathlib import Path; \
82-
[x.unlink(missing_ok=True) for x in Path('{toxinidir}/dist').glob('*')]"
83-
python -m build -o {toxinidir}/dist {toxinidir}
84-
twine check {toxinidir}/dist/*

0 commit comments

Comments
 (0)