From 39b955e7b16a71ebf3f17baf63e97301a6aafa80 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 7 Feb 2021 19:30:56 -0500 Subject: [PATCH 1/5] Update action.yml --- action.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/action.yml b/action.yml index e86c37d..309b82e 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,9 @@ inputs: required: false 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).' base_ref_branch: value: ${{ steps.branch.outputs.base_ref_branch }} description: 'The target branch of a pull request' @@ -43,6 +46,13 @@ runs: 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 branding: icon: git-branch color: white From a3164f525996a4814aa494e72cb106024d49acf5 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 7 Feb 2021 19:34:33 -0500 Subject: [PATCH 2/5] Update test.yml --- .github/workflows/test.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 55fca25..b8dde6e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,3 +38,14 @@ jobs: run: | echo "Ref unset: ${{ steps.branch-name.outputs.ref_branch }}" exit 1 + - name: Test current branch output for pull_request event. + if: github.event_name == 'pull_request' && !steps.branch-name.outputs.current_branch + run: | + echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}" + exit 1 + - name: Test current branch output for push event. + if: github.event_name == 'push' && !steps.branch-name.outputs.current_branch + run: | + echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}" + exit 1 + From 947917ad6ae3bd687efce550749a5a4265330bb6 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 7 Feb 2021 19:39:26 -0500 Subject: [PATCH 3/5] Update action.yml --- action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yml b/action.yml index 309b82e..ac4a44d 100644 --- a/action.yml +++ b/action.yml @@ -53,6 +53,8 @@ runs: else echo "::set-output name=current_branch::${{ steps.branch.outputs.ref_branch }}" fi + shell: bash + branding: icon: git-branch color: white From 796c67a499adcc6546e77274655146b07be7aa2b Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 7 Feb 2021 19:41:26 -0500 Subject: [PATCH 4/5] Update test.yml --- .github/workflows/test.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b8dde6e..4cb5c10 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,9 +20,10 @@ jobs: uses: ./ - name: Show output run: | - echo "${{ steps.branch-name.outputs.base_ref_branch }}" - echo "${{ steps.branch-name.outputs.head_ref_branch }}" - echo "${{ steps.branch-name.outputs.ref_branch }}" + echo "Current Branch: ${{ steps.branch-name.outputs.current_branch }}" + 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 }}" - name: Test base ref output if: github.event_name == 'pull_request' && !steps.branch-name.outputs.base_ref_branch run: | From bd09bab9c37f6afa9fda27ed710384c83101bcfe Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 7 Feb 2021 19:45:09 -0500 Subject: [PATCH 5/5] Update README.md --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 8782583..fee62d8 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,19 @@ Get branch information without the `/ref/*` prefix - name: Get branch names uses: tj-actions/branch-names@v2 id: branch-names + + - name: Current branch name + if: github.event_name == 'pull_request' + run: | + echo "${{ steps.branch-name.outputs.current_branch }}" + # Outputs: "feature/test" current PR branch. + + - name: Current branch name + if: github.event_name == 'push' + run: | + echo "${{ steps.branch-name.outputs.current_branch }}" + # Outputs: "main" the current branch that triggered the action. + - name: Get Ref brach name run: | echo "${{ steps.branch-name.outputs.ref_branch }}" @@ -28,6 +41,7 @@ Get branch information without the `/ref/*` prefix run: | echo "${{ steps.branch-name.outputs.base_ref_branch }}" # Outputs: "main" for main <- PR branch. + ``` @@ -65,6 +79,7 @@ on: | Output | type | Example | Description | |:--------------------:|:-----------:|:---------------------:|:------------------------------------------------:| +| current_branch | `string` | `main` | Always returns the branch that triggered the workflow run. | | base_ref_branch | `string` | `main` | The target branch of a pull request | | head_ref_branch | `string` | `feature/test` | The source branch of a pull request | | ref_branch | `string` | `1/merge` OR `main` | The branch that triggered the workflow run |