-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (82 loc) · 3.03 KB
/
publish.yml
File metadata and controls
96 lines (82 loc) · 3.03 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
name: Publish to PyPI
on:
push:
branches: ["main"]
permissions:
contents: write
concurrency:
group: publish-pypi
cancel-in-progress: false
jobs:
publish:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'chore: bump version')"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build tools
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Bump patch version in stable.toml and dev.toml
id: bump
run: |
python <<'EOF'
import os
import pathlib
import re
def bump(path: pathlib.Path) -> str:
text = path.read_text(encoding="utf-8")
match = re.search(r'^version\s*=\s*"(\d+)\.(\d+)\.(\d+)"', text, re.MULTILINE)
if not match:
raise SystemExit(f"Could not find version in {path}")
major, minor, patch = (int(part) for part in match.groups())
new_version = f"{major}.{minor}.{patch + 1}"
new_text = re.sub(
r'^(version\s*=\s*)"\d+\.\d+\.\d+"',
rf'\1"{new_version}"',
text,
count=1,
flags=re.MULTILINE,
)
path.write_text(new_text, encoding="utf-8")
return new_version
stable_version = bump(pathlib.Path("stable.toml"))
dev_version = bump(pathlib.Path("dev.toml"))
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
output.write(f"new_version={stable_version}\n")
output.write(f"dev_version={dev_version}\n")
print(f"stable.toml -> {stable_version}")
print(f"dev.toml -> {dev_version}")
EOF
- name: Use stable.toml as pyproject.toml
run: cp stable.toml pyproject.toml
- name: Build distribution
run: python -m build
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload --non-interactive dist/*
- name: Commit and tag version bump
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add stable.toml dev.toml
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }}"
git tag "v${{ steps.bump.outputs.new_version }}"
git push origin main
git push origin "v${{ steps.bump.outputs.new_version }}"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "v${{ steps.bump.outputs.new_version }}" \
dist/* \
--title "v${{ steps.bump.outputs.new_version }}" \
--generate-notes