From 487675b843e203b5c9a92a07f1ed763d046d7283 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 11 Jan 2023 13:58:50 -0700 Subject: [PATCH] fix: bug retrieving diff with custom a base sha (#945) Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com> --- .github/workflows/test.yml | 37 +++++++++++++++++++++++++------------ diff-sha.sh | 4 ++++ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3695c586..bef40065 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -950,18 +950,6 @@ jobs: fi shell: bash - - name: Run changed-files with custom sha - id: changed-files-custom-sha - if: github.event_name == 'pull_request' && github.event.action != 'closed' - uses: ./ - with: - sha: ${{ github.event.pull_request.head.sha }} - - name: Show output - if: github.event.action != 'closed' - run: | - echo '${{ toJSON(steps.changed-files-custom-sha.outputs) }}' - shell: - bash - name: Get branch name id: branch-name uses: tj-actions/branch-names@v6 @@ -984,6 +972,31 @@ jobs: echo '${{ toJSON(steps.changed-files-custom-base-sha.outputs) }}' shell: bash + - name: Run changed-files with custom sha + id: changed-files-custom-sha + if: github.event_name == 'pull_request' && github.event.action != 'closed' + uses: ./ + with: + sha: ${{ github.event.pull_request.head.sha }} + - name: Show output + if: github.event.action != 'closed' + run: | + echo '${{ toJSON(steps.changed-files-custom-sha.outputs) }}' + shell: + bash + - name: Run changed-files with the pull request base sha and head sha + id: changed-files-pull-request-base-sha-head-sha + if: github.event_name == 'pull_request' && github.event.action != 'closed' + uses: ./ + with: + base_sha: ${{ github.event.pull_request.base.sha }} + sha: ${{ github.event.pull_request.head.sha }} + - name: Show output + if: github.event.action != 'closed' + run: | + echo '${{ toJSON(steps.changed-files-pull-request-base-sha-head-sha.outputs) }}' + shell: + bash - name: Run changed-files with specific files (only-changed) id: changed-files-specific-only-changed uses: ./ diff --git a/diff-sha.sh b/diff-sha.sh index 3a3571cb..bdb52699 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -223,6 +223,10 @@ else echo "::debug::Previous SHA: $PREVIOUS_SHA" else PREVIOUS_SHA=$INPUT_BASE_SHA && exit_status=$? || exit_status=$? + + if ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then + DIFF=".." + fi fi echo "::debug::Target branch: $TARGET_BRANCH"