From dc88c3a0c5acd72b43e1c54afcf1ad51bbf82930 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 6 Nov 2022 22:31:54 -0700 Subject: [PATCH 1/4] chore: exclude fetching tags --- diff-sha.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index f617f05d..777b4f41 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -143,13 +143,13 @@ else echo "Fetching remote refs..." if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "false" ]]; then - git fetch --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" + git fetch --no-tags --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" git branch --track "$TARGET_BRANCH" origin/"$TARGET_BRANCH" 2>/dev/null || true depth=$INPUT_FETCH_DEPTH while [ -z "$( git merge-base "$TARGET_BRANCH" HEAD )" ]; do - git fetch --deepen="$depth" origin "$TARGET_BRANCH" HEAD; + git fetch --no-tags --deepen="$depth" origin "$TARGET_BRANCH" HEAD; depth=$((depth * 10)) max_depth=5000 From 321490c60a28d2f37d2bf276ac839fb6bf69c013 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 6 Nov 2022 22:53:53 -0700 Subject: [PATCH 2/4] Update diff-sha.sh --- diff-sha.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/diff-sha.sh b/diff-sha.sh index 777b4f41..53c1760c 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -155,6 +155,7 @@ else if [[ $depth -gt $max_depth ]]; then echo "::error::Unable to find merge-base between $TARGET_BRANCH and HEAD." + exit 1 fi done fi From c46761fdcdf33808fb554e300c8b0a3c87204fd9 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 6 Nov 2022 23:28:15 -0700 Subject: [PATCH 3/4] Update diff-sha.sh --- diff-sha.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 53c1760c..7f2d56c9 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -4,6 +4,11 @@ set -euo pipefail INITIAL_COMMIT="false" GITHUB_OUTPUT=${GITHUB_OUTPUT:-""} +EXTRA_ARGS="--no-tags" + +if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then + EXTRA_ARGS="" +fi echo "::group::changed-files-diff-sha" @@ -56,7 +61,8 @@ 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 - git fetch --no-tags -u --progress --deepen="$INPUT_FETCH_DEPTH" + # shellcheck disable=SC2086 + git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" CURRENT_SHA=$INPUT_SHA; exit_status=$? fi fi @@ -118,7 +124,8 @@ if [[ -z $GITHUB_BASE_REF ]]; then fi fi else - git fetch --no-tags -u --progress --deepen="$INPUT_FETCH_DEPTH" + # shellcheck disable=SC2086 + git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" PREVIOUS_SHA=$INPUT_BASE_SHA TARGET_BRANCH=$(git name-rev --name-only "$PREVIOUS_SHA" 2>&1) && exit_status=$? || exit_status=$? CURRENT_BRANCH=$TARGET_BRANCH @@ -143,13 +150,15 @@ else echo "Fetching remote refs..." if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "false" ]]; then - git fetch --no-tags --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" + # shellcheck disable=SC2086 + git fetch $EXTRA_ARGS --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" git branch --track "$TARGET_BRANCH" origin/"$TARGET_BRANCH" 2>/dev/null || true depth=$INPUT_FETCH_DEPTH while [ -z "$( git merge-base "$TARGET_BRANCH" HEAD )" ]; do - git fetch --no-tags --deepen="$depth" origin "$TARGET_BRANCH" HEAD; + # shellcheck disable=SC2086 + git fetch $EXTRA_ARGS --deepen="$depth" origin "$TARGET_BRANCH" HEAD; depth=$((depth * 10)) max_depth=5000 From 2d251d69240ca53fa3e75ebbcc956ba54a8751f8 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 6 Nov 2022 23:49:17 -0700 Subject: [PATCH 4/4] 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 7f2d56c9..56a16e0d 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -206,10 +206,10 @@ else fi if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "0000000000000000000000000000000000000000" ]]; then - PREVIOUS_SHA=$(git rev-list --no-merges -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$(git rev-list -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? fi else - PREVIOUS_SHA=$(git rev-list --no-merges -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$(git rev-list -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? fi if [[ -z "$PREVIOUS_SHA" ]]; then