|
28 | 28 | run: | |
29 | 29 | uv pip install --system build |
30 | 30 |
|
| 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 | +
|
31 | 80 | - name: Build package |
32 | 81 | run: | |
33 | 82 | python -m build |
|
0 commit comments