3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-01-17 19:17:45 +00:00

feat: remove duplicate files support backwards compatible set-output

This commit is contained in:
Tonye Jack 2022-10-14 12:59:47 -06:00
parent 48f056c336
commit 759895012f
5 changed files with 140 additions and 107 deletions

View file

@ -150,33 +150,6 @@ outputs:
runs: runs:
using: "composite" using: "composite"
steps: steps:
- run: |
# "Calculate the base sha..."
bash $GITHUB_ACTION_PATH/get-base-sha.sh
id: base-sha
shell: bash
env:
GITHUB_WORKSPACE: ${{ github.workspace }}
GITHUB_EVENT_BEFORE: ${{ github.event.before }}
GITHUB_EVENT_FORCED : ${{ github.event.forced }}
# 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_SINCE: ${{ inputs.since }}
INPUT_BASE_SHA: ${{ inputs.base_sha }}
INPUT_SHA: ${{ inputs.sha }}
INPUT_PATH: ${{ inputs.path }}
- run: |
# "Calculate the sha..."
bash $GITHUB_ACTION_PATH/get-sha.sh
id: sha
shell: bash
env:
GITHUB_WORKSPACE: ${{ github.workspace }}
# 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_UNTIL: ${{ inputs.until }}
INPUT_SHA: ${{ inputs.sha }}
INPUT_PATH: ${{ inputs.path }}
- run: | - run: |
# "Calculating the previous and current SHA..." # "Calculating the previous and current SHA..."
bash $GITHUB_ACTION_PATH/diff-sha.sh bash $GITHUB_ACTION_PATH/diff-sha.sh
@ -193,8 +166,10 @@ runs:
GITHUB_EVENT_FORCED: ${{ github.event.forced }} GITHUB_EVENT_FORCED: ${{ github.event.forced }}
# INPUT_<VARIABLE_NAME> is not available in Composite run steps # 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 # https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#example-specifying-inputs
INPUT_SHA: ${{ steps.sha.outputs.sha }} INPUT_SHA: ${{ inputs.sha }}
INPUT_BASE_SHA: ${{ steps.base-sha.outputs.base_sha }} INPUT_BASE_SHA: ${{ inputs.base_sha }}
INPUT_SINCE: ${{ inputs.since }}
INPUT_UNTIL: ${{ inputs.until }}
INPUT_PATH: ${{ inputs.path }} INPUT_PATH: ${{ inputs.path }}
INPUT_TARGET_BRANCH_FETCH_DEPTH: ${{ inputs.target_branch_fetch_depth }} INPUT_TARGET_BRANCH_FETCH_DEPTH: ${{ inputs.target_branch_fetch_depth }}
- name: Glob match - name: Glob match

View file

