mirror of
https://github.com/tj-actions/branch-names.git
synced 2024-12-27 14:27:59 +08:00
feat: add support for strip_branch_prefix
This commit is contained in:
parent
32798b2266
commit
660d082e57
12
action.yml
12
action.yml
@ -1,11 +1,15 @@
|
||||
name: Branch Names
|
||||
description: Retrieve github branch or tag information without the /ref/* prefix
|
||||
description: Retrieve GitHub branch or tag information without the /ref/* prefix
|
||||
author: tj-actions
|
||||
inputs:
|
||||
strip_tag_prefix:
|
||||
description: 'The prefix that should be stripped from the tag e.g `v` -> with a tag `v0.0.1` -> returns `0.0.1`'
|
||||
default: ''
|
||||
required: false
|
||||
strip_branch_prefix:
|
||||
description: 'The prefix that should be stripped from the branch e.g `release/` -> with a branch `release/1.0` -> returns `1.0`'
|
||||
default: ''
|
||||
required: false
|
||||
|
||||
outputs:
|
||||
is_default:
|
||||
@ -43,6 +47,7 @@ runs:
|
||||
GITHUB_HEAD_REF: ${{ github.event.pull_request.head.ref || github.head_ref }}
|
||||
GITHUB_EVENT_BASE_REF: ${{ github.event.base_ref }}
|
||||
INPUTS_STRIP_TAG_PREFIX: ${{ inputs.strip_tag_prefix }}
|
||||
INPUTS_STRIP_BRANCH_PREFIX: ${{ inputs.strip_branch_prefix }}
|
||||
run: |
|
||||
# "Set branch names..."
|
||||
if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then
|
||||
@ -55,6 +60,10 @@ runs:
|
||||
REF_BRANCH=${REF/refs\/pull\//}
|
||||
REF_BRANCH=${REF_BRANCH/refs\/heads\//}
|
||||
|
||||
# Strip branch prefix if provided
|
||||
REF_BRANCH=${REF_BRANCH/$INPUTS_STRIP_BRANCH_PREFIX/}
|
||||
HEAD_REF=${HEAD_REF/$INPUTS_STRIP_BRANCH_PREFIX/}
|
||||
|
||||
echo "base_ref_branch=$(eval printf "%s" "$BASE_REF")" >> "$GITHUB_OUTPUT"
|
||||
echo "head_ref_branch=$(eval printf "%s" "$HEAD_REF")" >> "$GITHUB_OUTPUT"
|
||||
echo "ref_branch=$(eval printf "%s" "$REF_BRANCH")" >> "$GITHUB_OUTPUT"
|
||||
@ -71,6 +80,7 @@ runs:
|
||||
GITHUB_EVENT_NAME: ${{ github.event_name }}
|
||||
HEAD_REF_BRANCH: ${{ steps.branch.outputs.head_ref_branch }}
|
||||
REF_BRANCH: ${{ steps.branch.outputs.ref_branch }}
|
||||
INPUTS_STRIP_BRANCH_PREFIX: ${{ inputs.strip_branch_prefix }}
|
||||
run: |
|
||||
# "Set the current branch name..."
|
||||
if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then
|
||||
|
Loading…
x
Reference in New Issue
Block a user