2020-12-11 23:23:15 +08:00
|
|
|
name: branch-names
|
2021-01-07 14:49:58 +08:00
|
|
|
description: Retrieve giithub branch information without `/ref/*` prefix
|
2020-12-11 21:15:40 +08:00
|
|
|
author: tj-actions
|
|
|
|
inputs:
|
2020-12-11 21:33:11 +08:00
|
|
|
base_ref:
|
|
|
|
description: 'The target branch of a pull request'
|
|
|
|
default: ${{ github.base_ref }}
|
|
|
|
required: false
|
|
|
|
head_ref:
|
|
|
|
description: 'The source branch of a pull request'
|
|
|
|
default: ${{ github.head_ref }}
|
|
|
|
required: false
|
|
|
|
ref:
|
|
|
|
description: 'The branch that triggered the workflow run.'
|
|
|
|
default: ${{ github.ref }}
|
|
|
|
required: false
|
2021-04-25 08:07:39 +08:00
|
|
|
strip_tag_prefix:
|
|
|
|
description: 'The tag prefix to strip i.e v0.0.1 -> (strip v) -> 0.0.1'
|
|
|
|
default: ''
|
|
|
|
required: false
|
2020-12-11 21:23:56 +08:00
|
|
|
|
2020-12-11 21:15:40 +08:00
|
|
|
outputs:
|
2021-02-13 05:30:56 +08:00
|
|
|
is_default:
|
2021-02-13 05:33:03 +08:00
|
|
|
value: ${{ steps.default.outputs.is_default }}
|
2021-02-13 05:30:56 +08:00
|
|
|
description: 'Returns "true" if the current branch is the default else "false".'
|
2021-02-08 08:30:56 +08:00
|
|
|
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).'
|
2020-12-11 21:15:40 +08:00
|
|
|
base_ref_branch:
|
2020-12-11 21:41:21 +08:00
|
|
|
value: ${{ steps.branch.outputs.base_ref_branch }}
|
2020-12-11 21:15:40 +08:00
|
|
|
description: 'The target branch of a pull request'
|
|
|
|
head_ref_branch:
|
2020-12-11 21:41:21 +08:00
|
|
|
value: ${{ steps.branch.outputs.head_ref_branch }}
|
2020-12-11 21:15:40 +08:00
|
|
|
description: 'The source branch of a pull request'
|
|
|
|
ref_branch:
|
2020-12-11 21:41:21 +08:00
|
|
|
value: ${{ steps.branch.outputs.ref_branch }}
|
2020-12-11 21:15:40 +08:00
|
|
|
description: 'The branch that triggered the workflow run.'
|
2021-04-24 18:35:28 +08:00
|
|
|
tag:
|
2021-04-24 18:50:42 +08:00
|
|
|
value: ${{ steps.tag.outputs.tag }}
|
2021-04-24 18:35:28 +08:00
|
|
|
description: 'The tag that triggered the workflow run.'
|
2020-12-11 21:15:40 +08:00
|
|
|
|
|
|
|
runs:
|
2020-12-11 21:41:21 +08:00
|
|
|
using: "composite"
|
|
|
|
steps:
|
|
|
|
- id: branch
|
|
|
|
run: |
|
2021-04-24 18:35:28 +08:00
|
|
|
if [[ !${{ startsWith(inputs.ref, 'refs/tags/') }} ]]; then
|
|
|
|
export BASE_REF=${{ inputs.base_ref }}
|
|
|
|
export HEAD_REF=${{ inputs.head_ref }}
|
|
|
|
export REF=${{ inputs.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
|
2020-12-11 21:41:21 +08:00
|
|
|
shell: bash
|
2021-02-08 08:30:56 +08:00
|
|
|
- id: current_branch
|
|
|
|
run: |
|
|
|
|
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
|
2021-02-08 08:39:26 +08:00
|
|
|
shell: bash
|
2021-02-13 05:33:03 +08:00
|
|
|
- id: default
|
2021-02-13 05:30:56 +08:00
|
|
|
run: |
|
2021-02-14 11:24:10 +08:00
|
|
|
if [[ "${{ steps.current_branch.outputs.current_branch }}" == "${{ steps.branch.outputs.ref_branch }}" ]]; then
|
|
|
|
echo "::set-output name=is_default::true"
|
2021-02-13 05:30:56 +08:00
|
|
|
else
|
|
|
|
echo "::set-output name=is_default::false"
|
|
|
|
fi
|
2021-04-24 18:35:28 +08:00
|
|
|
shell: bash
|
|
|
|
- id: tag
|
|
|
|
run: |
|
|
|
|
if [[ ${{ startsWith(inputs.ref, 'refs/tags/') }} ]]; then
|
|
|
|
export REF=${{ inputs.ref }}
|
2021-04-25 08:08:35 +08:00
|
|
|
TAG=$(echo "${REF/refs\/tags\//}" | sed "s/${{ inputs.strip_tag_prefix }}//")
|
2021-04-24 18:35:28 +08:00
|
|
|
echo "::set-output name=tag::$TAG"
|
|
|
|
fi
|
|
|
|
shell: bash
|
2021-02-08 08:39:26 +08:00
|
|
|
|
2020-12-11 21:15:40 +08:00
|
|
|
branding:
|
|
|
|
icon: git-branch
|
|
|
|
color: white
|