diff --git a/action.yml b/action.yml index b1824a0f..47f6744c 100644 --- a/action.yml +++ b/action.yml @@ -189,6 +189,7 @@ runs: GITHUB_HEAD_REF: ${{ github.head_ref }} GITHUB_WORKSPACE: ${{ github.workspace }} GITHUB_PULL_REQUEST_BASE_SHA: ${{ github.event.pull_request.base.sha }} + GITHUB_EVENT_BEFORE: ${{ github.event.before }} # 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_SHA: ${{ steps.sha.outputs.sha }} diff --git a/diff-sha.sh b/diff-sha.sh index 9116f3ba..22697493 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -57,30 +57,24 @@ else fi if [[ -z $GITHUB_BASE_REF ]]; then - TARGET_BRANCH=${GITHUB_REF/refs\/heads\//} - CURRENT_BRANCH=$TARGET_BRANCH - - echo "::debug::GITHUB_BASE_REF unset using $TARGET_BRANCH..." + TARGET_BRANCH=${GITHUB_REF/refs\/heads\//} && exit_status=$? || exit_status=$? + CURRENT_BRANCH=$TARGET_BRANCH && exit_status=$? || exit_status=$? if [[ -z $INPUT_BASE_SHA ]]; then - git fetch --no-tags -u --progress origin --depth=2 "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$? - - if [[ $(git rev-list --count "HEAD") -gt 1 ]]; then - PREVIOUS_SHA=$(git rev-parse "@~1" 2>&1) && exit_status=$? || exit_status=$? - echo "::debug::Previous SHA: $PREVIOUS_SHA" - else - PREVIOUS_SHA=$CURRENT_SHA; exit_status=$? + PREVIOUS_SHA=$GITHUB_EVENT_BEFORE + if [[ "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then INITIAL_COMMIT="true" echo "::debug::Initial commit detected" - echo "::debug::Previous SHA: $PREVIOUS_SHA" fi else - PREVIOUS_SHA=$INPUT_BASE_SHA; exit_status=$? + PREVIOUS_SHA=$INPUT_BASE_SHA TARGET_BRANCH=$(git name-rev --name-only "$PREVIOUS_SHA" 2>&1) && exit_status=$? || exit_status=$? - echo "::debug::Previous SHA: $PREVIOUS_SHA" - echo "::debug::Target branch: $TARGET_BRANCH" + CURRENT_BRANCH=$TARGET_BRANCH fi + echo "::debug::Target branch $TARGET_BRANCH..." + echo "::debug::Current branch $CURRENT_BRANCH..." + echo "::debug::Verifying the previous commit SHA: $PREVIOUS_SHA" git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$?