From ac602e39b8a72fa29a7116348af7812981e5b4b0 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 9 Dec 2022 23:49:27 -0700 Subject: [PATCH 1/8] fix: error verifying the previous commit sha for push event --- diff-sha.sh | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index b6c5e9a5..7e2c0523 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -7,16 +7,11 @@ GITHUB_OUTPUT=${GITHUB_OUTPUT:-""} EXTRA_ARGS="--no-tags" PREVIOUS_SHA="" CURRENT_SHA="" -MERGE_BASE_EXRTRA_ARGS="" if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then EXTRA_ARGS="" fi -if [[ "$GITHUB_EVENT_HEAD_REPO_FORK" == "true" ]]; then - MERGE_BASE_EXRTRA_ARGS="--fork-point" -fi - echo "::group::changed-files-diff-sha" if [[ -n $INPUT_PATH ]]; then @@ -68,9 +63,9 @@ if [[ -z $GITHUB_BASE_REF ]]; then if [[ -z $INPUT_SHA ]]; then CURRENT_SHA=$(git rev-list -n 1 HEAD 2>&1) && exit_status=$? || exit_status=$? else - CURRENT_SHA=$INPUT_SHA; exit_status=$? # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" 2>&1 && exit_status=$? || exit_status=$? + git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" + CURRENT_SHA=$INPUT_SHA; exit_status=$? fi fi @@ -131,9 +126,9 @@ if [[ -z $GITHUB_BASE_REF ]]; then fi fi else - PREVIOUS_SHA=$INPUT_BASE_SHA # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" 2>&1 && exit_status=$? || exit_status=$? + git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" + PREVIOUS_SHA=$INPUT_BASE_SHA fi echo "::debug::Target branch $TARGET_BRANCH..." @@ -204,7 +199,7 @@ else PREVIOUS_SHA=$(git rev-parse origin/"$CURRENT_BRANCH" 2>&1) && exit_status=$? || exit_status=$? fi else - PREVIOUS_SHA=$(git merge-base $MERGE_BASE_EXRTRA_ARGS "$TARGET_BRANCH" "$CURRENT_SHA" 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$(git merge-base "$TARGET_BRANCH" "$CURRENT_SHA" 2>&1) && exit_status=$? || exit_status=$? if [[ -z "$PREVIOUS_SHA" ]]; then PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$? @@ -230,7 +225,7 @@ else # shellcheck disable=SC2086 git fetch $EXTRA_ARGS -u --progress --deepen="$depth" origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" - PREVIOUS_SHA=$(git merge-base $MERGE_BASE_EXRTRA_ARGS "$TARGET_BRANCH" "$CURRENT_SHA" 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$(git merge-base "$TARGET_BRANCH" "$CURRENT_SHA" 2>&1) && exit_status=$? || exit_status=$? if [[ $depth -gt $max_depth ]]; then echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and $CURRENT_SHA" From fbc9b6157950183b3ff74a8f7c03253e85811583 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 9 Dec 2022 23:51:25 -0700 Subject: [PATCH 2/8] Update action.yml --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 31330112..242cab1c 100644 --- a/action.yml +++ b/action.yml @@ -212,6 +212,7 @@ runs: env: GITHUB_WORKSPACE: ${{ github.workspace }} GITHUB_BASE_REF: ${{ github.base_ref }} + GITHUB_EVENT_HEAD_REPO_FORK: ${{ github.event.pull_request.head.repo.fork }} # INPUT_ is not available in Composite run steps # https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs INPUT_FILES_PATTERN_FILE: ${{ steps.glob.outputs.paths-output-file }} From 0707f1b441110837b3801803ddb721c10a0d505f Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 9 Dec 2022 23:52:38 -0700 Subject: [PATCH 3/8] Update diff-sha.sh --- diff-sha.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index 7e2c0523..5dcdc39e 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -7,11 +7,16 @@ GITHUB_OUTPUT=${GITHUB_OUTPUT:-""} EXTRA_ARGS="--no-tags" PREVIOUS_SHA="" CURRENT_SHA="" +DIFF="..." if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then EXTRA_ARGS="" fi +if [[ "$GITHUB_EVENT_HEAD_REPO_FORK" == "true" ]]; then + DIFF=".." +fi + echo "::group::changed-files-diff-sha" if [[ -n $INPUT_PATH ]]; then @@ -205,7 +210,7 @@ else PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$? fi - if ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA"..."$CURRENT_SHA" 1>/dev/null 2>&1; then + if ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then PREVIOUS_SHA=$(git rev-parse origin/"$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? fi fi From 3f045143ec012b543a8580ec75b582a18adecbf3 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 9 Dec 2022 23:53:21 -0700 Subject: [PATCH 4/8] Update get-changed-paths.sh --- get-changed-paths.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get-changed-paths.sh b/get-changed-paths.sh index 746737ca..efe967e7 100755 --- a/get-changed-paths.sh +++ b/get-changed-paths.sh @@ -10,7 +10,7 @@ INPUT_SEPARATOR="${INPUT_SEPARATOR//$'\r'/'%0D'}" GITHUB_OUTPUT=${GITHUB_OUTPUT:-""} DIFF="..." -if [[ -z $GITHUB_BASE_REF ]]; then +if [[ -z $GITHUB_BASE_REF || "$GITHUB_EVENT_HEAD_REPO_FORK" == "true" ]]; then DIFF=".." fi From ae2404f72ef265a9947c91543d6079436c40e661 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 9 Dec 2022 23:58:40 -0700 Subject: [PATCH 5/8] Update diff-sha.sh --- diff-sha.sh | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 5dcdc39e..0feaaa68 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -193,7 +193,6 @@ else exit 1 else echo "::debug::Current SHA: $CURRENT_SHA" - fi if [[ -z $INPUT_BASE_SHA ]]; then if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then @@ -204,14 +203,10 @@ else PREVIOUS_SHA=$(git rev-parse origin/"$CURRENT_BRANCH" 2>&1) && exit_status=$? || exit_status=$? fi else - PREVIOUS_SHA=$(git merge-base "$TARGET_BRANCH" "$CURRENT_SHA" 2>&1) && exit_status=$? || exit_status=$? - - if [[ -z "$PREVIOUS_SHA" ]]; then - PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$? - fi + PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA if ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then - PREVIOUS_SHA=$(git rev-parse origin/"$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$(git merge-base "$PREVIOUS_SHA" "$CURRENT_SHA" 2>&1) && exit_status=$? || exit_status=$? fi fi @@ -224,7 +219,7 @@ else depth=$INPUT_FETCH_DEPTH max_depth=$INPUT_MAX_FETCH_DEPTH - while ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA"..."$CURRENT_SHA" 1>/dev/null 2>&1; do + while ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; do echo "Fetching $depth commits..." # shellcheck disable=SC2086 From 33eef1b0ed914f694e828972d7c306574b454e07 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 10 Dec 2022 00:05:52 -0700 Subject: [PATCH 6/8] Update diff-sha.sh --- diff-sha.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/diff-sha.sh b/diff-sha.sh index 0feaaa68..df63a4ac 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -193,6 +193,7 @@ else exit 1 else echo "::debug::Current SHA: $CURRENT_SHA" + fi if [[ -z $INPUT_BASE_SHA ]]; then if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then From a4f296d02e565fe68741b2a64e8b16d6c2e027c3 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 10 Dec 2022 00:21:14 -0700 Subject: [PATCH 7/8] Update diff-sha.sh --- diff-sha.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index df63a4ac..599ef9da 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -69,7 +69,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then CURRENT_SHA=$(git rev-list -n 1 HEAD 2>&1) && exit_status=$? || exit_status=$? else # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" + git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin "$CURRENT_BRANCH" CURRENT_SHA=$INPUT_SHA; exit_status=$? fi fi @@ -132,7 +132,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then fi else # shellcheck disable=SC2086 - git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" + git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin "$CURRENT_BRANCH" PREVIOUS_SHA=$INPUT_BASE_SHA fi From a84c8f54f9312e43db81350c8282e6404934e0cd Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 10 Dec 2022 00:30:40 -0700 Subject: [PATCH 8/8] Update diff-sha.sh --- diff-sha.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 599ef9da..3bda566e 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -220,7 +220,7 @@ else depth=$INPUT_FETCH_DEPTH max_depth=$INPUT_MAX_FETCH_DEPTH - while ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; do + for ((i=0; i&1) && exit_status=$? || exit_status=$? - if [[ $depth -gt $max_depth ]]; then - echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and $CURRENT_SHA" - exit 1 + if git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then + break fi - - depth=$((depth + 300)) done + + if ((i >= max_depth)); then + echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and $CURRENT_SHA" + exit 1 + fi else echo "::debug::Not a shallow clone, skipping merge-base check." fi