3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2024-12-17 23:44:46 +00:00

Merge pull request #606 from tj-actions/fix/bug-using-invalid-fetch-depth

fix: bug using invalid fetch-depth
This commit is contained in:
Tonye Jack 2022-09-02 20:39:54 -06:00 committed by GitHub
commit 60f4aabced
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 21 deletions

View file

@ -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

View file

@ -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,11 +126,48 @@ 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
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Run changed-files with similar base and commit sha
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) }}'
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
with:
fetch-depth: 1
- name: Run changed-files with a single commit history
id: changed-files
@ -149,7 +186,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 +238,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 +290,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

View file

@ -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,12 +40,13 @@ 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
git rev-parse --quiet --verify "$CURRENT_SHA^{commit}" 1>/dev/null 2>&1; exit_status=$?
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
echo "::error::Unable to locate the current sha: $CURRENT_SHA"
@ -62,8 +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=$? || 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=$? || exit_status=$?
echo "::debug::Previous SHA: $PREVIOUS_SHA"
else
PREVIOUS_SHA=$CURRENT_SHA; exit_status=$?
@ -73,12 +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
git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1; exit_status=$?
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
echo "::error::Unable to locate the previous sha: $PREVIOUS_SHA"
@ -94,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=$?
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
echo "::error::Unable to locate the previous sha: $PREVIOUS_SHA"
@ -122,6 +126,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