diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4cb5c10..b32ac99 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: | diff --git a/action.yml b/action.yml index 335f5c4..388a455 100644 --- a/action.yml +++ b/action.yml @@ -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