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

feat: remove duplicate files add back support for deprecated set-output #691

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -119,6 +119,34 @@ jobs:
shell:
bash

test-unset-github-output-env:
name: Test unset GITHUB_OUTPUT env
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: 0

- name: Run changed-files with unset GITHUB_OUTPUT env
id: changed-files
continue-on-error: true
uses: ./
env:
GITHUB_OUTPUT: ""

- 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 }}
Expand Down Expand Up @@ -335,6 +363,7 @@ jobs:
continue-on-error: true
with:
since: "2022-08-19"
target_branch_fetch_depth: "20000"
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-since.outputs) }}'
Expand All @@ -346,6 +375,7 @@ jobs:
continue-on-error: true
with:
until: "2022-08-20"
target_branch_fetch_depth: "20000"
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-until.outputs) }}'
Expand Down
33 changes: 4 additions & 29 deletions action.yml
Expand Up @@ -150,33 +150,6 @@ outputs:
runs:
using: "composite"
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: |
# "Calculating the previous and current SHA..."
bash $GITHUB_ACTION_PATH/diff-sha.sh
Expand All @@ -193,8 +166,10 @@ runs:
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_SHA: ${{ steps.sha.outputs.sha }}
INPUT_BASE_SHA: ${{ steps.base-sha.outputs.base_sha }}
INPUT_SHA: ${{ inputs.sha }}
INPUT_BASE_SHA: ${{ inputs.base_sha }}
INPUT_SINCE: ${{ inputs.since }}
INPUT_UNTIL: ${{ inputs.until }}
INPUT_PATH: ${{ inputs.path }}
INPUT_TARGET_BRANCH_FETCH_DEPTH: ${{ inputs.target_branch_fetch_depth }}
- name: Glob match
Expand Down
58 changes: 45 additions & 13 deletions diff-sha.sh
Expand Up @@ -3,6 +3,7 @@
set -eu

INITIAL_COMMIT="false"
GITHUB_OUTPUT=${GITHUB_OUTPUT:-""}

echo "::group::changed-files-diff-sha"

Expand Down Expand Up @@ -40,7 +41,16 @@ fi
echo "::debug::Getting HEAD SHA..."

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
CURRENT_SHA=$INPUT_SHA; exit_status=$?
fi
Expand All @@ -63,22 +73,37 @@ if [[ -z $GITHUB_BASE_REF ]]; 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=$?
PREVIOUS_SHA=""

if [[ "$GITHUB_EVENT_FORCED" == "false" ]]; then
PREVIOUS_SHA=$GITHUB_EVENT_BEFORE
fi
if [[ -n "$INPUT_SINCE" ]]; then
PREVIOUS_SHA=$(git log --format="%H" --date=local --since="$INPUT_SINCE" --reverse | head -n 1)

if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "0000000000000000000000000000000000000000" ]]; then
PREVIOUS_SHA=$(git rev-parse "$(git branch -r --sort=-committerdate | head -1 | xargs)")
fi
if [[ -z "$PREVIOUS_SHA" ]]; then
echo "::error::Unable to locate a previous commit for the specified date: $INPUT_SINCE"
exit 1
fi
else
PREVIOUS_SHA=""

if [[ "$PREVIOUS_SHA" == "$CURRENT_SHA" ]]; then
PREVIOUS_SHA=$(git rev-parse "$CURRENT_SHA^1")
if [[ "$GITHUB_EVENT_FORCED" == "false" ]]; then
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
INITIAL_COMMIT="true"
echo "::debug::Initial commit detected"
PREVIOUS_SHA=$(git rev-parse "$CURRENT_SHA^1")

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
else
Expand Down Expand Up @@ -132,11 +157,18 @@ if [[ -n "$PREVIOUS_SHA" && -n "$CURRENT_SHA" && "$PREVIOUS_SHA" == "$CURRENT_SH
exit 1
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
current_branch=$CURRENT_BRANCH
previous_sha=$PREVIOUS_SHA
current_sha=$CURRENT_SHA
EOF
fi

echo "::endgroup::"
24 changes: 0 additions & 24 deletions get-base-sha.sh

This file was deleted.

109 changes: 92 additions & 17 deletions get-changed-paths.sh
Expand Up @@ -7,6 +7,8 @@ INPUT_SEPARATOR="${INPUT_SEPARATOR//'.'/'%2E'}"
INPUT_SEPARATOR="${INPUT_SEPARATOR//$'\n'/'%0A'}"
INPUT_SEPARATOR="${INPUT_SEPARATOR//$'\r'/'%0D'}"

GITHUB_OUTPUT=${GITHUB_OUTPUT:-""}

if [[ $INPUT_QUOTEPATH == "false" ]]; then
git config --global core.quotepath off
else
Expand Down Expand Up @@ -131,9 +133,17 @@ else

if [[ -n "${ALL_CHANGED}" ]]; then
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
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

OTHER_CHANGED=""
Expand All @@ -154,19 +164,38 @@ else

if [[ -n "${OTHER_CHANGED}" && "${OTHER_CHANGED}" != "[]" ]]; then
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
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

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

OTHER_MODIFIED=""
Expand All @@ -187,19 +216,37 @@ else

if [[ -n "${OTHER_MODIFIED}" && "$OTHER_MODIFIED" != "[]" ]]; then
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
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

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

OTHER_DELETED=""
Expand All @@ -220,10 +267,19 @@ else

if [[ -n "${OTHER_DELETED}" && "${OTHER_DELETED}" != "[]" ]]; then
echo "::debug::Non Matching deleted files: ${OTHER_DELETED}"
echo "only_deleted=false" >> "$GITHUB_OUTPUT"
echo "other_deleted_files=$OTHER_DELETED" >> "$GITHUB_OUTPUT"
if [[ -z "$GITHUB_OUTPUT" ]]; then
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
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
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}')
Expand Down Expand Up @@ -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"
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
copied_files=$COPIED
deleted_files=$DELETED
Expand All @@ -280,8 +349,14 @@ all_changed_and_modified_files=$ALL_CHANGED_AND_MODIFIED
all_changed_files=$ALL_CHANGED
all_modified_files=$ALL_MODIFIED
EOF
fi

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

echo "::endgroup::"