Merge pull request #11 from tj-actions/feature/add-support-for-detecting-the-default-branch

This commit is contained in:
Tonye Jack 2021-02-13 05:41:54 -05:00 committed by GitHub
commit 7f0ba5c8c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -24,6 +24,17 @@ jobs:
echo "Base Ref: ${{ steps.branch-name.outputs.base_ref_branch }}"
echo "Head Ref: ${{ steps.branch-name.outputs.head_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
if: github.event_name == 'pull_request' && !steps.branch-name.outputs.base_ref_branch
run: |

View File

@ -16,6 +16,9 @@ inputs:
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).'
@ -50,6 +53,14 @@ runs:
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.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:
icon: git-branch