Skip to content

Commit 288c2c1

Browse files
committed
added autoupdate version fix
1 parent 6c5cb0e commit 288c2c1

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

.github/workflows/release.yaml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
name: Sync Version & Publish
1+
name: Publish
22

33
on:
4-
# push:
5-
# tags:
6-
# - "v*.*.*"
7-
workflow_dispatch:
8-
inputs:
9-
version:
10-
description: "Version to release (e.g. 0.6.0)"
11-
required: true
4+
push:
5+
tags:
6+
- "v*.*.*"
127

138
jobs:
149
release:
@@ -23,8 +18,19 @@ jobs:
2318
uses: actions/setup-python@v5
2419
with:
2520
python-version: "3.11"
26-
27-
# Build and publish to PyPI/TestPyPI (same as before)
21+
22+
- name: Update version from tag
23+
run: |
24+
TAG_NAME=${GITHUB_REF#refs/tags/}
25+
python scripts/set_version.py $TAG_NAME
26+
git config user.name "github-actions"
27+
git config user.email "actions@github.com"
28+
git commit -am "chore: set version from $TAG_NAME" || echo "No changes to commit"
29+
git push origin HEAD:${GITHUB_REF_NAME}
30+
31+
- name: Verify new version
32+
run: grep __version__ pytest_htmlx/__init__.py
33+
2834
- name: Install build tools
2935
run: |
3036
python -m pip install --upgrade pip

scripts/set_version.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import re
2+
import sys
3+
from pathlib import Path
4+
5+
root_dir = Path(__file__).parent.parent
6+
if len(sys.argv) != 2:
7+
print("Usage: python scripts/set_version.py vX.Y.Z")
8+
sys.exit(1)
9+
10+
tag = sys.argv[1] # e.g. v0.5.0
11+
if not tag.startswith("v"):
12+
raise RuntimeError("Tag must start with 'v', e.g. v1.2.3")
13+
14+
new_version = tag.lstrip("v")
15+
16+
version_file = root_dir / "pytest_htmlx" / "__init__.py"
17+
text = version_file.read_text()
18+
19+
new_text = re.sub(r'__version__ = ".+"', f'__version__ = "{new_version}"', text)
20+
version_file.write_text(new_text)
21+
22+
print(f"Updated version to {new_version}")

0 commit comments

Comments
 (0)