Skip to content

Commit

Permalink
Merge pull request #703 from tj-actions/feat/switch-to-three-dot-diff
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Oct 21, 2022
2 parents 3b998fd + 9403c91 commit b493888
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/codacy-analysis.yml
Expand Up @@ -19,11 +19,6 @@ on:

jobs:
codacy-security-scan:
# Cancel other workflows that are running for the same branch
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
name: Codacy Security Scan
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions action.yml
Expand Up @@ -194,6 +194,7 @@ runs:
shell: bash
env:
GITHUB_WORKSPACE: ${{ github.workspace }}
GITHUB_BASE_REF: ${{ github.base_ref }}
# INPUT_<VARIABLE_NAME> is not available in Composite run steps
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
INPUT_FILES_PATTERN_FILE: ${{ steps.glob.outputs.paths-output-file }}
Expand Down
61 changes: 53 additions & 8 deletions get-changed-paths.sh
Expand Up @@ -8,6 +8,11 @@ INPUT_SEPARATOR="${INPUT_SEPARATOR//$'\n'/'%0A'}"
INPUT_SEPARATOR="${INPUT_SEPARATOR//$'\r'/'%0D'}"

GITHUB_OUTPUT=${GITHUB_OUTPUT:-""}
DIFF="..."

if [[ -z $GITHUB_BASE_REF ]]; then
DIFF=".."
fi

if [[ $INPUT_QUOTEPATH == "false" ]]; then
git config --global core.quotepath off
Expand All @@ -24,8 +29,18 @@ function get_diff() {
sha="$2"
filter="$3"
while IFS='' read -r sub; do
sub_commit_pre="$(git diff "$base" "$sha" -- "$sub" | grep '^[-]Subproject commit' | awk '{print $3}')"
sub_commit_cur="$(git diff "$base" "$sha" -- "$sub" | grep '^[+]Subproject commit' | awk '{print $3}')"
sub_commit_pre="$(git diff "$base$DIFF$sha" -- "$sub" | grep '^[-]Subproject commit' | awk '{print $3}')" && exit_status=$? || exit_status=$?
if [[ $exit_status -ne 0 ]]; then
echo "::error::Failed to get previous commit for submodule ($sub) between: $base$DIFF$sha"
exit 1
fi

sub_commit_cur="$(git diff "$base$DIFF$sha" -- "$sub" | grep '^[+]Subproject commit' | awk '{print $3}')" && exit_status=$? || exit_status=$?
if [[ $exit_status -ne 0 ]]; then
echo "::error::Failed to get current commit for submodule ($sub) between: $base$DIFF$sha"
exit 1
fi

if [ -n "$sub_commit_cur" ]; then
(
cd "$sub" && (
Expand All @@ -37,18 +52,38 @@ function get_diff() {
done < <(git submodule | awk '{print $2}')

if [[ "$INPUT_DIR_NAMES" == "true" ]]; then
git diff --diff-filter="$filter" --name-only --ignore-submodules=all "$base" "$sha" | xargs -I {} dirname {} | uniq
git diff --diff-filter="$filter" --name-only --ignore-submodules=all "$base$DIFF$sha" | xargs -I {} dirname {} | uniq && exit_status=$? || exit_status=$?

if [[ $exit_status -ne 0 ]]; then
echo "::error::Failed to get changed directories between: $base$DIFF$sha"
exit 1
fi
else
git diff --diff-filter="$filter" --name-only --ignore-submodules=all "$base" "$sha"
git diff --diff-filter="$filter" --name-only --ignore-submodules=all "$base$DIFF$sha" && exit_status=$? || exit_status=$?

if [[ $exit_status -ne 0 ]]; then
echo "::error::Failed to get changed files between: $base$DIFF$sha"
exit 1
fi
fi
}

function get_renames() {
base="$1"
sha="$2"
while IFS='' read -r sub; do
sub_commit_pre="$(git diff "$base" "$sha" -- "$sub" | grep '^[-]Subproject commit' | awk '{print $3}')"
sub_commit_cur="$(git diff "$base" "$sha" -- "$sub" | grep '^[+]Subproject commit' | awk '{print $3}')"
sub_commit_pre="$(git diff "$base$DIFF$sha" -- "$sub" | grep '^[-]Subproject commit' | awk '{print $3}')" && exit_status=$? || exit_status=$?
if [[ $exit_status -ne 0 ]]; then
echo "::error::Failed to get previous commit for submodule ($sub) between: $base$DIFF$sha"
exit 1
fi

sub_commit_cur="$(git diff "$base$DIFF$sha" -- "$sub" | grep '^[+]Subproject commit' | awk '{print $3}')" && exit_status=$? || exit_status=$?
if [[ $exit_status -ne 0 ]]; then
echo "::error::Failed to get current commit for submodule ($sub) between: $base$DIFF$sha"
exit 1
fi

if [ -n "$sub_commit_cur" ]; then
(
cd "$sub" && (
Expand All @@ -60,9 +95,19 @@ function get_renames() {
done < <(git submodule | awk '{print $2}')

if [[ "$INPUT_DIR_NAMES" == "true" ]]; then
git log --name-status --ignore-submodules=all "$base".."$sha" | grep -E "^R" | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}' | xargs -I {} dirname {} | uniq
git log --name-status --ignore-submodules=all "$base" "$sha" | grep -E "^R" | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}' | xargs -I {} dirname {} | uniq && exit_status=$? || exit_status=$?

if [[ $exit_status -ne 0 ]]; then
echo "::error::Failed to get renamed directories between: $base$sha"
exit 1
fi
else
git log --name-status --ignore-submodules=all "$base".."$sha" | grep -E "^R" | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}'
git log --name-status --ignore-submodules=all "$base" "$sha" | grep -E "^R" | awk -F '\t' -v d="$INPUT_OLD_NEW_SEPARATOR" '{print $2d$3}' && exit_status=$? || exit_status=$?

if [[ $exit_status -ne 0 ]]; then
echo "::error::Failed to get renamed files between: $base$sha"
exit 1
fi
fi
}

Expand Down

0 comments on commit b493888

Please sign in to comment.