From cb433740f0b62fdebf430fba33db122306f0dd76 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 1 Sep 2022 13:14:33 -0600 Subject: [PATCH 01/11] chore: test invalid fetch-depth --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bb51520e..1c4085ba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -260,7 +260,7 @@ jobs: uses: actions/checkout@v3 with: submodules: true - fetch-depth: 0 + fetch-depth: 1 - name: Run changed-files with defaults id: changed-files uses: ./ From 52a83d3ef347348ace267c2493bec78d8065803b Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 2 Sep 2022 15:08:19 -0600 Subject: [PATCH 02/11] fix: bug using invalid fetch-depth --- diff-sha.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index 5e7ae911..1d1193ed 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -62,8 +62,10 @@ 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 origin --depth=2 "${TARGET_BRANCH}":"${TARGET_BRANCH}"; exit_status=$? + if [[ $(git rev-list --count "HEAD") -gt 1 ]]; then - PREVIOUS_SHA=$(git rev-parse "@~" 2>&1); exit_status=$? + PREVIOUS_SHA=$(git rev-parse "@~1" 2>&1); exit_status=$? echo "::debug::Previous SHA: $PREVIOUS_SHA" else PREVIOUS_SHA=$CURRENT_SHA; exit_status=$? @@ -122,6 +124,7 @@ fi if [[ -n "$PREVIOUS_SHA" && -n "$CURRENT_SHA" && "$PREVIOUS_SHA" == "$CURRENT_SHA" && "$INITIAL_COMMIT" == "false" ]]; 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 From 4472745cf1973d5fc1e62a80701f39cf51ade0cc Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 2 Sep 2022 15:20:06 -0600 Subject: [PATCH 03/11] add debug message. --- diff-sha.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diff-sha.sh b/diff-sha.sh index 1d1193ed..da65bba2 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -45,6 +45,7 @@ else CURRENT_SHA=$INPUT_SHA; exit_status=$? fi +echo "Verifying the commit SHA: $CURRENT_SHA" git rev-parse --quiet --verify "$CURRENT_SHA^{commit}" 1>/dev/null 2>&1; exit_status=$? if [[ $exit_status -ne 0 ]]; then @@ -80,6 +81,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then echo "::debug::Target branch: $TARGET_BRANCH" fi + echo "Verifying the commit SHA: $PREVIOUS_SHA" git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1; exit_status=$? if [[ $exit_status -ne 0 ]]; then From 0f7f451225831eafd58d6e22f2772f766a211810 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 2 Sep 2022 15:24:30 -0600 Subject: [PATCH 04/11] updated tested platforms. --- .github/workflows/manual-test.yml | 2 +- .github/workflows/test.yml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/manual-test.yml b/.github/workflows/manual-test.yml index 34613b5c..e325ce50 100644 --- a/.github/workflows/manual-test.yml +++ b/.github/workflows/manual-test.yml @@ -11,7 +11,7 @@ jobs: fail-fast: false max-parallel: 4 matrix: - platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] + platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] steps: - name: Checkout diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c4085ba..9438bce7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: fail-fast: false max-parallel: 4 matrix: - platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] + platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] steps: - name: Checkout @@ -70,7 +70,7 @@ jobs: fail-fast: false max-parallel: 4 matrix: - platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] + platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] steps: - name: Checkout into dir1 uses: actions/checkout@v3 @@ -126,7 +126,7 @@ jobs: fail-fast: false max-parallel: 4 matrix: - platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] + platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] steps: - name: Checkout to branch @@ -149,7 +149,7 @@ jobs: fail-fast: false max-parallel: 4 matrix: - platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] + platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] steps: - name: Checkout to branch @@ -201,7 +201,7 @@ jobs: fail-fast: false max-parallel: 4 matrix: - platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] + platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] steps: - name: Checkout to branch @@ -253,7 +253,7 @@ jobs: fail-fast: false max-parallel: 4 matrix: - platform: [ubuntu-latest, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] + platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] steps: - name: Checkout From 1faa996b8782803fb39958368a3443a5b5266ecc Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 2 Sep 2022 16:41:25 -0600 Subject: [PATCH 05/11] Updated setting the exit status --- diff-sha.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index da65bba2..663f421f 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -46,7 +46,7 @@ else fi echo "Verifying the commit SHA: $CURRENT_SHA" -git rev-parse --quiet --verify "$CURRENT_SHA^{commit}" 1>/dev/null 2>&1; exit_status=$? +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" From 618e7037685b75f33676fa86ec6c48274c9011d1 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 2 Sep 2022 18:23:52 -0600 Subject: [PATCH 06/11] Fixed bug with setting the exit status --- diff-sha.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 663f421f..702e78d8 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -23,7 +23,7 @@ function __version() { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } -GIT_VERSION=$(git --version | awk '{print $3}'); exit_status=$? +GIT_VERSION=$(git --version | awk '{print $3}') && exit_status=$? || exit_status=$? if [[ $exit_status -ne 0 ]]; then echo "::error::git not installed" @@ -40,7 +40,7 @@ fi echo "::debug::Getting HEAD SHA..." if [[ -z $INPUT_SHA ]]; then - CURRENT_SHA=$(git rev-list -n 1 "HEAD" 2>&1); exit_status=$? + CURRENT_SHA=$(git rev-list -n 1 "HEAD" 2>&1) && exit_status=$? || exit_status=$? else CURRENT_SHA=$INPUT_SHA; exit_status=$? fi @@ -63,10 +63,10 @@ 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 origin --depth=2 "${TARGET_BRANCH}":"${TARGET_BRANCH}"; exit_status=$? + 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=$? + 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=$? @@ -76,13 +76,13 @@ if [[ -z $GITHUB_BASE_REF ]]; then fi else PREVIOUS_SHA=$INPUT_BASE_SHA; exit_status=$? - TARGET_BRANCH=$(git name-rev --name-only "$PREVIOUS_SHA" 2>&1); 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 echo "Verifying the commit SHA: $PREVIOUS_SHA" - git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1; exit_status=$? + git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$? if [[ $exit_status -ne 0 ]]; then echo "::error::Unable to locate the previous sha: $PREVIOUS_SHA" @@ -98,24 +98,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=$? - PREVIOUS_SHA=$(git merge-base --fork-point "${TARGET_BRANCH}" "$(git name-rev --name-only "$CURRENT_SHA")"); exit_status=$? + 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=$? - PREVIOUS_SHA=$(git rev-list -n 1 "${TARGET_BRANCH}" 2>&1); exit_status=$? + 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=$? echo "::debug::Previous SHA: $PREVIOUS_SHA" fi else - git fetch --no-tags -u --progress origin --depth=1 "$(git rev-parse --verify "$INPUT_BASE_SHA")"; exit_status=$? + git fetch --no-tags -u --progress origin --depth=1 "$(git rev-parse --verify "$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=$? + 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..." - git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1; exit_status=$? + git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1 && exit_status=$? || exit_status=$? if [[ $exit_status -ne 0 ]]; then echo "::error::Unable to locate the previous sha: $PREVIOUS_SHA" From 16e8ea38dafa71a0d57e84898a55cef68b71fc0e Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 2 Sep 2022 18:25:29 -0600 Subject: [PATCH 07/11] Updated the test --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9438bce7..7b83170f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -131,6 +131,8 @@ jobs: steps: - name: Checkout to branch uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Run changed-files with a single commit history id: changed-files @@ -260,7 +262,7 @@ jobs: uses: actions/checkout@v3 with: submodules: true - fetch-depth: 1 + fetch-depth: 0 - name: Run changed-files with defaults id: changed-files uses: ./ From 3a8cb1858935dc46a29769060d78b7357dbf9ed5 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 2 Sep 2022 18:32:08 -0600 Subject: [PATCH 08/11] update the test. --- .github/workflows/test.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7b83170f..d0d1eff0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -128,6 +128,34 @@ jobs: matrix: platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] + steps: + - name: Checkout to branch + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Run changed-files with a single commit history + id: changed-files + uses: ./ + with: + base_sha: d1c0ee4 + sha: d1c0ee4 + + - name: Show output + run: | + echo '${{ toJSON(steps.changed-files.outputs) }}' + shell: + bash + + test-single-commit-history: + name: Test changed-files single commit history + runs-on: ${{ matrix.platform }} + strategy: + fail-fast: false + max-parallel: 4 + matrix: + platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, ubuntu-18.04, windows-2022] + steps: - name: Checkout to branch uses: actions/checkout@v3 From dcd088713aa5ca25afe80c2b5109c70ab8c15683 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 2 Sep 2022 18:40:51 -0600 Subject: [PATCH 09/11] updated debug message. --- diff-sha.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/diff-sha.sh b/diff-sha.sh index 702e78d8..1e17d360 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -45,7 +45,7 @@ else CURRENT_SHA=$INPUT_SHA; exit_status=$? fi -echo "Verifying the commit SHA: $CURRENT_SHA" +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 @@ -81,7 +81,7 @@ if [[ -z $GITHUB_BASE_REF ]]; then echo "::debug::Target branch: $TARGET_BRANCH" fi - echo "Verifying the 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=$? if [[ $exit_status -ne 0 ]]; then @@ -114,7 +114,7 @@ else echo "::debug::Target branch: $TARGET_BRANCH" fi - echo "::debug::Verifying commit 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=$? if [[ $exit_status -ne 0 ]]; then From 6ffc0e26e3e88c17c61c9658003be49af93e1736 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 2 Sep 2022 18:50:38 -0600 Subject: [PATCH 10/11] added continue-on-error. --- .github/workflows/test.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d0d1eff0..f00b76fc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -136,11 +136,18 @@ jobs: - name: Run changed-files with a single commit history id: changed-files + continue-on-error: true uses: ./ with: base_sha: d1c0ee4 sha: d1c0ee4 + - name: Exit with 1 if no error is raised + if: steps.changed-files.outcome != 'failure' + run: | + echo "Expected: (failure) got ${{ steps.changed-files.outcome }}" + exit 1 + - name: Show output run: | echo '${{ toJSON(steps.changed-files.outputs) }}' From 5dd27b18ae12f8662ae2be013cb29f30e7445688 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 2 Sep 2022 18:55:23 -0600 Subject: [PATCH 11/11] update test name --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f00b76fc..7fc59dde 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -134,7 +134,7 @@ jobs: with: fetch-depth: 0 - - name: Run changed-files with a single commit history + - name: Run changed-files with similar base and commit sha id: changed-files continue-on-error: true uses: ./