-
Notifications
You must be signed in to change notification settings - Fork 1
111 lines (97 loc) · 3.53 KB
/
Copy pathpublish.yml
File metadata and controls
111 lines (97 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Publishing uses PyPI Trusted Publishing (OIDC) -- no token secrets.
# One-time setup by a project owner:
# https://pypi.org/manage/project/pythonik/settings/publishing/
# Owner: NorthShoreAutomation, Repository: pythonik,
# Workflow: publish.yml, Environment: pypi
# https://test.pypi.org/manage/account/publishing/ (or the project's
# publishing settings if pythonik already exists on TestPyPI):
# Owner: NorthShoreAutomation, Repository: pythonik,
# Workflow: publish.yml, Environment: testpypi
name: Publish to PyPI
on:
release:
types: [published] # Trigger on manual release publications
workflow_call:
inputs:
publish_test:
description: "Publish to TestPyPI"
required: false
type: boolean
default: false
workflow_dispatch:
inputs:
publish_test:
description: "Publish to TestPyPI"
required: false
type: boolean
default: false
permissions:
contents: read
jobs:
publish:
runs-on: ubuntu-latest
if: inputs.publish_test != true
environment: pypi
permissions:
id-token: write # required for PyPI trusted publishing
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build
run: python -m pip install build
- name: Verify tag matches package version
run: |
if [[ "$GITHUB_REF" != refs/tags/* ]]; then
echo "::error::Publishing to PyPI requires a tag ref, got $GITHUB_REF"
exit 1
fi
python <<'EOF'
import os, sys, tomllib
tag = os.environ["GITHUB_REF_NAME"].removeprefix("v")
with open("pyproject.toml", "rb") as f:
version = tomllib.load(f)["project"]["version"]
if tag != version:
sys.exit(f"Tag {tag!r} does not match pyproject.toml version {version!r}. "
"The generator repo owns the version; re-tag to match.")
print(f"Tag matches pyproject.toml version {version}")
EOF
- name: Build
run: python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
publish-test:
runs-on: ubuntu-latest
if: inputs.publish_test == true && github.event_name == 'workflow_dispatch' # Only run for manual triggers with publish_test true
environment: testpypi
permissions:
id-token: write # required for PyPI trusted publishing
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build
run: python -m pip install build
- name: Verify tag matches package version
if: startsWith(github.ref, 'refs/tags/')
run: |
python <<'EOF'
import os, sys, tomllib
tag = os.environ["GITHUB_REF_NAME"].removeprefix("v")
with open("pyproject.toml", "rb") as f:
version = tomllib.load(f)["project"]["version"]
if tag != version:
sys.exit(f"Tag {tag!r} does not match pyproject.toml version {version!r}. "
"The generator repo owns the version; re-tag to match.")
print(f"Tag matches pyproject.toml version {version}")
EOF
- name: Build
run: python -m build
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/