@@ -2,49 +2,71 @@ name: Deploy
22
33on :
44 push :
5- branches :
6- - main
5+ branches : [main]
6+ tags : ["*"]
7+ pull_request :
8+ branches : [main]
79 release :
810 types :
911 - published
1012 workflow_dispatch :
1113
14+ permissions :
15+ contents : read
16+
1217jobs :
13- deploy :
14- if : github.repository_owner == 'hugovk'
18+ # Always build & lint package.
19+ build-package :
20+ name : Build & verify package
1521 runs-on : ubuntu-latest
1622
17- permissions :
18- # IMPORTANT: this permission is mandatory for OIDC publishing
19- id-token : write
20-
2123 steps :
2224 - uses : actions/checkout@v3
2325 with :
2426 fetch-depth : 0
2527
26- - name : Set up Python
27- uses : actions/setup-python@v4
28+ - uses : hynek/build-and-inspect-python-package@v1
29+
30+ # Upload to Test PyPI on every commit on main.
31+ release-test-pypi :
32+ name : Publish in-dev package to test.pypi.org
33+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
34+ runs-on : ubuntu-latest
35+ needs : build-package
36+
37+ permissions :
38+ # IMPORTANT: this permission is mandatory for trusted publishing
39+ id-token : write
40+
41+ steps :
42+ - name : Download packages built by build-and-inspect-python-package
43+ uses : actions/download-artifact@v3
2844 with :
29- python-version : " 3.x"
30- cache : pip
31- cache-dependency-path : pyproject.toml
32-
33- - name : Install dependencies
34- run : |
35- python -m pip install -U pip
36- python -m pip install -U build twine wheel
37-
38- - name : Build package
39- run : |
40- python -m build
41- twine check --strict dist/*
42-
43- - name : Publish package to PyPI
44- if : github.event.action == 'published'
45- uses : pypa/gh-action-pypi-publish@release/v1
45+ name : Packages
46+ path : dist
4647
47- - name : Publish package to TestPyPI
48+ - name : Upload package to Test PyPI
4849 uses : pypa/gh-action-pypi-publish@release/v1
4950 with :
5051 repository-url : https://test.pypi.org/legacy/
52+
53+ # Upload to real PyPI on GitHub Releases.
54+ release-pypi :
55+ name : Publish released package to pypi.org
56+ if : github.event.action == 'published'
57+ runs-on : ubuntu-latest
58+ needs : build-package
59+
60+ permissions :
61+ # IMPORTANT: this permission is mandatory for trusted publishing
62+ id-token : write
63+
64+ steps :
65+ - name : Download packages built by build-and-inspect-python-package
66+ uses : actions/download-artifact@v3
67+ with :
68+ name : Packages
69+ path : dist
70+
71+ - name : Upload package to PyPI
72+ uses : pypa/gh-action-pypi-publish@release/v1
0 commit comments