Skip to content

Commit 9d00a95

Browse files
committed
validate tag
1 parent f0c5d3d commit 9d00a95

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

.github/workflows/publish.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ name: Publish
2020
on:
2121
push:
2222
tags:
23-
- "*"
23+
# Trigger this workflow when tag follows the versioning format: v<major>.<minor>.<patch>-rc.<release_candidate>
24+
# Example valid tags: v0.4.0, v0.4.0-rc.1
25+
- "v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?"
2426
workflow_dispatch:
2527

2628
env:

.github/workflows/release_python.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ jobs:
9999
name: Publish Python 🐍 distribution 📦 to Pypi
100100
needs: [sdist, wheels]
101101
runs-on: ubuntu-latest
102-
# Only publish to PyPi if the tag is not a pre-release OR if manually triggered
103-
# Note, `workflow_run.head_branch` does not contain `refs/tags/` prefix, just the tag name, i.e. `v0.4.0` or `v0.4.0-rc.1`
104-
if: ${{ !contains(github.event.workflow_run.head_branch, '-') || github.event_name == 'workflow_dispatch' }}
105102

106103
environment:
107104
name: pypi
@@ -111,6 +108,17 @@ jobs:
111108
id-token: write # IMPORTANT: mandatory for trusted publishing
112109

113110
steps:
111+
- name: Validate release tag format
112+
# Note, `workflow_run.head_branch` does not contain `refs/tags/` prefix, just the tag name, i.e. `v0.4.0` or `v0.4.0-rc.1`
113+
run: |
114+
RELEASE_TAG="${{ github.event.workflow_run.head_branch }}"
115+
echo "Validating release tag: $RELEASE_TAG"
116+
if [[ ! "$RELEASE_TAG" =~ v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)? ]]; then
117+
echo "❌ Invalid release tag format: $RELEASE_TAG"
118+
exit 1
119+
fi
120+
echo "✅ Release tag format is valid"
121+
114122
- name: Download all the dists
115123
uses: actions/download-artifact@v4
116124
with:

0 commit comments

Comments
 (0)