From 4144d3a80a172379d33ce413eef9541371f42c1c Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 1 Jan 2023 11:41:39 -0700 Subject: [PATCH 1/9] chore: update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 900efab91d3..6523961ead4 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,7 @@ Support this project with a :star: + ## Examples
From be72f6c1aa22dff8c79aeed8a8f8dfd261a19fab Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 1 Jan 2023 12:42:32 -0700 Subject: [PATCH 2/9] Update diff-sha.sh --- diff-sha.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index f6d337d4992..419a9df7eb7 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -euo pipefail +set -exuo pipefail INITIAL_COMMIT="false" GITHUB_OUTPUT=${GITHUB_OUTPUT:-""} @@ -50,6 +50,7 @@ else echo "Valid git version found: ($GIT_VERSION)" fi +env echo "Base Ref: $GITHUB_BASE_REF" if [[ -z $GITHUB_BASE_REF ]]; then From 73c80f53f08dc7d10fbfda31c5399a898bb960d2 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 1 Jan 2023 20:05:26 -0700 Subject: [PATCH 3/9] Updated env --- diff-sha.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 419a9df7eb7..d034c72e9f1 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -exuo pipefail +set -euo pipefail INITIAL_COMMIT="false" GITHUB_OUTPUT=${GITHUB_OUTPUT:-""} @@ -13,7 +13,7 @@ if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then EXTRA_ARGS="--prune --no-recurse-submodules" fi -if [[ -z $GITHUB_BASE_REF || "$GITHUB_EVENT_HEAD_REPO_FORK" == "true" ]]; then +if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF || "$GITHUB_EVENT_HEAD_REPO_FORK" == "true" ]]; then DIFF=".." fi @@ -50,10 +50,9 @@ else echo "Valid git version found: ($GIT_VERSION)" fi -env -echo "Base Ref: $GITHUB_BASE_REF" +echo "Base Ref: $GITHUB_EVENT_PULL_REQUEST_BASE_REF" -if [[ -z $GITHUB_BASE_REF ]]; then +if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF ]]; then echo "Running on a push event..." TARGET_BRANCH=$GITHUB_REFNAME CURRENT_BRANCH=$TARGET_BRANCH @@ -153,8 +152,8 @@ if [[ -z $GITHUB_BASE_REF ]]; then fi else echo "Running on a pull request event..." - TARGET_BRANCH=$GITHUB_BASE_REF - CURRENT_BRANCH=$GITHUB_HEAD_REF + TARGET_BRANCH=$GITHUB_EVENT_PULL_REQUEST_BASE_REF + CURRENT_BRANCH=$GITHUB_EVENT_PULL_REQUEST_HEAD_REF if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then TARGET_BRANCH=$CURRENT_BRANCH From 790e43b92628148589e80543ff4bbc68a6e2e1a6 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 1 Jan 2023 20:13:43 -0700 Subject: [PATCH 4/9] Updated to enable debug --- diff-sha.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index d034c72e9f1..f3bf15d0919 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -euo pipefail +set -exuo pipefail INITIAL_COMMIT="false" GITHUB_OUTPUT=${GITHUB_OUTPUT:-""} @@ -60,7 +60,7 @@ if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF ]]; then echo "Fetching remote refs..." # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin "$CURRENT_BRANCH" 1>/dev/null 2>&1 + git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin "$CURRENT_BRANCH" 1>/dev/null echo "::debug::Getting HEAD SHA..." if [[ -n "$INPUT_UNTIL" ]]; then @@ -161,7 +161,7 @@ else echo "Fetching remote refs..." # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS -u --progress origin pull/"$GITHUB_EVENT_NUMBER"/head:"$CURRENT_BRANCH" 1>/dev/null 2>&1 + git fetch $EXTRA_ARGS -u --progress origin pull/"$GITHUB_EVENT_NUMBER"/head:"$CURRENT_BRANCH" 1>/dev/null echo "::debug::Getting HEAD SHA..." if [[ -n "$INPUT_UNTIL" ]]; then @@ -201,7 +201,7 @@ else else echo "::debug::Fetching remote target branch..." # shellcheck disable=SC2086 - git fetch -u --progress $EXTRA_ARGS --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" 1>/dev/null 2>&1 + git fetch -u --progress $EXTRA_ARGS --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" 1>/dev/null git branch --track "$TARGET_BRANCH" origin/"$TARGET_BRANCH" 1>/dev/null 2>&1 || true From 15333b92d6042d83b0dbd4af8d15012aa22ab665 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 1 Jan 2023 20:22:58 -0700 Subject: [PATCH 5/9] Updated action --- action.yml | 2 +- diff-sha.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 4758333c6ac..5ef247caa1a 100644 --- a/action.yml +++ b/action.yml @@ -183,8 +183,8 @@ runs: GITHUB_REF: ${{ github.ref }} GITHUB_SHA: ${{ github.sha }} GITHUB_WORKSPACE: ${{ github.workspace }} - GITHUB_EVENT_NUMBER: ${{ github.event.number }} GITHUB_EVENT_HEAD_REPO_FORK: ${{ github.event.pull_request.head.repo.fork }} + GITHUB_EVENT_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} GITHUB_EVENT_PULL_REQUEST_BASE_REF: ${{ github.event.pull_request.base.ref }} GITHUB_EVENT_PULL_REQUEST_HEAD_REF: ${{ github.event.pull_request.head.ref }} GITHUB_EVENT_PULL_REQUEST_BASE_SHA: ${{ github.event.pull_request.base.sha }} diff --git a/diff-sha.sh b/diff-sha.sh index f3bf15d0919..1142eecfb9b 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -161,7 +161,7 @@ else echo "Fetching remote refs..." # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS -u --progress origin pull/"$GITHUB_EVENT_NUMBER"/head:"$CURRENT_BRANCH" 1>/dev/null + git fetch $EXTRA_ARGS -u --progress origin pull/"$GITHUB_EVENT_PULL_REQUEST_NUMBER"/head:"$CURRENT_BRANCH" 1>/dev/null echo "::debug::Getting HEAD SHA..." if [[ -n "$INPUT_UNTIL" ]]; then From 20463ee95e07e18a6c070be2dd277a2aa751f09e Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 1 Jan 2023 20:29:51 -0700 Subject: [PATCH 6/9] Updated test --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f69ea7d7301..d6a44548583 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -953,7 +953,7 @@ jobs: bash - name: Run changed-files with custom sha id: changed-files-custom-sha - if: github.event_name == 'pull_request' && github.event.action != 'closed' + if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.action != 'closed' uses: ./ with: sha: ${{ github.event.pull_request.head.sha }} @@ -966,21 +966,21 @@ jobs: - name: Get branch name id: branch-name uses: tj-actions/branch-names@v6 - if: github.event_name == 'pull_request' && matrix.fetch-depth == 0 + if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && matrix.fetch-depth == 0 - uses: nrwl/nx-set-shas@v3 id: last_successful_commit - if: github.event_name == 'pull_request' && github.event.action != 'closed' && matrix.fetch-depth == 0 + if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.action != 'closed' && matrix.fetch-depth == 0 with: main-branch-name: ${{ steps.branch-name.outputs.base_ref_branch }} workflow-id: 'test.yml' - name: Run changed-files with a custom base sha - if: github.event_name == 'pull_request' && github.event.action != 'closed' && matrix.fetch-depth == 0 + if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.action != 'closed' && matrix.fetch-depth == 0 id: changed-files-custom-base-sha uses: ./ with: base_sha: ${{ steps.last_successful_commit.outputs.base }} - name: Show output - if: github.event_name == 'pull_request' && github.event.action != 'closed' && matrix.fetch-depth == 0 + if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.action != 'closed' && matrix.fetch-depth == 0 run: | echo '${{ toJSON(steps.changed-files-custom-base-sha.outputs) }}' shell: From 7762a170a3a599e8f8248f307a5963050bbffedb Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 1 Jan 2023 20:30:23 -0700 Subject: [PATCH 7/9] Updated action --- diff-sha.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index 1142eecfb9b..92c84612134 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -exuo pipefail +set -euo pipefail INITIAL_COMMIT="false" GITHUB_OUTPUT=${GITHUB_OUTPUT:-""} From d8e28a38640bb9b6d43d11fc78913d0cbb289d16 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 1 Jan 2023 20:31:03 -0700 Subject: [PATCH 8/9] Update diff-sha.sh --- diff-sha.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 92c84612134..2345d067d4a 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -50,8 +50,6 @@ else echo "Valid git version found: ($GIT_VERSION)" fi -echo "Base Ref: $GITHUB_EVENT_PULL_REQUEST_BASE_REF" - if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF ]]; then echo "Running on a push event..." TARGET_BRANCH=$GITHUB_REFNAME From c351eca277be0bbbdf827f696208b6554799d346 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 1 Jan 2023 21:23:41 -0700 Subject: [PATCH 9/9] Fixed test --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d6a44548583..f69ea7d7301 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -953,7 +953,7 @@ jobs: bash - name: Run changed-files with custom sha id: changed-files-custom-sha - if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.action != 'closed' + if: github.event_name == 'pull_request' && github.event.action != 'closed' uses: ./ with: sha: ${{ github.event.pull_request.head.sha }} @@ -966,21 +966,21 @@ jobs: - name: Get branch name id: branch-name uses: tj-actions/branch-names@v6 - if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && matrix.fetch-depth == 0 + if: github.event_name == 'pull_request' && matrix.fetch-depth == 0 - uses: nrwl/nx-set-shas@v3 id: last_successful_commit - if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.action != 'closed' && matrix.fetch-depth == 0 + if: github.event_name == 'pull_request' && github.event.action != 'closed' && matrix.fetch-depth == 0 with: main-branch-name: ${{ steps.branch-name.outputs.base_ref_branch }} workflow-id: 'test.yml' - name: Run changed-files with a custom base sha - if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.action != 'closed' && matrix.fetch-depth == 0 + if: github.event_name == 'pull_request' && github.event.action != 'closed' && matrix.fetch-depth == 0 id: changed-files-custom-base-sha uses: ./ with: base_sha: ${{ steps.last_successful_commit.outputs.base }} - name: Show output - if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.action != 'closed' && matrix.fetch-depth == 0 + if: github.event_name == 'pull_request' && github.event.action != 'closed' && matrix.fetch-depth == 0 run: | echo '${{ toJSON(steps.changed-files-custom-base-sha.outputs) }}' shell: