feat: add support for strip_branch_prefix

This commit is contained in:
Tonye Jack 2024-11-21 06:14:44 -07:00 committed by GitHub
parent 32798b2266
commit 660d082e57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,11 +1,15 @@
name: Branch Names 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 author: tj-actions
inputs: inputs:
strip_tag_prefix: 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`' description: 'The prefix that should be stripped from the tag e.g `v` -> with a tag `v0.0.1` -> returns `0.0.1`'
default: '' default: ''
required: false 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: outputs:
is_default: is_default:
@ -43,6 +47,7 @@ runs:
GITHUB_HEAD_REF: ${{ github.event.pull_request.head.ref || github.head_ref }} GITHUB_HEAD_REF: ${{ github.event.pull_request.head.ref || github.head_ref }}
GITHUB_EVENT_BASE_REF: ${{ github.event.base_ref }} GITHUB_EVENT_BASE_REF: ${{ github.event.base_ref }}
INPUTS_STRIP_TAG_PREFIX: ${{ inputs.strip_tag_prefix }} INPUTS_STRIP_TAG_PREFIX: ${{ inputs.strip_tag_prefix }}
INPUTS_STRIP_BRANCH_PREFIX: ${{ inputs.strip_branch_prefix }}
run: | run: |
# "Set branch names..." # "Set branch names..."
if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then
@ -55,6 +60,10 @@ runs:
REF_BRANCH=${REF/refs\/pull\//} REF_BRANCH=${REF/refs\/pull\//}
REF_BRANCH=${REF_BRANCH/refs\/heads\//} 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 "base_ref_branch=$(eval printf "%s" "$BASE_REF")" >> "$GITHUB_OUTPUT"
echo "head_ref_branch=$(eval printf "%s" "$HEAD_REF")" >> "$GITHUB_OUTPUT" echo "head_ref_branch=$(eval printf "%s" "$HEAD_REF")" >> "$GITHUB_OUTPUT"
echo "ref_branch=$(eval printf "%s" "$REF_BRANCH")" >> "$GITHUB_OUTPUT" echo "ref_branch=$(eval printf "%s" "$REF_BRANCH")" >> "$GITHUB_OUTPUT"
@ -71,6 +80,7 @@ runs:
GITHUB_EVENT_NAME: ${{ github.event_name }} GITHUB_EVENT_NAME: ${{ github.event_name }}
HEAD_REF_BRANCH: ${{ steps.branch.outputs.head_ref_branch }} HEAD_REF_BRANCH: ${{ steps.branch.outputs.head_ref_branch }}
REF_BRANCH: ${{ steps.branch.outputs.ref_branch }} REF_BRANCH: ${{ steps.branch.outputs.ref_branch }}
INPUTS_STRIP_BRANCH_PREFIX: ${{ inputs.strip_branch_prefix }}
run: | run: |
# "Set the current branch name..." # "Set the current branch name..."
if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then