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

fix: error retrieving changed files #882

Merged
merged 61 commits into from Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
5305478
chore: update test
jackton1 Dec 17, 2022
b34d5e2
Update test.yml
jackton1 Dec 17, 2022
544eedb
Update diff-sha.sh
jackton1 Dec 17, 2022
89c3040
Update diff-sha.sh
jackton1 Dec 17, 2022
cdb935e
Update diff-sha.sh
jackton1 Dec 17, 2022
62cf6ff
Update diff-sha.sh
jackton1 Dec 17, 2022
711063a
Update diff-sha.sh
jackton1 Dec 17, 2022
fcd7ae2
Updated diff-sha.sh
jackton1 Dec 17, 2022
e8e58a6
Fixed test
jackton1 Dec 17, 2022
8c95fb0
add support for reverting back to detached head state
jackton1 Dec 17, 2022
50b6410
Update to catch error
jackton1 Dec 17, 2022
fb232fe
Update to pull latest commits from the target branch
jackton1 Dec 17, 2022
e42a88c
Update to verify the diff
jackton1 Dec 17, 2022
08b8ee2
Update to verify the diff
jackton1 Dec 17, 2022
60a9d77
Update to verify the diff
jackton1 Dec 17, 2022
283e880
Simplify code
jackton1 Dec 18, 2022
4214c2a
Apply suggestions from code review
jackton1 Dec 18, 2022
a8d56bb
Update diff-sha.sh
jackton1 Dec 18, 2022
703b662
Fixed test
jackton1 Dec 18, 2022
febdf1a
Remove quotes
jackton1 Dec 18, 2022
f53b7e9
Fixed test
jackton1 Dec 18, 2022
845693f
Update diff-sha.sh
jackton1 Dec 18, 2022
2ffae43
Update diff-sha.sh
jackton1 Dec 18, 2022
34375c2
Merge branch 'main' into chore/update-test
jackton1 Dec 18, 2022
fffc9d3
Fixed test
jackton1 Dec 18, 2022
0e24086
Update to change diff type when the previous commit is a merge commit
jackton1 Dec 18, 2022
118e726
Fixed test
jackton1 Dec 18, 2022
603fac5
Merge branch 'main' into chore/update-test
jackton1 Dec 18, 2022
5f0eeb7
Revert change
jackton1 Dec 18, 2022
a5c1a43
Updated to use rev-list
jackton1 Dec 18, 2022
2de79fb
Updated to use the latest commit
jackton1 Dec 18, 2022
65352aa
Merge branch 'main' into chore/update-test
jackton1 Dec 18, 2022
84d2ce6
Updated to use the latest commit
jackton1 Dec 18, 2022
c812b6c
Updated to use the latest commit
jackton1 Dec 18, 2022
13e9787
Updated to use the latest commit
jackton1 Dec 18, 2022
9d94ea1
Updated to use the latest commit
jackton1 Dec 18, 2022
4e8080d
Updated to use the latest commit
jackton1 Dec 18, 2022
40b82be
Updated code
jackton1 Dec 18, 2022
721f2f5
Merge branch 'main' into chore/update-test
jackton1 Dec 18, 2022
d8d060e
Updated to use the first commit.
jackton1 Dec 19, 2022
d42c826
Updated to fetch all PR commits
jackton1 Dec 19, 2022
1274700
Updated to fetch all PR commits
jackton1 Dec 19, 2022
c216a56
Update to use 2dot diff
jackton1 Dec 19, 2022
43ada8a
Updated debug information
jackton1 Dec 19, 2022
4e437e5
Update diff-sha.sh
jackton1 Dec 19, 2022
31e82da
Update action.yml
jackton1 Dec 19, 2022
e29f1ab
Update diff-sha.sh
jackton1 Dec 19, 2022
9bd2f84
Updated to use the last commit as fallback
jackton1 Dec 19, 2022
1aeb40d
Fixed test
jackton1 Dec 19, 2022
7ee4ded
Updated test
jackton1 Dec 19, 2022
b7066b6
fix test
jackton1 Dec 19, 2022
6d11ed9
Exclude merge commits
jackton1 Dec 19, 2022
0bb4353
Update README.md
jackton1 Dec 18, 2022
eedcf22
Update README.md
jackton1 Dec 19, 2022
e7601b2
Update README.md
jackton1 Dec 19, 2022
28c3853
Update README.md
jackton1 Dec 19, 2022
24cfd27
Update README.md
jackton1 Dec 19, 2022
8120d3d
Update README.md
jackton1 Dec 19, 2022
5b64877
Update README.md
jackton1 Dec 19, 2022
74b4115
Removed unused input
jackton1 Dec 19, 2022
027bd85
Merge branch 'main' into chore/update-test
jackton1 Dec 19, 2022
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
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Expand Up @@ -37,7 +37,7 @@ jobs:
fail-fast: false
max-parallel: 2
matrix:
platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, windows-2022]
platform: [ubuntu-latest]
steps:
- name: Checkout into dir1
uses: actions/checkout@v3
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
fail-fast: false
max-parallel: 2
matrix:
platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-11, macos-latest, windows-2022]
platform: [ubuntu-latest]

