mirror of
https://github.com/tj-actions/branch-names.git
synced 2024-11-27 13:33:51 +08:00
68 lines
2.3 KiB
YAML
68 lines
2.3 KiB
YAML
name: branch-names
|
|
description: Retrieve giithub branch information without `/ref/*` prefix
|
|
author: tj-actions
|
|
inputs:
|
|
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
|
|
|
|
outputs:
|
|
is_default:
|
|
value: ${{ steps.default.outputs.is_default }}
|
|
description: 'Returns "true" if the current branch is the default 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.'
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- id: branch
|
|
run: |
|
|
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\//}"
|
|
shell: bash
|
|
- 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
|
|
shell: bash
|
|
- id: default
|
|
run: |
|
|
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
|
|
shell: bash
|
|
|
|
branding:
|
|
icon: git-branch
|
|
color: white
|