-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (139 loc) · 4.68 KB
/
publish.yml
File metadata and controls
165 lines (139 loc) · 4.68 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Publish
on:
workflow_dispatch:
inputs:
publish_testpypi:
description: "Publish to TestPyPI"
type: boolean
default: true
publish_pypi:
description: "Publish to PyPI"
type: boolean
default: false
concurrency:
group: publish
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
new_version: ${{ steps.bump_version.outputs.new_version }}
env:
ACT: ""
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Bump package version
id: bump_version
if: ${{ inputs.publish_testpypi || inputs.publish_pypi }}
run: |
python - <<'PY'
import os
import pathlib
import re
pyproject = pathlib.Path("pyproject.toml")
version_py = pathlib.Path("src/scrapi_sdk/version.py")
pyproject_text = pyproject.read_text(encoding="utf-8")
match = re.search(r'^version\s*=\s*"(\d+)\.(\d+)\.(\d+)"\s*$', pyproject_text, re.MULTILINE)
if not match:
raise SystemExit("Could not find [project] version in pyproject.toml")
major, minor, patch = map(int, match.groups())
new_version = f"{major}.{minor}.{patch + 1}"
pyproject_text = (
pyproject_text[: match.start()] + f'version = "{new_version}"' + pyproject_text[match.end() :]
)
pyproject.write_text(pyproject_text, encoding="utf-8")
version_py_text = version_py.read_text(encoding="utf-8")
version_py_text, replaced = re.subn(
r'__version__\s*=\s*"[^"]+"',
f'__version__ = "{new_version}"',
version_py_text,
count=1,
)
if replaced != 1:
raise SystemExit("Could not update __version__ in src/scrapi_sdk/version.py")
version_py.write_text(version_py_text, encoding="utf-8")
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
output.write(f"new_version={new_version}\n")
PY
- name: Commit version bump
if: ${{ !env.ACT && (inputs.publish_testpypi || inputs.publish_pypi) }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add pyproject.toml src/scrapi_sdk/version.py
if git diff --cached --quiet; then
echo "No version bump changes to commit."
exit 0
fi
git commit -m "chore(release): bump version to ${{ steps.bump_version.outputs.new_version }}"
git tag "v${{ steps.bump_version.outputs.new_version }}"
git push --follow-tags
- name: Install build tools
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build distributions
run: |
rm -rf dist/
python -m build
- name: Check distributions
run: python -m twine check dist/*
- name: Upload dist to artifact
if: ${{ !env.ACT && (inputs.publish_testpypi || inputs.publish_pypi) }}
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
publish-testpypi:
needs: build
if: ${{ inputs.publish_testpypi }}
runs-on: ubuntu-latest
permissions:
id-token: write
environment:
name: testpypi
url: https://test.pypi.org/p/scrapi-sdk
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to TestPyPI (Trusted Publishing)
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
publish-pypi:
needs: build
if: ${{ inputs.publish_pypi }}
runs-on: ubuntu-latest
permissions:
id-token: write
environment:
name: pypi
url: https://pypi.org/p/scrapi-sdk
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Publish to PyPI (Trusted Publishing)
uses: pypa/gh-action-pypi-publish@release/v1
create-release:
needs: [build, publish-pypi]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.build.outputs.new_version }}
name: v${{ needs.build.outputs.new_version }}
generate_release_notes: true