branch-names/action.yml
2021-08-04 15:17:49 -04:00

87 lines
3.1 KiB
YAML

name: Branch Names
description: Retrieve giithub branch or tag information without the /ref/* prefix
author: tj-actions
inputs:
strip_tag_prefix:
description: 'The tag prefix to strip i.e v0.0.1 -> (strip v) -> 0.0.1'
default: ''
required: false
outputs:
is_default:
value: ${{ steps.default.outputs.is_default }}
description: 'Returns "true" if the current branch is the default else "false".'
is_tag:
value: ${{ steps.tag.outputs.is_tag }}
description: 'Returns "true" if the current branch is a tag else "false".'
current_branch:
value: ${{ steps.current_branch.outputs.current_branch }}
description: 'Returns the value of the current branch which is consistent regardless of event_type: i.e (push, pull_requests).'
base_ref_branch:
value: ${{ steps.branch.outputs.base_ref_branch }}
description: 'The target branch of a pull request'
head_ref_branch:
value: ${{ steps.branch.outputs.head_ref_branch }}
description: 'The source branch of a pull request'
ref_branch:
value: ${{ steps.branch.outputs.ref_branch }}
description: 'The branch that triggered the workflow run.'
tag:
value: ${{ steps.tag.outputs.tag }}
description: 'The tag that triggered the workflow run.'
runs:
using: "composite"
steps:
- id: branch
run: |
if [[ "${{ github.ref }}" != "refs/tags/"* ]]; then
BASE_REF=${{ github.base_ref }}
HEAD_REF=${{ github.head_ref }}
REF=${{ github.ref }}
echo "::set-output name=base_ref_branch::${BASE_REF/refs\/heads\//}"
echo "::set-output name=head_ref_branch::${HEAD_REF/refs\/heads\//}"
REF_BRANCH=${REF/refs\/pull\//}
echo "::set-output name=ref_branch::${REF_BRANCH/refs\/heads\//}"
fi
shell: bash
- id: current_branch
run: |
if [[ "${{ github.ref }}" != "refs/tags/"* ]]; then
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
echo "::set-output name=current_branch::${{ steps.branch.outputs.head_ref_branch }}"
else
echo "::set-output name=current_branch::${{ steps.branch.outputs.ref_branch }}"
fi
else
REF=${{ github.ref }}
REF_BRANCH=${REF/refs\/tags\//}
echo "::set-output name=current_branch::$REF_BRANCH"
fi
shell: bash
- id: default
run: |
if [[ "${{ github.ref }}" != "refs/tags/"* ]]; then
if [[ "${{ steps.current_branch.outputs.current_branch }}" == "${{ steps.branch.outputs.ref_branch }}" ]]; then
echo "::set-output name=is_default::true"
else
echo "::set-output name=is_default::false"
fi
fi
shell: bash
- id: tag
run: |
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
REF=${{ github.ref }}
TAG=${REF/refs\/tags\/${{ inputs.strip_tag_prefix }}/}
echo "::set-output name=tag::$TAG"
echo "::set-output name=is_tag::true"
else
echo "::set-output name=is_tag::false"
fi
shell: bash
branding:
icon: git-branch
color: white