Skip to content

Commit be7d1c1

Browse files
committed
ci: improve tag validation and extraction in create-linked-release workflow
1 parent dd2750d commit be7d1c1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

.github/workflows/create-linked-release.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ jobs:
3030
- name: Validate Release Tag Format
3131
id: validate_tag
3232
env:
33-
# Use the repo variable for the regex if it exists, otherwise use the default.
3433
VERSION_REGEX: ${{ vars.VERSION_REGEX || '^v?[0-9]+\.[0-9]+\.[0-9]+$' }}
3534
run: |
3635
TAG_NAME="${{ steps.get_release_b.outputs.release }}"
@@ -45,6 +44,10 @@ jobs:
4544
if [[ "$TAG_NAME" =~ $VERSION_REGEX ]]; then
4645
echo "Tag '$TAG_NAME' matches the required format."
4746
echo "is_valid=true" >> "$GITHUB_OUTPUT"
47+
# Extract matched portion (Bash stores full match in BASH_REMATCH[0])
48+
new_version="${BASH_REMATCH[0]}"
49+
echo "Extracted version: $new_version"
50+
echo "new_version=$new_version" >> "$GITHUB_OUTPUT"
4851
else
4952
echo "Tag '$TAG_NAME' does not match the required format. Ignoring."
5053
echo "is_valid=false" >> "$GITHUB_OUTPUT"
@@ -70,7 +73,7 @@ jobs:
7073
id: check_tag
7174
if: steps.validate_tag.outputs.is_valid == 'true'
7275
env:
73-
RELEASE_TAG: ${{ steps.get_release_b.outputs.release }}
76+
RELEASE_TAG: v${{ steps.validate_tag.outputs.new_version }}
7477
run: |
7578
if git tag --list | grep -q "^${RELEASE_TAG}$"; then
7679
echo "Tag '$RELEASE_TAG' already exists. No action needed."
@@ -81,10 +84,11 @@ jobs:
8184
fi
8285
8386
- name: Create and push new tag
87+
id: create_and_push
8488
# This step only runs if the tag is valid AND new.
8589
if: steps.check_tag.outputs.create_tag == 'true'
8690
env:
87-
RELEASE_TAG: ${{ steps.get_release_b.outputs.release }}
91+
RELEASE_TAG: v${{ steps.validate_tag.outputs.new_version }}
8892
run: |
8993
RELEASE_TAG="v${RELEASE_TAG#v}" # Ensure the tag starts with 'v'
9094

0 commit comments

Comments
 (0)