mirror of
https://github.com/tj-actions/branch-names.git
synced 2024-12-27 14:27:59 +08:00
Merge pull request #11 from tj-actions/feature/add-support-for-detecting-the-default-branch
This commit is contained in:
commit
7f0ba5c8c3
11
.github/workflows/test.yml
vendored
11
.github/workflows/test.yml
vendored
@ -24,6 +24,17 @@ jobs:
|
|||||||
echo "Base Ref: ${{ steps.branch-name.outputs.base_ref_branch }}"
|
echo "Base Ref: ${{ steps.branch-name.outputs.base_ref_branch }}"
|
||||||
echo "Head Ref: ${{ steps.branch-name.outputs.head_ref_branch }}"
|
echo "Head Ref: ${{ steps.branch-name.outputs.head_ref_branch }}"
|
||||||
echo "Ref: ${{ steps.branch-name.outputs.ref_branch }}"
|
echo "Ref: ${{ steps.branch-name.outputs.ref_branch }}"
|
||||||
|
echo "Is Default: ${{ steps.branch-name.outputs.is_default }}"
|
||||||
|
- name: Check is_default for pull request
|
||||||
|
if: github.event_name == 'pull_request' && steps.branch-name.outputs.is_default != 'false'
|
||||||
|
run: |
|
||||||
|
echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}"
|
||||||
|
exit 1
|
||||||
|
- name: Check is_default for non pull request
|
||||||
|
if: github.event_name != 'pull_request' && steps.branch-name.outputs.is_default != 'true'
|
||||||
|
run: |
|
||||||
|
echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}"
|
||||||
|
exit 1
|
||||||
- name: Test base ref output
|
- name: Test base ref output
|
||||||
if: github.event_name == 'pull_request' && !steps.branch-name.outputs.base_ref_branch
|
if: github.event_name == 'pull_request' && !steps.branch-name.outputs.base_ref_branch
|
||||||
run: |
|
run: |
|
||||||
|
11
action.yml
11
action.yml
@ -16,6 +16,9 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
|
is_default:
|
||||||
|
value: ${{ steps.default.outputs.is_default }}
|
||||||
|
description: 'Returns "true" if the current branch is the default else "false".'
|
||||||
current_branch:
|
current_branch:
|
||||||
value: ${{ steps.current_branch.outputs.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).'
|
description: 'Returns the value of the current branch which is consistent regardless of event_type: i.e (push, pull_requests).'
|
||||||
@ -50,6 +53,14 @@ runs:
|
|||||||
echo "::set-output name=current_branch::${{ steps.branch.outputs.ref_branch }}"
|
echo "::set-output name=current_branch::${{ steps.branch.outputs.ref_branch }}"
|
||||||
fi
|
fi
|
||||||
shell: bash
|
shell: bash
|
||||||
|
- id: default
|
||||||
|
run: |
|
||||||
|
if [[ "${{ steps.current_branch.outputs.current_branch }}" == "${{ steps.current_branch.outputs.base_ref_branch }}" ]]; then
|
||||||
|
echo "::set-output name=is_default::true"
|
||||||
|
else
|
||||||
|
echo "::set-output name=is_default::false"
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|
||||||
branding:
|
branding:
|
||||||
icon: git-branch
|
icon: git-branch
|
||||||
|
Loading…
x
Reference in New Issue
Block a user