File tree Expand file tree Collapse file tree 1 file changed +34
-1
lines changed
Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -56,13 +56,13 @@ actions:
5656 - trunk-upgrade-available
5757 - trunk-check-pre-commit
5858 - ensure-tag-matches-version
59+ - update-version-from-tag
5960 definitions :
6061 - id : ensure-tag-matches-version
6162 description : Hooks to ensure git tag matches version in pyproject.toml
6263 triggers :
6364 - git_hooks :
6465 - pre-push
65- - pre-commit
6666 run : |
6767 #!/usr/bin/env bash
6868 set -e
@@ -91,6 +91,39 @@ actions:
9191 echo "Not on main/master branch - skipping tag validation."
9292 fi
9393 exit 0
94+ - id : update-version-from-tag
95+ description : Update version in pyproject.toml from git tag
96+ triggers :
97+ - git_hooks :
98+ - pre-push
99+ run : |
100+ #!/usr/bin/env bash
101+ set -e
102+
103+ # Check if we're on main or master branch
104+ if git rev-parse --abbrev-ref HEAD | grep -q 'main\|master'; then
105+ # Try to get the tag for the current commit, ignore errors
106+ TAG=$(git describe --tags --exact-match "$(git log -n1 --pretty='%h')" 2>/dev/null || true)
107+
108+ # If no tag found, skip updating version entirely
109+ if [ -z "$TAG" ]; then
110+ echo "No tag found for the current commit - skipping version update."
111+ exit 0
112+ fi
113+
114+ # Update pyproject.toml version if it differs from the tag
115+ VERSION=$(grep '^version =' pyproject.toml | sed -E 's/version = "(.*)"/\1/' 2>/dev/null || echo "")
116+
117+ if [ "$TAG" != "$VERSION" ]; then
118+ echo "Updating version in pyproject.toml from '$VERSION' to '$TAG'."
119+ uv version "$TAG"
120+ else
121+ echo "Version in pyproject.toml already matches tag '$TAG'."
122+ fi
123+ else
124+ echo "Not on main/master branch - skipping version update."
125+ fi
126+ exit 0
94127tools :
95128 enabled :
96129
You can’t perform that action at this time.
0 commit comments