@ -40,7 +40,16 @@ fi
echo "::debug::Getting HEAD SHA..." echo "::debug::Getting HEAD SHA..."
if [[ -z $INPUT_SHA ]]; then if [[ -z $INPUT_SHA ]]; then
CURRENT_SHA=$(git rev-list -n 1 "HEAD" 2>&1) && exit_status=$? || exit_status=$? if [[ -n "$INPUT_UNTIL" ]]; then
CURRENT_SHA=$(git log -1 --format="%H" --date=local --until="$INPUT_UNTIL") && exit_status=$? || exit_status=$?
if [[ $exit_status -ne 0 ]]; then
echo "::error::Invalid until date: $INPUT_UNTIL"
exit 1
fi
else
CURRENT_SHA=$(git rev-list -n 1 "HEAD" 2>&1) && exit_status=$? || exit_status=$?
fi
else else
CURRENT_SHA=$INPUT_SHA; exit_status=$? CURRENT_SHA=$INPUT_SHA; exit_status=$?
fi fi
@ -63,22 +72,37 @@ if [[ -z $GITHUB_BASE_REF ]]; then
if [[ -z $INPUT_BASE_SHA ]]; then if [[ -z $INPUT_BASE_SHA ]]; then
git fetch --no-tags -u --progress origin --depth="$INPUT_TARGET_BRANCH_FETCH_DEPTH" "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$? git fetch --no-tags -u --progress origin --depth="$INPUT_TARGET_BRANCH_FETCH_DEPTH" "${TARGET_BRANCH}":"${TARGET_BRANCH}" && exit_status=$? || exit_status=$?
PREVIOUS_SHA=""
if [[ "$GITHUB_EVENT_FORCED" == "false" ]]; then if [[ -n "$INPUT_SINCE" ]]; then
PREVIOUS_SHA=$GITHUB_EVENT_BEFORE PREVIOUS_SHA=$(git log --format="%H" --date=local --since="$INPUT_SINCE" --reverse | head -n 1)
fi
if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "0000000000000000000000000000000000000000" ]]; then if [[ -z "$PREVIOUS_SHA" ]]; then
PREVIOUS_SHA=$(git rev-parse "$(git branch -r --sort=-committerdate | head -1 | xargs)") echo "::error::Unable to locate a previous commit for the specified date: $INPUT_SINCE"
fi exit 1
fi
else
PREVIOUS_SHA=""
if [[ "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then if [[ "$GITHUB_EVENT_FORCED" == "false" ]]; then
PREVIOUS_SHA=$(git rev-parse "$CURRENT_SHA^1") PREVIOUS_SHA=$GITHUB_EVENT_BEFORE
fi
if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "0000000000000000000000000000000000000000" ]]; then
PREVIOUS_SHA=$(git rev-parse "$(git branch -r --sort=-committerdate | head -1 | xargs)")
fi
if [[ "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then if [[ "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then
INITIAL_COMMIT="true" PREVIOUS_SHA=$(git rev-parse "$CURRENT_SHA^1")
echo "::debug::Initial commit detected"
if [[ "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then
INITIAL_COMMIT="true"
echo "::debug::Initial commit detected"
fi
fi
if [[ -z "$PREVIOUS_SHA" ]]; then
echo "::error::Unable to locate a previous commit"
exit 1
fi fi
fi fi
else else
@ -132,11 +156,18 @@ if [[ -n "$PREVIOUS_SHA" && -n "$CURRENT_SHA" && "$PREVIOUS_SHA" == "$CURRENT_SH
exit 1 exit 1
fi fi
cat <<EOF >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=target_branch::$TARGET_BRANCH"
echo "::set-output name=current_branch::$CURRENT_BRANCH"
echo "::set-output name=previous_sha::$PREVIOUS_SHA"
echo "::set-output name=current_sha::$CURRENT_SHA"
else
cat <<EOF >> "$GITHUB_OUTPUT"
target_branch=$TARGET_BRANCH target_branch=$TARGET_BRANCH
current_branch=$CURRENT_BRANCH current_branch=$CURRENT_BRANCH
previous_sha=$PREVIOUS_SHA previous_sha=$PREVIOUS_SHA
current_sha=$CURRENT_SHA current_sha=$CURRENT_SHA
EOF EOF
fi
echo "::endgroup::" echo "::endgroup::"

View file

@ -1,24 +0,0 @@
#!/usr/bin/env bash
set -eu
if [[ -n $INPUT_PATH ]]; then
REPO_DIR="$GITHUB_WORKSPACE/$INPUT_PATH"
echo "Resolving repository path: $REPO_DIR"
if [[ ! -d "$REPO_DIR" ]]; then
echo "::error::Invalid repository path: $REPO_DIR"
exit 1
fi
cd "$REPO_DIR"
fi
if [[ -n "$INPUT_SINCE" ]]; then
BASE_SHA=$(git log --format="%H" --date=local --since="$INPUT_SINCE" --reverse | head -n 1)
if [[ -z "$BASE_SHA" ]]; then
echo "::warning::The BASE_SHA for date '$INPUT_SINCE' couldn't be determined."
fi
echo "base_sha=$BASE_SHA" >> "$GITHUB_OUTPUT"
elif [[ -n "$INPUT_BASE_SHA" ]]; then
echo "base_sha=$INPUT_BASE_SHA" >> "$GITHUB_OUTPUT"
fi

View file

@ -7,6 +7,8 @@ INPUT_SEPARATOR="${INPUT_SEPARATOR//'.'/'%2E'}"
INPUT_SEPARATOR="${INPUT_SEPARATOR//$'\n'/'%0A'}" INPUT_SEPARATOR="${INPUT_SEPARATOR//$'\n'/'%0A'}"
INPUT_SEPARATOR="${INPUT_SEPARATOR//$'\r'/'%0D'}" INPUT_SEPARATOR="${INPUT_SEPARATOR//$'\r'/'%0D'}"
GITHUB_OUTPUT=${GITHUB_OUTPUT:-""}
if [[ $INPUT_QUOTEPATH == "false" ]]; then if [[ $INPUT_QUOTEPATH == "false" ]]; then
git config --global core.quotepath off git config --global core.quotepath off
else else
@ -131,9 +133,17 @@ else
if [[ -n "${ALL_CHANGED}" ]]; then if [[ -n "${ALL_CHANGED}" ]]; then
echo "::debug::Matching changed files: ${ALL_CHANGED}" echo "::debug::Matching changed files: ${ALL_CHANGED}"
echo "any_changed=true" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=any_changed::true"
else
echo "any_changed=true" >> "$GITHUB_OUTPUT"
fi
else else
echo "any_changed=false" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=any_changed::false"
else
echo "any_changed=false" >> "$GITHUB_OUTPUT"
fi
fi fi
OTHER_CHANGED="" OTHER_CHANGED=""
@ -154,19 +164,38 @@ else
if [[ -n "${OTHER_CHANGED}" && "${OTHER_CHANGED}" != "[]" ]]; then if [[ -n "${OTHER_CHANGED}" && "${OTHER_CHANGED}" != "[]" ]]; then
echo "::debug::Non Matching changed files: ${OTHER_CHANGED}" echo "::debug::Non Matching changed files: ${OTHER_CHANGED}"
echo "only_changed=false" >> "$GITHUB_OUTPUT"
echo "other_changed_files=$OTHER_CHANGED" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=only_changed::false"
echo "::set-output name=other_changed_files::$OTHER_CHANGED"
else
echo "only_changed=false" >> "$GITHUB_OUTPUT"
echo "other_changed_files=$OTHER_CHANGED" >> "$GITHUB_OUTPUT"
fi
elif [[ -n "${ALL_CHANGED}" ]]; then elif [[ -n "${ALL_CHANGED}" ]]; then
echo "only_changed=true" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=only_changed::true"
else
echo "only_changed=true" >> "$GITHUB_OUTPUT"
fi
fi fi
ALL_OTHER_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMRD" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') ALL_OTHER_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMRD" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
if [[ -n "${ALL_MODIFIED}" ]]; then if [[ -n "${ALL_MODIFIED}" ]]; then
echo "::debug::Matching modified files: ${ALL_MODIFIED}" echo "::debug::Matching modified files: ${ALL_MODIFIED}"
echo "any_modified=true" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=any_modified::true"
else
echo "any_modified=true" >> "$GITHUB_OUTPUT"
fi
else else
echo "any_modified=false" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=any_modified::false"
else
echo "any_modified=false" >> "$GITHUB_OUTPUT"
fi
fi fi
OTHER_MODIFIED="" OTHER_MODIFIED=""
@ -187,19 +216,37 @@ else
if [[ -n "${OTHER_MODIFIED}" && "$OTHER_MODIFIED" != "[]" ]]; then if [[ -n "${OTHER_MODIFIED}" && "$OTHER_MODIFIED" != "[]" ]]; then
echo "::debug::Non Matching modified files: ${OTHER_MODIFIED}" echo "::debug::Non Matching modified files: ${OTHER_MODIFIED}"
echo "only_modified=false" >> "$GITHUB_OUTPUT"
echo "other_modified_files=$OTHER_MODIFIED" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=only_modified::false"
echo "::set-output name=other_modified_files::$OTHER_MODIFIED"
else
echo "only_modified=false" >> "$GITHUB_OUTPUT"
echo "other_modified_files=$OTHER_MODIFIED" >> "$GITHUB_OUTPUT"
fi
elif [[ -n "${ALL_MODIFIED}" ]]; then elif [[ -n "${ALL_MODIFIED}" ]]; then
echo "only_modified=true" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=only_modified::true"
else
echo "only_modified=true" >> "$GITHUB_OUTPUT"
fi
fi fi
ALL_OTHER_DELETED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" D | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') ALL_OTHER_DELETED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" D | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}')
if [[ -n "${DELETED}" ]]; then if [[ -n "${DELETED}" ]]; then
echo "::debug::Matching deleted files: ${DELETED}" echo "::debug::Matching deleted files: ${DELETED}"
echo "any_deleted=true" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=any_deleted::true"
else
echo "any_deleted=true" >> "$GITHUB_OUTPUT"
fi
else else
echo "any_deleted=false" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=any_deleted::false"
else
echo "any_deleted=false" >> "$GITHUB_OUTPUT"
fi
fi fi
OTHER_DELETED="" OTHER_DELETED=""
@ -220,10 +267,19 @@ else
if [[ -n "${OTHER_DELETED}" && "${OTHER_DELETED}" != "[]" ]]; then if [[ -n "${OTHER_DELETED}" && "${OTHER_DELETED}" != "[]" ]]; then
echo "::debug::Non Matching deleted files: ${OTHER_DELETED}" echo "::debug::Non Matching deleted files: ${OTHER_DELETED}"
echo "only_deleted=false" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "other_deleted_files=$OTHER_DELETED" >> "$GITHUB_OUTPUT" echo "::set-output name=only_deleted::false"
echo "::set-output name=other_deleted_files::$OTHER_DELETED"
else
echo "only_deleted=false" >> "$GITHUB_OUTPUT"
echo "other_deleted_files=$OTHER_DELETED" >> "$GITHUB_OUTPUT"
fi
elif [[ -n "${DELETED}" ]]; then elif [[ -n "${DELETED}" ]]; then
echo "only_deleted=true" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=only_deleted::true"
else
echo "only_deleted=true" >> "$GITHUB_OUTPUT"
fi
fi fi
if [[ "$INPUT_JSON" == "false" ]]; then if [[ "$INPUT_JSON" == "false" ]]; then
ADDED=$(echo "${ADDED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') ADDED=$(echo "${ADDED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
@ -267,7 +323,20 @@ if [[ $INPUT_INCLUDE_ALL_OLD_NEW_RENAMED_FILES == "true" ]]; then
echo "::debug::All old & new renamed files: $ALL_OLD_NEW_RENAMED" echo "::debug::All old & new renamed files: $ALL_OLD_NEW_RENAMED"
fi fi
cat <<EOF >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=added_files::$ADDED"
echo "::set-output name=copied_files::$COPIED"
echo "::set-output name=deleted_files::$DELETED"
echo "::set-output name=modified_files::$MODIFIED"
echo "::set-output name=renamed_files::$RENAMED"
echo "::set-output name=type_changed_files::$TYPE_CHANGED"
echo "::set-output name=unmerged_files::$UNMERGED"
echo "::set-output name=unknown_files::$UNKNOWN"
echo "::set-output name=all_changed_and_modified_files::$ALL_CHANGED_AND_MODIFIED"
echo "::set-output name=all_changed_files::$ALL_CHANGED"
echo "::set-output name=all_modified_files::$ALL_MODIFIED"
else
cat <<EOF >> "$GITHUB_OUTPUT"
added_files=$ADDED added_files=$ADDED
copied_files=$COPIED copied_files=$COPIED
deleted_files=$DELETED deleted_files=$DELETED
@ -280,8 +349,14 @@ all_changed_and_modified_files=$ALL_CHANGED_AND_MODIFIED
all_changed_files=$ALL_CHANGED all_changed_files=$ALL_CHANGED
all_modified_files=$ALL_MODIFIED all_modified_files=$ALL_MODIFIED
EOF EOF
fi
if [[ $INPUT_INCLUDE_ALL_OLD_NEW_RENAMED_FILES == "true" ]]; then if [[ $INPUT_INCLUDE_ALL_OLD_NEW_RENAMED_FILES == "true" ]]; then
echo "all_old_new_renamed_files=$ALL_OLD_NEW_RENAMED" >> "$GITHUB_OUTPUT" if [[ -z "$GITHUB_OUTPUT" ]]; then
echo "::set-output name=all_old_new_renamed_files::$ALL_OLD_NEW_RENAMED"
else
echo "all_old_new_renamed_files=$ALL_OLD_NEW_RENAMED" >> "$GITHUB_OUTPUT"
fi
fi fi
echo "::endgroup::" echo "::endgroup::"

View file

@ -1,24 +0,0 @@
#!/usr/bin/env bash
set -eu
if [[ -n $INPUT_PATH ]]; then
REPO_DIR="$GITHUB_WORKSPACE/$INPUT_PATH"
echo "Resolving repository path: $REPO_DIR"
if [[ ! -d "$REPO_DIR" ]]; then
echo "::error::Invalid repository path: $REPO_DIR"
exit 1
fi
cd "$REPO_DIR"
fi
if [[ -n "$INPUT_UNTIL" ]]; then
SHA=$(git log -1 --format="%H" --date=local --until="$INPUT_UNTIL")
if [[ -z "$SHA" ]]; then
echo "::warning::The SHA for date '$INPUT_UNTIL' couldn't be determined, falling back to the current sha."
fi
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
else
echo "sha=$INPUT_SHA" >> "$GITHUB_OUTPUT"
fi