steps:
- name: Checkout to branch
Expand Down Expand Up @@ -149,7 +149,7 @@ jobs:
fail-fast: false
max-parallel: 4
matrix:
platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, windows-2022]
platform: [ubuntu-latest]

steps:
- name: Checkout to branch
Expand Down Expand Up @@ -184,7 +184,7 @@ jobs:
fail-fast: false
max-parallel: 4
matrix:
platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, windows-2022]
platform: [ubuntu-latest]

steps:
- name: Checkout to branch
Expand Down Expand Up @@ -212,7 +212,7 @@ jobs:
fail-fast: false
max-parallel: 4
matrix:
platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, windows-2022]
platform: [ubuntu-latest]
fetch-depth: [1, 2]

steps:
Expand All @@ -238,7 +238,7 @@ jobs:
fail-fast: false
max-parallel: 4
matrix:
platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, windows-2022]
platform: [ubuntu-latest]

steps:
- name: Checkout to branch
Expand Down Expand Up @@ -290,7 +290,7 @@ jobs:
fail-fast: false
max-parallel: 4
matrix:
platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, windows-2022]
platform: [ubuntu-latest]

steps:
- name: Checkout to branch
Expand Down
87 changes: 18 additions & 69 deletions diff-sha.sh
@@ -1,13 +1,14 @@
#!/usr/bin/env bash

set -euo pipefail
set -euxo pipefail

INITIAL_COMMIT="false"
GITHUB_OUTPUT=${GITHUB_OUTPUT:-""}
EXTRA_ARGS="--no-tags --prune --no-recurse-submodules"
PREVIOUS_SHA=""
CURRENT_SHA=""
DIFF="..."
DETACHED_HEAD="false"
Fixed Show fixed Hide fixed

if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then
EXTRA_ARGS="--prune --no-recurse-submodules"
Expand Down Expand Up @@ -158,36 +159,6 @@ else

echo "Fetching remote refs..."

if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "false" ]]; then
# shellcheck disable=SC2086
git fetch -u --progress $EXTRA_ARGS --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" 1>/dev/null 2>&1
git branch --track "$TARGET_BRANCH" origin/"$TARGET_BRANCH" 1>/dev/null 2>&1 || true
# shellcheck disable=SC2086
git fetch $EXTRA_ARGS -u --progress --depth=$(( GITHUB_EVENT_PULL_REQUEST_COMMITS + 1 )) origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" 1>/dev/null 2>&1

COMMON_ANCESTOR=$(git merge-base --fork-point "$TARGET_BRANCH" HEAD) && exit_status=$? || exit_status=$?

if [[ -z "$COMMON_ANCESTOR" ]]; then
echo "::debug::Unable to locate a common ancestor for the current branch: $CURRENT_BRANCH"
else
echo "::debug::Common ancestor: $COMMON_ANCESTOR"

DATE=$(git show --quiet --date=iso8601 --format=%cd "$COMMON_ANCESTOR")

