Updated to use the last remote commit by default.

This commit is contained in:
Tonye Jack 2022-09-24 19:08:58 -06:00
parent 2c4c729f2a
commit 5485a02af8
2 changed files with 10 additions and 15 deletions

View File

@ -189,6 +189,7 @@ runs:
GITHUB_HEAD_REF: ${{ github.head_ref }} GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_WORKSPACE: ${{ github.workspace }} GITHUB_WORKSPACE: ${{ github.workspace }}
GITHUB_PULL_REQUEST_BASE_SHA: ${{ github.event.pull_request.base.sha }} GITHUB_PULL_REQUEST_BASE_SHA: ${{ github.event.pull_request.base.sha }}
GITHUB_EVENT_BEFORE: ${{ github.event.before }}
# INPUT_<VARIABLE_NAME> is not available in Composite run steps # INPUT_<VARIABLE_NAME> is not available in Composite run steps
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs # https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
INPUT_SHA: ${{ steps.sha.outputs.sha }} INPUT_SHA: ${{ steps.sha.outputs.sha }}

View File

@ -57,30 +57,24 @@ else
fi fi
if [[ -z $GITHUB_BASE_REF ]]; then if [[ -z $GITHUB_BASE_REF ]]; then
TARGET_BRANCH=${GITHUB_REF/refs\/heads\//} TARGET_BRANCH=${GITHUB_REF/refs\/heads\//} && exit_status=$? || exit_status=$?
CURRENT_BRANCH=$TARGET_BRANCH CURRENT_BRANCH=$TARGET_BRANCH && exit_status=$? || exit_status=$?
echo "::debug::GITHUB_BASE_REF unset using $TARGET_BRANCH..."
if [[ -z $INPUT_BASE_SHA ]]; then if [[ -z $INPUT_BASE_SHA ]]; then
git fetch --no-tags -u --progress origin --depth=2 "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$? PREVIOUS_SHA=$GITHUB_EVENT_BEFORE
if [[ "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then
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=$?
INITIAL_COMMIT="true" INITIAL_COMMIT="true"
echo "::debug::Initial commit detected" echo "::debug::Initial commit detected"
echo "::debug::Previous SHA: $PREVIOUS_SHA"
fi fi
else 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=$? TARGET_BRANCH=$(git name-rev --name-only "$PREVIOUS_SHA" 2>&1) && exit_status=$? || exit_status=$?
echo "::debug::Previous SHA: $PREVIOUS_SHA" CURRENT_BRANCH=$TARGET_BRANCH
echo "::debug::Target branch: $TARGET_BRANCH"
fi fi
echo "::debug::Target branch $TARGET_BRANCH..."
echo "::debug::Current branch $CURRENT_BRANCH..."
echo "::debug::Verifying the previous commit SHA: $PREVIOUS_SHA" 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=$? git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$?