Skip to content

Commit 4db7145

Browse files
authored
feat: add support for using commit hash in tag replacement pattern (#314)
* feat: add support for using commit hash in tag replacement pattern - Introduced `use_tag_commit_hash` input to allow users to include commit hashes in the replacement pattern. - Updated `entrypoint.sh` to handle the new input and adjust the tag replacement logic accordingly. * Update action.yml
1 parent f178279 commit 4db7145

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ inputs:
2323
description: 'Prefix to strip from the tag. For example if `strip_prefix` is set to `v` and the tag is `v1.0.0` the output becomes `1.0.0`.'
2424
required: false
2525
default: ''
26+
use_tag_commit_hash:
27+
description: 'When true, uses commit hash in the replacement pattern. For example, replaces `hash # v1` with `hash # v2`.'
28+
required: false
29+
default: 'false'
2630

2731
outputs:
2832
is_initial_release:
@@ -58,6 +62,7 @@ runs:
5862
INPUT_PATTERN: ${{ inputs.pattern }}
5963
INPUT_ONLY_MAJOR: ${{ inputs.only_major }}
6064
INPUT_STRIP_PREFIX: ${{ inputs.strip_prefix }}
65+
INPUT_USE_TAG_COMMIT_HASH: ${{ inputs.use_tag_commit_hash }}
6166
6267
branding:
6368
icon: arrow-up

entrypoint.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ else
3636
echo "is_initial_release=false" >> "$GITHUB_OUTPUT"
3737
fi
3838

39+
# Get commit hash for current tag if use_tag_commit_hash is true
40+
if [[ "$INPUT_USE_TAG_COMMIT_HASH" == "true" ]]; then
41+
CURRENT_COMMIT_HASH=$(git rev-parse "$CURRENT_TAG" 2>/dev/null || git rev-parse HEAD)
42+
NEW_COMMIT_HASH=$(git rev-parse "$NEW_TAG" 2>/dev/null || git rev-parse HEAD)
43+
CURRENT_PATTERN="$CURRENT_COMMIT_HASH # $CURRENT_TAG"
44+
NEW_PATTERN="$NEW_COMMIT_HASH # $NEW_TAG"
45+
else
46+
CURRENT_PATTERN="$PATTERN$CURRENT_TAG"
47+
NEW_PATTERN="$PATTERN$NEW_TAG"
48+
fi
49+
3950
if [[ "$INPUT_ONLY_MAJOR" == "true" ]]; then
4051
NEW_MAJOR_TAG=$(echo "$NEW_TAG" | cut -d. -f1)
4152
CURRENT_MAJOR_TAG=$(echo "$CURRENT_TAG" | cut -d. -f1)
@@ -51,7 +62,11 @@ EOF
5162
for path in $INPUT_PATHS
5263
do
5364
echo "Replacing major version $CURRENT_MAJOR_TAG with $NEW_MAJOR_TAG for: $path"
54-
sed -i "s|$PATTERN$CURRENT_MAJOR_TAG\(.[[:digit:]]\)\{0,1\}\(.[[:digit:]]\)\{0,1\}|$PATTERN$NEW_MAJOR_TAG|g" "$path"
65+
if [[ "$INPUT_USE_TAG_COMMIT_HASH" == "true" ]]; then
66+
sed -i "s|$CURRENT_PATTERN|$NEW_PATTERN|g" "$path"
67+
else
68+
sed -i "s|$PATTERN$CURRENT_MAJOR_TAG\(.[[:digit:]]\)\{0,1\}\(.[[:digit:]]\)\{0,1\}|$PATTERN$NEW_MAJOR_TAG|g" "$path"
69+
fi
5570
done
5671

5772
cat <<EOF >> "$GITHUB_OUTPUT"
@@ -68,7 +83,7 @@ else
6883
for path in $INPUT_PATHS
6984
do
7085
echo "Replacing $CURRENT_TAG with $NEW_TAG for: $path"
71-
sed -i "s|$PATTERN$CURRENT_TAG|$PATTERN$NEW_TAG|g" "$path"
86+
sed -i "s|$CURRENT_PATTERN|$NEW_PATTERN|g" "$path"
7287
done
7388
fi
7489

0 commit comments

Comments
 (0)