Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,33 @@ jobs:
echo "Is Default: ${{ steps.branch-names-strip_branch_prefix.outputs.is_default }}"
echo "Is Tag: ${{ steps.branch-names-strip_branch_prefix.outputs.is_tag }}"
echo "Current tag: ${{ steps.branch-names-strip_branch_prefix.outputs.tag }}"

- name: Run test replace_slashes_with_hyphens
id: branch-names-replace-slashes
uses: ./
with:
replace_slashes_with_hyphens: 'true'
- name: Show output with replaced slashes
run: |
echo "Default Branch: ${{ steps.branch-names-replace-slashes.outputs.default_branch }}"
echo "Current Branch: ${{ steps.branch-names-replace-slashes.outputs.current_branch }}"
echo "Base Ref: ${{ steps.branch-names-replace-slashes.outputs.base_ref_branch }}"
echo "Head Ref: ${{ steps.branch-names-replace-slashes.outputs.head_ref_branch }}"
echo "Ref: ${{ steps.branch-names-replace-slashes.outputs.ref_branch }}"
echo "Is Default: ${{ steps.branch-names-replace-slashes.outputs.is_default }}"
echo "Is Tag: ${{ steps.branch-names-replace-slashes.outputs.is_tag }}"
echo "Current tag: ${{ steps.branch-names-replace-slashes.outputs.tag }}"
- name: Test slash replacement in branch names
if: contains(github.event_name, 'pull_request')
shell: bash
run: |
head_ref="${{ steps.branch-names-replace-slashes.outputs.head_ref_branch }}"
if [[ "$head_ref" == *"/"* ]]; then
echo "Slash found in head_ref_branch after replacement: $head_ref"
exit 1
fi
current_branch="${{ steps.branch-names-replace-slashes.outputs.current_branch }}"
if [[ "$current_branch" == *"/"* ]]; then
echo "Slash found in current_branch after replacement: $current_branch"
exit 1
fi
23 changes: 23 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
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
replace_slashes_with_hyphens:
description: 'Replace forward slashes with hyphens in branch names'
default: 'false'
required: false

outputs:
is_default:
Expand Down Expand Up @@ -48,6 +52,7 @@ runs:
GITHUB_EVENT_BASE_REF: ${{ github.event.base_ref }}
INPUTS_STRIP_TAG_PREFIX: ${{ inputs.strip_tag_prefix }}
INPUTS_STRIP_BRANCH_PREFIX: ${{ inputs.strip_branch_prefix }}
INPUTS_REPLACE_SLASHES: ${{ inputs.replace_slashes_with_hyphens }}
run: |
# "Set branch names..."
if [[ "$GITHUB_REF" != "refs/tags/"* ]]; then
Expand All @@ -64,13 +69,25 @@ runs:
REF_BRANCH=${REF_BRANCH/$INPUTS_STRIP_BRANCH_PREFIX/}
HEAD_REF=${HEAD_REF/$INPUTS_STRIP_BRANCH_PREFIX/}

# Replace slashes with hyphens if enabled
if [[ "$INPUTS_REPLACE_SLASHES" == "true" ]]; then
BASE_REF=${BASE_REF//\//-}
HEAD_REF=${HEAD_REF//\//-}
REF_BRANCH=${REF_BRANCH//\//-}
fi

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"
else
BASE_REF=$(printf "%q" "$GITHUB_EVENT_BASE_REF")
BASE_REF=${BASE_REF/refs\/heads\/$INPUTS_STRIP_TAG_PREFIX/}

# Replace slashes with hyphens if enabled
if [[ "$INPUTS_REPLACE_SLASHES" == "true" ]]; then
BASE_REF=${BASE_REF//\//-}
fi

echo "base_ref_branch=$(eval printf "%s" "$BASE_REF")" >> "$GITHUB_OUTPUT"
fi
shell: bash
Expand Down Expand Up @@ -112,12 +129,18 @@ runs:
env:
GITHUB_REF: ${{ github.ref }}
INPUTS_STRIP_TAG_PREFIX: ${{ inputs.strip_tag_prefix }}
INPUTS_REPLACE_SLASHES: ${{ inputs.replace_slashes_with_hyphens }}
run: |
# "Set the tag name..."
if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then
REF=$(printf "%q" "$GITHUB_REF")
TAG="${REF/refs\/tags\/$INPUTS_STRIP_TAG_PREFIX/}"

# Replace slashes with hyphens if enabled
if [[ "$INPUTS_REPLACE_SLASHES" == "true" ]]; then
TAG=${TAG//\//-}
fi

echo "tag=$(eval printf "%s" "$TAG")" >> "$GITHUB_OUTPUT"
echo "is_tag=true" >> "$GITHUB_OUTPUT"
else
Expand Down