Skip to content

Commit 341f243

Browse files
authored
Add version extraction and update for release workflow
1 parent 95c6955 commit 341f243

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,55 @@ jobs:
2828
run: |
2929
uv pip install --system build
3030
31+
- name: Extract version from tag
32+
id: get_version
33+
run: |
34+
# Extract version from tag (e.g., v0.4.0 -> 0.4.0 or 0.4.0 -> 0.4.0)
35+
TAG_NAME=${GITHUB_REF#refs/tags/}
36+
# Remove 'v' prefix if it exists at the start
37+
if [[ "$TAG_NAME" == v* ]]; then
38+
VERSION="${TAG_NAME:1}"
39+
else
40+
VERSION="$TAG_NAME"
41+
fi
42+
echo "version=$VERSION" >> $GITHUB_OUTPUT
43+
echo "Extracted version: $VERSION from tag: $TAG_NAME"
44+
45+
- name: Update version in pyproject.toml
46+
env:
47+
VERSION: ${{ steps.get_version.outputs.version }}
48+
run: |
49+
python3 << 'EOF'
50+
import os
51+
import re
52+
53+
version = os.environ['VERSION']
54+
55+
# Read pyproject.toml
56+
with open("pyproject.toml", "r") as f:
57+
content = f.read()
58+
59+
# Escape special characters in version for TOML
60+
# Replace backslash and double quote with escaped versions
61+
escaped_version = version.replace('\\', '\\\\').replace('"', '\\"')
62+
63+
# Update version line (handles both single and double quotes)
64+
updated_content = re.sub(
65+
r'^version\s*=\s*["\'][^"\']*["\']',
66+
f'version = "{escaped_version}"',
67+
content,
68+
count=1,
69+
flags=re.MULTILINE
70+
)
71+
72+
# Write back
73+
with open("pyproject.toml", "w") as f:
74+
f.write(updated_content)
75+
76+
print(f"Updated pyproject.toml with version {version}")
77+
EOF
78+
grep "^version = " pyproject.toml
79+
3180
- name: Build package
3281
run: |
3382
python -m build

0 commit comments

Comments
 (0)