Skip to content

Commit c83c87a

Browse files
authored
feat: add support for strip_branch_prefix (#406)
* feat: add support for strip_branch_prefix * Update action.yml
1 parent 86aaf17 commit c83c87a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

action.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
name: Branch Names
2-
description: Retrieve github branch or tag information without the /ref/* prefix
2+
description: Retrieve GitHub branch or tag information without the /ref/* prefix
33
author: tj-actions
44
inputs:
55
strip_tag_prefix:
66
description: 'The prefix that should be stripped from the tag e.g `v` -> with a tag `v0.0.1` -> returns `0.0.1`'
77
default: ''
88
required: false
9+
strip_branch_prefix:
10+
description: 'The prefix that should be stripped from the branch e.g `release/` -> with a branch `release/1.0` -> returns `1.0`'
11+
default: ''
12+
required: false
913

1014
outputs:
1115
is_default:
@@ -43,6 +47,7 @@ runs:
4347
GITHUB_HEAD_REF: ${{ github.event.pull_request.head.ref || github.head_ref }}
4448
GITHUB_EVENT_BASE_REF: ${{ github.event.base_ref }}
4549
INPUTS_STRIP_TAG_PREFIX: ${{ inputs.strip_tag_prefix }}
50+
INPUTS_STRIP_BRANCH_PREFIX: ${{ inputs.strip_branch_prefix }}
4651
run: |
4752
# "Set branch names..."
4853
if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then
@@ -55,6 +60,10 @@ runs:
5560
REF_BRANCH=${REF/refs\/pull\//}
5661
REF_BRANCH=${REF_BRANCH/refs\/heads\//}
5762
63+
# Strip branch prefix if provided
64+
REF_BRANCH=${REF_BRANCH/$INPUTS_STRIP_BRANCH_PREFIX/}
65+
HEAD_REF=${HEAD_REF/$INPUTS_STRIP_BRANCH_PREFIX/}
66+
5867
echo "base_ref_branch=$(eval printf "%s" "$BASE_REF")" >> "$GITHUB_OUTPUT"
5968
echo "head_ref_branch=$(eval printf "%s" "$HEAD_REF")" >> "$GITHUB_OUTPUT"
6069
echo "ref_branch=$(eval printf "%s" "$REF_BRANCH")" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)