if [[ -z "$DATE" ]]; then
echo "::error::Unable to locate a date for the common ancestor: $COMMON_ANCESTOR"
exit 1
else
# shellcheck disable=SC2086
git fetch $EXTRA_ARGS --shallow-since="${DATE}" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" 1>/dev/null 2>&1
echo "::debug::Date: $DATE"
fi
fi
else
# shellcheck disable=SC2086
git fetch $EXTRA_ARGS -u --progress --depth="$INPUT_FETCH_DEPTH" origin +"$GITHUB_REF":refs/remotes/origin/"$CURRENT_BRANCH" 1>/dev/null 2>&1
fi

echo "::debug::Getting HEAD SHA..."
if [[ -n "$INPUT_UNTIL" ]]; then
echo "::debug::Getting HEAD SHA for '$INPUT_UNTIL'..."
Expand Down Expand Up @@ -222,20 +193,31 @@ else

if [[ -z $INPUT_BASE_SHA ]]; then
if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then
echo "::debug::Fetching remote current branch..."

git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin "$CURRENT_BRANCH" 1>/dev/null 2>&1
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
Fixed Show fixed Hide fixed
jackton1 marked this conversation as resolved.
Show resolved Hide resolved

PREVIOUS_SHA=$GITHUB_EVENT_BEFORE

if ! git rev-parse --quiet --verify "$PREVIOUS_SHA^{commit}" 1>/dev/null 2>&1; then
PREVIOUS_SHA=$(git rev-parse origin/"$CURRENT_BRANCH")
fi
else
PREVIOUS_SHA=${COMMON_ANCESTOR:-}

echo "::debug::Fetching remote target branch..."
git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin "$TARGET_BRANCH" 1>/dev/null 2>&1
jackton1 marked this conversation as resolved.
Show resolved Hide resolved
Fixed Show fixed Hide fixed
jackton1 marked this conversation as resolved.
Show resolved Hide resolved

PREVIOUS_SHA=$(git rev-parse origin/"$TARGET_BRANCH")

# Find the merge-base between the target branch and the current branch
if [[ -z "$PREVIOUS_SHA" ]]; then
PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$?
PREVIOUS_SHA=$(git merge-base origin/"$TARGET_BRANCH" "$CURRENT_SHA") && exit_status=$? || exit_status=$?
fi

if ! git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then
PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA
# Verify that the merge-base is valid
if [[ $exit_status -ne 0 ]]; then
echo "::error::Unable to locate the merge-base between $TARGET_BRANCH and $CURRENT_BRANCH."
echo "::error::Please verify that the target branch is valid, and increase the fetch_depth to a number higher than $INPUT_FETCH_DEPTH."
exit 1
fi
fi

Expand All @@ -247,39 +229,6 @@ else
else
PREVIOUS_SHA=$INPUT_BASE_SHA && exit_status=$? || exit_status=$?
fi

if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "false" ]]; then
if [[ -f .git/shallow ]]; then
depth=$INPUT_FETCH_DEPTH
max_depth=$INPUT_MAX_FETCH_DEPTH

for ((i=20; i<max_depth; i+=depth)); do
if git diff --name-only --ignore-submodules=all "$PREVIOUS_SHA$DIFF$CURRENT_SHA" 1>/dev/null 2>&1; then
break
fi

if [[ -z "$INPUT_BASE_SHA" ]]; then
NEW_PREVIOUS_SHA=$(git merge-base --fork-point "$TARGET_BRANCH" "$CURRENT_SHA") && exit_status=$? || exit_status=$?

if [[ -n "$NEW_PREVIOUS_SHA" ]]; then
PREVIOUS_SHA=$NEW_PREVIOUS_SHA
fi
fi

echo "Fetching $i commits..."

# shellcheck disable=SC2086
git fetch $EXTRA_ARGS -u --progress --deepen="$i" origin $TARGET_BRANCH $CURRENT_SHA 1>/dev/null 2>&1
done

if ((i > max_depth)); then
echo "::error::Unable to locate a common ancestor between $TARGET_BRANCH and $CURRENT_BRANCH with: $PREVIOUS_SHA$DIFF$CURRENT_SHA"
exit 1
fi
else
echo "::debug::Not a shallow clone, skipping merge-base check."
fi
fi

echo "::debug::Target branch: $TARGET_BRANCH"
echo "::debug::Current branch: $CURRENT_BRANCH"
Expand Down