Skip to content

Commit c38079f

Browse files
committed
feat: Add tag existence check to prevent release workflow failures
1 parent 9d91756 commit c38079f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

.github/workflows/publish.yaml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
- run: pip install poetry
1414
- run: poetry install
1515

16-
# Check if version already exists on PyPI
17-
- name: Check if version exists on PyPI
16+
# Check if version already exists on PyPI and if tag exists
17+
- name: Check if version exists on PyPI and if tag exists
1818
id: version_check
1919
run: |
2020
VERSION=$(poetry run ./current_version.py)
@@ -28,6 +28,25 @@ jobs:
2828
echo "Version $VERSION is new, proceeding with release"
2929
echo "skip_release=false" >> $GITHUB_OUTPUT
3030
fi
31+
32+
# Check if tag already exists
33+
if git tag -l | grep -q "v$VERSION"; then
34+
echo "Tag v$VERSION already exists, skipping tag creation"
35+
echo "skip_tag=true" >> $GITHUB_OUTPUT
36+
else
37+
echo "Tag v$VERSION does not exist, will create it"
38+
echo "skip_tag=false" >> $GITHUB_OUTPUT
39+
fi
40+
41+
# Create tag if it doesn't exist
42+
- name: Create tag if needed
43+
if: steps.version_check.outputs.skip_release != 'true' && steps.version_check.outputs.skip_tag != 'true'
44+
run: |
45+
VERSION=$(poetry run ./current_version.py)
46+
git config --local user.email "[email protected]"
47+
git config --local user.name "GitHub Action"
48+
git tag -a "v$VERSION" -m "Release v$VERSION"
49+
git push origin "v$VERSION"
3150
3251
# Only run the release steps if the version doesn't exist on PyPI
3352
- name: Publish to PyPI

0 commit comments

Comments
 (0)