From bfe077bfb660393b4ca22f6b52d43ed55999b9d5 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 3 Nov 2022 12:29:02 -0600 Subject: [PATCH] Updated diff-sha.sh --- diff-sha.sh | 87 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 29 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 0f953c85..a99be2a1 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -38,40 +38,40 @@ else echo "Valid git version found: ($GIT_VERSION)" fi -echo "::debug::Getting HEAD SHA..." - -if [[ -n "$INPUT_UNTIL" ]]; then - echo "::debug::Getting HEAD SHA for '$INPUT_UNTIL'..." - CURRENT_SHA=$(git log -1 --format="%H" --date=local --until="$INPUT_UNTIL") && exit_status=$? || exit_status=$? - - if [[ $exit_status -ne 0 ]]; then - echo "::error::Invalid until date: $INPUT_UNTIL" - exit 1 - fi -else - if [[ -z $INPUT_SHA ]]; then - CURRENT_SHA=$(git rev-list --no-merges -n 1 HEAD 2>&1) && exit_status=$? || exit_status=$? - else - CURRENT_SHA=$INPUT_SHA; exit_status=$? - fi -fi - -echo "::debug::Verifying the current commit SHA: $CURRENT_SHA" -git rev-parse --quiet --verify "$CURRENT_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$? - -if [[ $exit_status -ne 0 ]]; then - echo "::error::Unable to locate the current sha: $CURRENT_SHA" - echo "::error::Please verify that current sha is valid, and increase the fetch_depth to a number higher than $INPUT_FETCH_DEPTH." - exit 1 -else - echo "::debug::Current SHA: $CURRENT_SHA" -fi - if [[ -z $GITHUB_BASE_REF ]]; then echo "Running on a push event..." TARGET_BRANCH=${GITHUB_REF/refs\/heads\//} && exit_status=$? || exit_status=$? CURRENT_BRANCH=$TARGET_BRANCH && exit_status=$? || exit_status=$? + echo "::debug::Getting HEAD SHA..." + if [[ -n "$INPUT_UNTIL" ]]; then + echo "::debug::Getting HEAD SHA for '$INPUT_UNTIL'..." + CURRENT_SHA=$(git log -1 --format="%H" --date=local --until="$INPUT_UNTIL") && exit_status=$? || exit_status=$? + + if [[ $exit_status -ne 0 ]]; then + echo "::error::Invalid until date: $INPUT_UNTIL" + exit 1 + fi + else + git fetch --no-tags -u --progress --depth="$INPUT_FETCH_DEPTH" origin "$TARGET_BRANCH":"$TARGET_BRANCH" + if [[ -z $INPUT_SHA ]]; then + CURRENT_SHA=$(git rev-list --no-merges -n 1 HEAD 2>&1) && exit_status=$? || exit_status=$? + else + CURRENT_SHA=$INPUT_SHA; exit_status=$? + fi + fi + + echo "::debug::Verifying the current commit SHA: $CURRENT_SHA" + git rev-parse --quiet --verify "$CURRENT_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$? + + if [[ $exit_status -ne 0 ]]; then + echo "::error::Unable to locate the current sha: $CURRENT_SHA" + echo "::error::Please verify that current sha is valid, and increase the fetch_depth to a number higher than $INPUT_FETCH_DEPTH." + exit 1 + else + echo "::debug::Current SHA: $CURRENT_SHA" + fi + if [[ -z $INPUT_BASE_SHA ]]; then if [[ -n "$INPUT_SINCE" ]]; then echo "::debug::Getting base SHA for '$INPUT_SINCE'..." @@ -133,9 +133,38 @@ else TARGET_BRANCH=$GITHUB_BASE_REF CURRENT_BRANCH=$GITHUB_HEAD_REF + echo "Fetching remote refs..." git fetch --no-tags -u --progress --deepen=40000 git fetch --no-tags -u --progress --depth="$INPUT_FETCH_DEPTH" origin "$TARGET_BRANCH":"$TARGET_BRANCH" + echo "::debug::Getting HEAD SHA..." + if [[ -n "$INPUT_UNTIL" ]]; then + echo "::debug::Getting HEAD SHA for '$INPUT_UNTIL'..." + CURRENT_SHA=$(git log -1 --format="%H" --date=local --until="$INPUT_UNTIL") && exit_status=$? || exit_status=$? + + if [[ $exit_status -ne 0 ]]; then + echo "::error::Invalid until date: $INPUT_UNTIL" + exit 1 + fi + else + if [[ -z $INPUT_SHA ]]; then + CURRENT_SHA=$(git rev-list --no-merges -n 1 HEAD 2>&1) && exit_status=$? || exit_status=$? + else + CURRENT_SHA=$INPUT_SHA; exit_status=$? + fi + fi + + echo "::debug::Verifying the current commit SHA: $CURRENT_SHA" + git rev-parse --quiet --verify "$CURRENT_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$? + + if [[ $exit_status -ne 0 ]]; then + echo "::error::Unable to locate the current sha: $CURRENT_SHA" + echo "::error::Please verify that current sha is valid, and increase the fetch_depth to a number higher than $INPUT_FETCH_DEPTH." + exit 1 + else + echo "::debug::Current SHA: $CURRENT_SHA" + fi + if [[ -z $INPUT_BASE_SHA ]]; then PREVIOUS_SHA=$(git rev-list --no-merges -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$? if [[ -z "$PREVIOUS_SHA" ]]; then