Skip to content

Commit 304853e

Browse files
authored
Add GitHub Actions workflow for versioning and release
1 parent be2edde commit 304853e

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Auto-bump version, release, and publish
2+
3+
on:
4+
push:
5+
branches:
6+
- Publish
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
bump-release-publish:
13+
name: Auto-bump version and publish
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Check out repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.11"
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
python -m pip install build twine toml
31+
32+
- name: Auto-increment version
33+
id: bump
34+
run: |
35+
python - << 'PY'
36+
import os
37+
import toml
38+
from pathlib import Path
39+
40+
path = Path("pyproject.toml")
41+
data = toml.loads(path.read_text(encoding="utf-8"))
42+
43+
version = data["project"]["version"]
44+
45+
major, minor, patch = version.split(".")
46+
patch = str(int(patch) + 1)
47+
new_version = ".".join([major, minor, patch])
48+
49+
data["project"]["version"] = new_version
50+
path.write_text(toml.dumps(data), encoding="utf-8")
51+
52+
print(f"Bumped version: {version} -> {new_version}")
53+
54+
# Export for later steps
55+
github_output = os.environ["GITHUB_OUTPUT"]
56+
with open(github_output, "a", encoding="utf-8") as f:
57+
f.write(f"new_version={new_version}\n")
58+
PY
59+
60+
- name: Commit updated version on Publish
61+
run: |
62+
git config user.name "github-actions"
63+
git config user.email "[email protected]"
64+
git add pyproject.toml
65+
66+
if git diff --cached --quiet; then
67+
echo "No version change to commit on Publish."
68+
else
69+
git commit -m "Auto-bump version to ${{ steps.bump.outputs.new_version }}"
70+
git push origin HEAD:Publish
71+
fi
72+
73+
- name: Sync pyproject.toml to main
74+
# Only run if we actually bumped/committed something
75+
run: |
76+
VERSION="${{ steps.bump.outputs.new_version }}"
77+
echo "Syncing version $VERSION to main branch"
78+
79+
# Make sure we have the latest branches
80+
git fetch origin
81+
82+
# Switch to main and pull latest
83+
git checkout main
84+
git pull origin main
85+
86+
# Bring over the bumped pyproject.toml from Publish
87+
git checkout Publish -- pyproject.toml
88+
89+
# Stage and commit if there is a change
90+
if git diff --cached --quiet; then
91+
echo "No changes to commit on main."
92+
else
93+
git add pyproject.toml
94+
git commit -m "Sync version to ${VERSION} from Publish"
95+
git push origin main
96+
fi
97+
98+
- name: Build distributions
99+
run: |
100+
python -m build
101+
102+
- name: Publish to PyPI
103+
env:
104+
TWINE_USERNAME: "__token__"
105+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
106+
run: |
107+
twine upload dist/*
108+
109+
- name: Create GitHub release
110+
uses: softprops/action-gh-release@v2
111+
with:
112+
tag_name: v${{ steps.bump.outputs.new_version }}
113+
name: docker-enumsensitive v${{ steps.bump.outputs.new_version }}
114+
generate_release_notes: true
115+
env:
116+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)