-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (65 loc) · 2.44 KB
/
python-library-release.yml
File metadata and controls
82 lines (65 loc) · 2.44 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
name: python-library-release
on:
workflow_call:
jobs:
bump-and-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-python@v6
with:
python-version: '3.x'
- name: Bump patch version in setup.py
id: bump
run: |
python3 - <<'EOF'
import re, os
with open("setup.py", "r") as f:
content = f.read()
match = re.search(r"version='(\d+\.\d+\.\d+)'", content)
if not match:
raise ValueError("Could not find version string in setup.py")
current = match.group(1)
major, minor, patch = current.split(".")
new_version = f"{major}.{minor}.{int(patch) + 1}"
updated = content.replace(f"version='{current}'", f"version='{new_version}'")
with open("setup.py", "w") as f:
f.write(updated)
print(f"Bumped: {current} -> {new_version}")
with open(os.environ["GITHUB_OUTPUT"], "a") as out:
out.write(f"old_version={current}\n")
out.write(f"new_version={new_version}\n")
EOF
- name: Commit bumped version
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add setup.py
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }} [skip ci]"
git push
- name: Create Git tag
run: |
git tag "v${{ steps.bump.outputs.new_version }}"
git push origin "v${{ steps.bump.outputs.new_version }}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: "v${{ steps.bump.outputs.new_version }}"
name: "v${{ steps.bump.outputs.new_version }}"
body: |
Automatically released on push to `main`.
### Install this version
```bash
python3 -m pip install git+https://github.com/${{ github.repository }}.git@v${{ steps.bump.outputs.new_version }}
```
### Always use latest
```bash
python3 -m pip install --upgrade git+https://github.com/${{ github.repository }}.git@main
```
draft: false
prerelease: false