From 7e4f34e152b8bd8fd1c2f45e1fe220fa4301d850 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 18 Jul 2022 13:17:31 -0400 Subject: [PATCH 1/6] feat: improve error handling when similar commit hashed are detected. --- .github/workflows/test.yml | 23 +++++++++++++++++++++++ diff-sha.sh | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a250a675017..c935da81db9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -116,6 +116,29 @@ jobs: shell: bash + test-similar-base-and-commit-sha: + name: Test changed-files similar base and commit sha + runs-on: ${{ matrix.platform }} + strategy: + fail-fast: false + max-parallel: 4 + matrix: + platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] + + steps: + - name: Checkout to branch + uses: actions/checkout@v3 + + - name: Run changed-files with a single commit history + id: changed-files + uses: ./ + + - name: Show output + run: | + echo '${{ toJSON(steps.changed-files.outputs) }}' + shell: + bash + test-non-existent-base-sha: name: Test changed-files non existent base sha runs-on: ${{ matrix.platform }} diff --git a/diff-sha.sh b/diff-sha.sh index 2ded6dd0679..c68c7b5d7fd 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -94,6 +94,12 @@ else fi fi +if [[ -n "$PREVIOUS_SHA" && -n "$CURRENT_SHA" && "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then + echo "::error::Similar commit hashes detected: previous sha: $PREVIOUS_SHA is equivalent to the current sha: $CURRENT_SHA" + echo "::error::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage" + exit 1 +fi + echo "::set-output name=target_branch::$TARGET_BRANCH" echo "::set-output name=current_branch::$CURRENT_BRANCH" echo "::set-output name=previous_sha::$PREVIOUS_SHA" From c50a256518903b2fcc775686a7ad2084e5b5c58f Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 18 Jul 2022 13:22:27 -0400 Subject: [PATCH 2/6] Updated triggered event --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c935da81db9..2a38624a091 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,6 +8,9 @@ on: pull_request: branches: - main + pull_request_review: + types: + - submitted jobs: shellcheck: From 2dd7420eeb1aecef398be6a18e03c62a8c907212 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 18 Jul 2022 15:00:32 -0400 Subject: [PATCH 3/6] Update debug message. --- diff-sha.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index c68c7b5d7fd..d82561a87a7 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -25,7 +25,7 @@ fi echo "::debug::Getting HEAD SHA..." if [[ -z $INPUT_SHA ]]; then - CURRENT_SHA=$(git rev-list --no-merges -n 1 HEAD 2>&1) && exit_status=$? || exit_status=$? + CURRENT_SHA=$(git rev-list --no-merges -n 1 "HEAD" 2>&1) && exit_status=$? || exit_status=$? else CURRENT_SHA=$INPUT_SHA && exit_status=$? || exit_status=$? fi @@ -37,25 +37,33 @@ if [[ $exit_status -ne 0 ]]; then git --version echo "::error::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage" exit 1 +else + echo "::debug::Current SHA: $CURRENT_SHA" 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..." + if [[ -z $INPUT_BASE_SHA ]]; then git fetch --no-tags -u --progress --depth=2 origin "${CURRENT_BRANCH}":"${CURRENT_BRANCH}" && exit_status=$? || exit_status=$? if [[ $(git rev-list --count HEAD) -gt 1 ]]; then - PREVIOUS_SHA=$(git rev-list --no-merges -n 1 HEAD^1 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$(git rev-list --no-merges -n 1 "HEAD^1" 2>&1) && exit_status=$? || exit_status=$? + echo "::debug::Previous SHA: $PREVIOUS_SHA" else PREVIOUS_SHA=$CURRENT_SHA && exit_status=$? || exit_status=$? 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=$? + 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=$? @@ -69,19 +77,25 @@ else TARGET_BRANCH=$GITHUB_BASE_REF CURRENT_BRANCH=$GITHUB_HEAD_REF + echo "::debug::GITHUB_BASE_REF: $TARGET_BRANCH..." + 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=$? + 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 --no-merges -n 1 "${TARGET_BRANCH}" 2>&1) && exit_status=$? || 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=$? 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" fi echo "::debug::Verifying commit SHA..." From 5ffc83493ccdfdd6f222101d702a928fc62b5689 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 18 Jul 2022 15:34:15 -0400 Subject: [PATCH 4/6] Removed --no-merges restriction. --- diff-sha.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index d82561a87a7..b490b2012e8 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -25,7 +25,7 @@ fi echo "::debug::Getting HEAD SHA..." if [[ -z $INPUT_SHA ]]; then - CURRENT_SHA=$(git rev-list --no-merges -n 1 "HEAD" 2>&1) && exit_status=$? || exit_status=$? + CURRENT_SHA=$(git rev-list -n 1 "HEAD" 2>&1) && exit_status=$? || exit_status=$? else CURRENT_SHA=$INPUT_SHA && exit_status=$? || exit_status=$? fi @@ -52,7 +52,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then exit_status=$? || exit_status=$? if [[ $(git rev-list --count HEAD) -gt 1 ]]; then - PREVIOUS_SHA=$(git rev-list --no-merges -n 1 "HEAD^1" 2>&1) && exit_status=$? || exit_status=$? + PREVIOUS_SHA=$(git rev-list -n 1 "HEAD^1" 2>&1) && exit_status=$? || exit_status=$? echo "::debug::Previous SHA: $PREVIOUS_SHA" else PREVIOUS_SHA=$CURRENT_SHA && exit_status=$? || exit_status=$? @@ -87,7 +87,7 @@ else 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 --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=$? echo "::debug::Previous SHA: $PREVIOUS_SHA" fi else From dfd024d538c3c72d1d74e5988c4a25ec252e7d7b Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 18 Jul 2022 15:35:34 -0400 Subject: [PATCH 5/6] Update to use qoutes. --- diff-sha.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index b490b2012e8..c9f4d6fe834 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -51,7 +51,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then git fetch --no-tags -u --progress --depth=2 origin "${CURRENT_BRANCH}":"${CURRENT_BRANCH}" && exit_status=$? || exit_status=$? - if [[ $(git rev-list --count HEAD) -gt 1 ]]; then + if [[ $(git rev-list --count "HEAD") -gt 1 ]]; then PREVIOUS_SHA=$(git rev-list -n 1 "HEAD^1" 2>&1) && exit_status=$? || exit_status=$? echo "::debug::Previous SHA: $PREVIOUS_SHA" else From cdca1ae73de3e0ab910c6e0abceedfed9f653583 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 18 Jul 2022 16:04:00 -0400 Subject: [PATCH 6/6] updated git fetch. --- diff-sha.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index c9f4d6fe834..50e57d061c8 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -48,8 +48,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then echo "::debug::GITHUB_BASE_REF unset using $TARGET_BRANCH..." if [[ -z $INPUT_BASE_SHA ]]; then - git fetch --no-tags -u --progress --depth=2 origin "${CURRENT_BRANCH}":"${CURRENT_BRANCH}" && - exit_status=$? || exit_status=$? + git fetch --no-tags -u --progress --depth=2 origin "${CURRENT_BRANCH}":"${CURRENT_BRANCH}" && exit_status=$? || exit_status=$? if [[ $(git rev-list --count "HEAD") -gt 1 ]]; then PREVIOUS_SHA=$(git rev-list -n 1 "HEAD^1" 2>&1) && exit_status=$? || exit_status=$?