Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: Simplify checks #570

Merged
merged 3 commits into from Aug 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 15 additions & 16 deletions diff-sha.sh
Expand Up @@ -17,7 +17,6 @@ if [[ -n $INPUT_PATH ]]; then
cd "$REPO_DIR"
fi


echo "Verifying git version..."

function __version() {
Expand All @@ -41,12 +40,12 @@ fi
echo "::debug::Getting HEAD SHA..."

if [[ -z $INPUT_SHA ]]; then
CURRENT_SHA=$(git rev-list -n 1 "HEAD" 2>&1) && exit_status=$? || exit_status=$?
CURRENT_SHA=$(git rev-list -n 1 "HEAD" 2>&1) ; exit_status=$?
else
CURRENT_SHA=$INPUT_SHA && exit_status=$? || exit_status=$?
CURRENT_SHA=$INPUT_SHA ; exit_status=$?
fi

git rev-parse --quiet --verify "$CURRENT_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$?
git rev-parse --quiet --verify "$CURRENT_SHA^{commit}" 1>/dev/null 2>&1 ; exit_status=$?

if [[ $exit_status -ne 0 ]]; then
echo "::error::Unable to locate the current sha: $CURRENT_SHA"
Expand All @@ -64,22 +63,22 @@ if [[ -z $GITHUB_BASE_REF ]]; then

if [[ -z $INPUT_BASE_SHA ]]; then
if [[ $(git rev-list --count "HEAD") -gt 1 ]]; then
PREVIOUS_SHA=$(git rev-parse "@~" 2>&1) && exit_status=$? || exit_status=$?
PREVIOUS_SHA=$(git rev-parse "@~" 2>&1) ; exit_status=$?
echo "::debug::Previous SHA: $PREVIOUS_SHA"
else
PREVIOUS_SHA=$CURRENT_SHA && exit_status=$? || exit_status=$?
PREVIOUS_SHA=$CURRENT_SHA ; exit_status=$?
INITIAL_COMMIT="true"
echo "::debug::Initial commit detected"
echo "::debug::Previous SHA: $PREVIOUS_SHA"
fi
else
PREVIOUS_SHA=$INPUT_BASE_SHA && exit_status=$? || exit_status=$?
TARGET_BRANCH=$(git name-rev --name-only "$PREVIOUS_SHA" 2>&1) && exit_status=$? || exit_status=$?
PREVIOUS_SHA=$INPUT_BASE_SHA ; exit_status=$?
TARGET_BRANCH=$(git name-rev --name-only "$PREVIOUS_SHA" 2>&1) ; exit_status=$?
echo "::debug::Previous SHA: $PREVIOUS_SHA"
echo "::debug::Target branch: $TARGET_BRANCH"
fi

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=$?

if [[ $exit_status -ne 0 ]]; then
echo "::error::Unable to locate the previous sha: $PREVIOUS_SHA"
Expand All @@ -95,24 +94,24 @@ else
if [[ -z $INPUT_BASE_SHA ]]; then
if [[ "$INPUT_USE_FORK_POINT" == "true" ]]; then
echo "::debug::Getting fork point..."
git fetch --no-tags -u --progress origin "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$?
PREVIOUS_SHA=$(git merge-base --fork-point "${TARGET_BRANCH}" "$(git name-rev --name-only "$CURRENT_SHA")") && exit_status=$? || exit_status=$?
git fetch --no-tags -u --progress origin "${TARGET_BRANCH}":"${TARGET_BRANCH}" ; exit_status=$?
PREVIOUS_SHA=$(git merge-base --fork-point "${TARGET_BRANCH}" "$(git name-rev --name-only "$CURRENT_SHA")") ; exit_status=$?
echo "::debug::Previous SHA: $PREVIOUS_SHA"
else
git fetch --no-tags -u --progress origin --depth=1 "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$?
PREVIOUS_SHA=$(git rev-list -n 1 "${TARGET_BRANCH}" 2>&1) && exit_status=$? || exit_status=$?
git fetch --no-tags -u --progress origin --depth=1 "${TARGET_BRANCH}":"${TARGET_BRANCH}" ; exit_status=$?
PREVIOUS_SHA=$(git rev-list -n 1 "${TARGET_BRANCH}" 2>&1) ; exit_status=$?
echo "::debug::Previous SHA: $PREVIOUS_SHA"
fi
else
git fetch --no-tags -u --progress origin --depth=1 "$INPUT_BASE_SHA" && exit_status=$? || exit_status=$?
git fetch --no-tags -u --progress origin --depth=1 "$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=$?
echo "::debug::Previous SHA: $PREVIOUS_SHA"
echo "::debug::Target branch: $TARGET_BRANCH"
fi

echo "::debug::Verifying commit 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=$?

if [[ $exit_status -ne 0 ]]; then
echo "::error::Unable to locate the previous sha: $PREVIOUS_SHA"
Expand Down