Skip to content

Commit d9cda7e

Browse files
author
Anket Satbhai
committed
feat: add tag name validation
1 parent 42d44bc commit d9cda7e

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

.github/workflows/release-major-tag.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,57 @@ jobs:
1414
runs-on: ubuntu-latest
1515

1616
steps:
17+
- name: Check tag format
18+
id: check
19+
run: |
20+
TAG=${{ github.event.release.tag_name }}
21+
22+
echo "Release tag: $TAG"
23+
24+
if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
25+
echo "valid=true" >> $GITHUB_OUTPUT
26+
echo "Tag format valid"
27+
else
28+
echo "valid=false" >> $GITHUB_OUTPUT
29+
echo "Tag format invalid. Workflow will skip."
30+
fi
31+
1732
- name: Checkout repo
33+
if: steps.check.outputs.valid == 'true'
1834
uses: actions/checkout@v4
1935
with:
2036
fetch-depth: 0
2137

2238
- name: Fetch tags
39+
if: steps.check.outputs.valid == 'true'
2340
run: git fetch --tags
2441

2542
- name: Configure git
43+
if: steps.check.outputs.valid == 'true'
2644
run: |
2745
git config user.name "github-actions[bot]"
2846
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
2947
3048
- name: Extract major version
49+
if: steps.check.outputs.valid == 'true'
3150
id: version
3251
run: |
33-
TAG=${GITHUB_REF#refs/tags/}
34-
35-
echo "Release tag: $TAG"
52+
TAG=${{ github.event.release.tag_name }}
3653
37-
# Extract major version from X.Y.Z
3854
MAJOR=$(echo "$TAG" | cut -d. -f1)
39-
4055
MAJOR_TAG="v$MAJOR"
4156
4257
echo "Major tag: $MAJOR_TAG"
4358
4459
echo "major_tag=$MAJOR_TAG" >> $GITHUB_OUTPUT
4560
4661
- name: Update major tag
62+
if: steps.check.outputs.valid == 'true'
4763
run: |
48-
git tag -f ${{ steps.version.outputs.major_tag }} ${{ github.ref_name }}
64+
git tag -f ${{ steps.version.outputs.major_tag }} ${{ github.event.release.tag_name }}
4965
5066
- name: Push major tag
67+
if: steps.check.outputs.valid == 'true'
5168
run: |
5269
git push origin ${{ steps.version.outputs.major_tag }} --force
5370
...

0 commit comments

Comments
 (0)