From 26eb884112f14e3b12c0e59650f6bd88ad8efb4f Mon Sep 17 00:00:00 2001 From: "Jason C. Leach" Date: Fri, 25 Oct 2024 08:01:31 -0700 Subject: [PATCH] fix: pipe logic Signed-off-by: Jason C. Leach --- .../actions/early-exit-check/action.yml | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/actions/early-exit-check/action.yml b/.github/workflows/actions/early-exit-check/action.yml index ffc4c4b8a..ba09161f0 100644 --- a/.github/workflows/actions/early-exit-check/action.yml +++ b/.github/workflows/actions/early-exit-check/action.yml @@ -9,19 +9,30 @@ runs: - name: Check location of changed files shell: bash run: | - # On main branch, compare with the previous - # commit otherwise (for PRs) compare with the - # current commit. - if [ "${GITHUB_REF_NAME}" = "main" ]; then - end_ref="HEAD^" + set -x + + if [ "${GITHUB_REF_NAME}" = "main" ]; then + # On main branch, compare with the previous + # commit otherwise (for PRs) compare with the + # current commit. + parent_ref="${GITHUB_REF_NAME}^" + child_ref="${GITHUB_SHA}" else - end_ref="HEAD" + # On PRs, compare with the base branch. + parent_ref="origin/${GITHUB_BASE_REF:-main}" + child_ref="HEAD" fi - echo "Comparing origin/${GITHUB_BASE_REF:-HEAD} with ${end_ref}" + echo "Comparing ${parent_ref} with ${child_ref}" - change_count=$(git diff --name-only origin/${GITHUB_BASE_REF:-HEAD}..${end_ref} | grep -E '^(app/.*)|(.yarn/.*)|(.github/workflows/.*)' | wc -l | awk '{$1=$1};1') + change_count=$( + git diff --name-only $parent_ref..$child_ref | \ + grep -E '^(app/.*)|(.yarn/.*)|(.github/workflows/.*)' || true | \ + wc -l | \ + awk '{$1=$1};1' + ) echo "$change_count files changed in app, .yarn, or .github/workflows" + if [ $change_count -gt 0 ]; then # A result greater than 0 means there are changes # in the specified directories.