mirror of
https://github.com/tj-actions/changed-files
synced 2024-09-13 04:20:53 +02:00
fix: bug getting diff for submodules and fetching more history (#980)
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
parent
8efe373530
commit
b477871310
35
.github/workflows/test.yml
vendored
35
.github/workflows/test.yml
vendored
|
@ -334,6 +334,41 @@ jobs:
|
||||||
echo "Expected: (failure) got ${{ steps.changed-files-specific.outcome }}"
|
echo "Expected: (failure) got ${{ steps.changed-files-specific.outcome }}"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
||||||
|
test-submodules:
|
||||||
|
name: Test changed-files with submodule
|
||||||
|
runs-on: ${{ matrix.platform }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
max-parallel: 4
|
||||||
|
matrix:
|
||||||
|
platform: [ubuntu-latest]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout to branch
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Run changed-files with submodule
|
||||||
|
id: changed-files
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
base_sha: "85bd869"
|
||||||
|
sha: "adde7bb"
|
||||||
|
fetch_depth: 60000
|
||||||
|
|
||||||
|
- name: Verify added files
|
||||||
|
if: steps.changed-files.outputs.added_files != 'test/demo/test/test.txt'
|
||||||
|
run: |
|
||||||
|
echo "Expected: (test/demo/test/test.txt) got ${{ steps.changed-files.outputs.added_files }}"
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
- name: Show output
|
||||||
|
run: |
|
||||||
|
echo "${{ toJSON(steps.changed-files.outputs) }}"
|
||||||
|
shell:
|
||||||
|
bash
|
||||||
|
|
||||||
test:
|
test:
|
||||||
name: Test changed-files
|
name: Test changed-files
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
|
|
|
@ -4,7 +4,7 @@ set -euo pipefail
|
||||||
|
|
||||||
INITIAL_COMMIT="false"
|
INITIAL_COMMIT="false"
|
||||||
GITHUB_OUTPUT=${GITHUB_OUTPUT:-""}
|
GITHUB_OUTPUT=${GITHUB_OUTPUT:-""}
|
||||||
EXTRA_ARGS="--no-tags --prune --no-recurse-submodules"
|
EXTRA_ARGS="--no-tags --prune --recurse-submodules"
|
||||||
PREVIOUS_SHA=""
|
PREVIOUS_SHA=""
|
||||||
CURRENT_SHA=""
|
CURRENT_SHA=""
|
||||||
DIFF="..."
|
DIFF="..."
|
||||||
|
@ -60,7 +60,9 @@ if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF ]]; then
|
||||||
if [[ -f .git/shallow ]]; then
|
if [[ -f .git/shallow ]]; then
|
||||||
echo "Fetching remote refs..."
|
echo "Fetching remote refs..."
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin "$CURRENT_BRANCH" 1>/dev/null || true
|
git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin +refs/heads/"$CURRENT_BRANCH":refs/remotes/origin/"$CURRENT_BRANCH" 1>/dev/null
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
git submodule foreach git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "::debug::Getting HEAD SHA..."
|
echo "::debug::Getting HEAD SHA..."
|
||||||
|
@ -218,7 +220,7 @@ else
|
||||||
# Fetch more of the target branch history until the merge base is found
|
# Fetch more of the target branch history until the merge base is found
|
||||||
for i in {1..10}; do
|
for i in {1..10}; do
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin "$TARGET_BRANCH:$TARGET_BRANCH" 1>/dev/null
|
git fetch $EXTRA_ARGS -u --progress --deepen="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH" 1>/dev/null
|
||||||
if git merge-base "$PREVIOUS_SHA" "$CURRENT_SHA" 1>/dev/null 2>&1; then
|
if git merge-base "$PREVIOUS_SHA" "$CURRENT_SHA" 1>/dev/null 2>&1; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -56,13 +56,13 @@ function get_dirname_max_depth() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function json_output() {
|
function json_output() {
|
||||||
JQ_ARGS="-sR"
|
local jq_args="-sR"
|
||||||
if [[ "$INPUT_JSON_RAW_FORMAT" == "true" ]]; then
|
if [[ "$INPUT_JSON_RAW_FORMAT" == "true" ]]; then
|
||||||
JQ_ARGS="$JQ_ARGS -r"
|
jq_args="$jq_args -r"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
jq $JQ_ARGS 'split("\n") | map(select(. != "")) | @json' | sed -r 's/^"|"$//g' | tr -s /
|
jq $jq_args 'split("\n") | map(select(. != "")) | @json' | sed -r 's/^"|"$//g' | tr -s /
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_diff() {
|
function get_diff() {
|
||||||
|
@ -71,33 +71,33 @@ function get_diff() {
|
||||||
local filter="$3"
|
local filter="$3"
|
||||||
|
|
||||||
while IFS='' read -r sub; do
|
while IFS='' read -r sub; do
|
||||||
sub_commit_pre="$(git diff "$base$DIFF$sha" -- "$sub" | { grep '^[-]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$?
|
sub_commit_pre="$(git diff "$base" "$sha" -- "$sub" | { grep '^[-]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$?
|
||||||
if [[ $exit_status -ne 0 ]]; then
|
if [[ $exit_status -ne 0 ]]; then
|
||||||
echo "::error::Failed to get previous commit for submodule ($sub) between: $base$DIFF$sha"
|
echo "::warning::Failed to get previous commit for submodule ($sub) between: $base $sha. Please ensure that submodules are initialized and up to date. See: https://github.com/actions/checkout#usage" >&2
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sub_commit_cur="$(git diff "$base$DIFF$sha" -- "$sub" | { grep '^[+]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$?
|
sub_commit_cur="$(git diff "$base" "$sha" -- "$sub" | { grep '^[+]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$?
|
||||||
if [[ $exit_status -ne 0 ]]; then
|
if [[ $exit_status -ne 0 ]]; then
|
||||||
echo "::error::Failed to get current commit for submodule ($sub) between: $base$DIFF$sha"
|
echo "::warning::Failed to get current commit for submodule ($sub) between: $base $sha. Please ensure that submodules are initialized and up to date. See: https://github.com/actions/checkout#usage" >&2
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$sub_commit_cur" ]; then
|
if [ -n "$sub_commit_cur" ]; then
|
||||||
(
|
(
|
||||||
cd "$sub" && (
|
cd "$sub" && (
|
||||||
# the strange magic number is a hardcoded "empty tree" commit sha
|
# the strange magic number is a hardcoded "empty tree" commit sha
|
||||||
get_diff "${sub_commit_pre:-4b825dc642cb6eb9a060e54bf8d69288fbee4904}" "${sub_commit_cur}" "$filter" | awk -v r="$sub" '{ print "" r "/" $0}'
|
git diff --diff-filter="$filter" --name-only --ignore-submodules=all "${sub_commit_pre:-4b825dc642cb6eb9a060e54bf8d69288fbee4904}" "${sub_commit_cur}" | awk -v r="$sub" '{ print "" r "/" $0}' 2>/dev/null
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
) || {
|
||||||
|
echo "::warning::Failed to get changed files for submodule ($sub) between: ${sub_commit_pre:-4b825dc642cb6eb9a060e54bf8d69288fbee4904} ${sub_commit_cur}. Please ensure that submodules are initialized and up to date. See: https://github.com/actions/checkout#usage" >&2
|
||||||
|
}
|
||||||
fi
|
fi
|
||||||
done < <(git submodule | awk '{print $2}')
|
done < <(git submodule | awk '{print $2}')
|
||||||
|
|
||||||
git diff --diff-filter="$filter" --name-only --ignore-submodules=all --no-merges "$base$DIFF$sha" && exit_status=$? || exit_status=$?
|
git diff --diff-filter="$filter" --name-only --ignore-submodules=all "$base$DIFF$sha" && exit_status=$? || exit_status=$?
|
||||||
|
|
||||||
if [[ $exit_status -ne 0 ]]; then
|
if [[ $exit_status -ne 0 ]]; then
|
||||||
echo "::error::Failed to get changed files between: $base$DIFF$sha"
|
echo "::error::Failed to get changed files between: $base$DIFF$sha" >&2
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,33 +106,33 @@ function get_renames() {
|
||||||
local sha="$2"
|
local sha="$2"
|
||||||
|
|
||||||
while IFS='' read -r sub; do
|
while IFS='' read -r sub; do
|
||||||
sub_commit_pre="$(git diff "$base$DIFF$sha" -- "$sub" | { grep '^[-]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$?
|
sub_commit_pre="$(git diff "$base" "$sha" -- "$sub" | { grep '^[-]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$?
|
||||||
if [[ $exit_status -ne 0 ]]; then
|
if [[ $exit_status -ne 0 ]]; then
|
||||||
echo "::error::Failed to get previous commit for submodule ($sub) between: $base$DIFF$sha"
|
echo "::warning::Failed to get previous commit for submodule ($sub) between: $base $sha. Please ensure that submodules are initialized and up to date. See: https://github.com/actions/checkout#usage" >&2
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sub_commit_cur="$(git diff "$base$DIFF$sha" -- "$sub" | { grep '^[+]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$?
|
sub_commit_cur="$(git diff "$base" "$sha" -- "$sub" | { grep '^[+]Subproject commit' || true; } | awk '{print $3}')" && exit_status=$? || exit_status=$?
|
||||||
if [[ $exit_status -ne 0 ]]; then
|
if [[ $exit_status -ne 0 ]]; then
|
||||||
echo "::error::Failed to get current commit for submodule ($sub) between: $base$DIFF$sha"
|
echo "::warning::Failed to get current commit for submodule ($sub) between: $base $sha. Please ensure that submodules are initialized and up to date. See: https://github.com/actions/checkout#usage" >&2
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$sub_commit_cur" ]; then
|
if [ -n "$sub_commit_cur" ]; then
|
||||||
(
|
(
|
||||||
cd "$sub" && (
|
cd "$sub" && (
|
||||||
# the strange magic number is a hardcoded "empty tree" commit sha
|
# the strange magic number is a hardcoded "empty tree" commit sha
|
||||||
get_renames "${sub_commit_pre:-4b825dc642cb6eb9a060e54bf8d69288fbee4904}" "${sub_commit_cur}" | awk -v r="$sub" '{ print "" r "/" $0}'
|
git log --name-status --ignore-submodules=all "${sub_commit_pre:-4b825dc642cb6eb9a060e54bf8d69288fbee4904}" "${sub_commit_cur}" | { grep -E "^R" || true; } | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}' | awk -v r="$sub" '{ print "" r "/" $0}'
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
) || {
|
||||||
|
echo "::warning::Failed to get renamed files for submodule ($sub) between: ${sub_commit_pre:-4b825dc642cb6eb9a060e54bf8d69288fbee4904} ${sub_commit_cur}. Please ensure that submodules are initialized and up to date. See: https://github.com/actions/checkout#usage" >&2
|
||||||
|
}
|
||||||
fi
|
fi
|
||||||
done < <(git submodule | awk '{print $2}')
|
done < <(git submodule | awk '{print $2}')
|
||||||
|
|
||||||
git log --name-status --ignore-submodules=all "$base" "$sha" | { grep -E "^R" || true; } | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}' && exit_status=$? || exit_status=$?
|
git log --name-status --ignore-submodules=all "$base" "$sha" | { grep -E "^R" || true; } | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}' && exit_status=$? || exit_status=$?
|
||||||
|
|
||||||
if [[ $exit_status -ne 0 ]]; then
|
if [[ $exit_status -ne 0 ]]; then
|
||||||
echo "::error::Failed to get renamed files between: $base → $sha"
|
echo "::error::Failed to get renamed files between: $base → $sha" >&2
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 3b8549eb19fb6d4ff2017cbe27d2cec353cace93
|
Subproject commit 83ccca9b633cc41dc1f04e690e4a3a8026a01359
|
Loading…
Reference in a new issue