Skip to content

Commit

Permalink
Handle errors with sed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Sep 1, 2021
1 parent 684c3a8 commit f4abeac
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ jobs:
echo "Your README.md has been modified ${{ steps.changed-files.outputs.modified_files }}."
shell:
bash
- name: Run changed-files with forward slash separator
id: changed-files-forward-slash
uses: ./
with:
separator: "/"
- name: Show output
run: |
echo "${{ toJSON(steps.changed-files-forward-slash.outputs) }}"
shell:
bash
- name: Run changed-files with pipe separator
id: changed-files-pipe
uses: ./
with:
separator: "|"
- name: Show output
run: |
echo "${{ toJSON(steps.changed-files-pipe.outputs) }}"
shell:
bash
- name: Run changed-files with comma separator
id: changed-files-comma
uses: ./
Expand Down
65 changes: 32 additions & 33 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ UNIQUE_FILES=$(echo "$INPUT_FILES" | tr " " "\n" | sort -u | xargs -0)

if [[ -z "$UNIQUE_FILES" ]]; then
echo "Getting diff..."
ADDED=$(git diff --diff-filter=A --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
COPIED=$(git diff --diff-filter=C --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
DELETED=$(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
MODIFIED=$(git diff --diff-filter=M --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
RENAMED=$(git diff --diff-filter=R --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
TYPE_CHANGED=$(git diff --diff-filter=T --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
UNMERGED=$(git diff --diff-filter=U --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
UNKNOWN=$(git diff --diff-filter=X --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
ALL_CHANGED=$(git diff --diff-filter="*ACDMRTUX" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
ALL_MODIFIED_FILES=$(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//")
ADDED=$(git diff --diff-filter=A --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
COPIED=$(git diff --diff-filter=C --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
DELETED=$(git diff --diff-filter=D --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
MODIFIED=$(git diff --diff-filter=M --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
RENAMED=$(git diff --diff-filter=R --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
TYPE_CHANGED=$(git diff --diff-filter=T --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
UNMERGED=$(git diff --diff-filter=U --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
UNKNOWN=$(git diff --diff-filter=X --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
ALL_CHANGED=$(git diff --diff-filter="*ACDMRTUX" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
ALL_MODIFIED_FILES=$(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")
else
ADDED_ARRAY=()
COPIED_ARRAY=()
Expand Down Expand Up @@ -114,28 +114,29 @@ else
ALL_MODIFIED_FILES_ARRAY+=($(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA" | grep -E "(${path})" | xargs -0 || true))
done

# shellcheck disable=SC2001
ADDED=$(echo "${ADDED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g' | tr " " "\n" | sort -u | xargs -0)
# shellcheck disable=SC2001
COPIED=$(echo "${COPIED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g' | tr " " "\n" | sort -u | xargs -0)
# shellcheck disable=SC2001
DELETED=$(echo "${DELETED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g' | tr " " "\n" | sort -u | xargs -0)
# shellcheck disable=SC2001
MODIFIED=$(echo "${MODIFIED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g' | tr " " "\n" | sort -u | xargs -0)
# shellcheck disable=SC2001
RENAMED=$(echo "${RENAMED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g' | tr " " "\n" | sort -u | xargs -0)
# shellcheck disable=SC2001
TYPE_CHANGED=$(echo "${TYPE_CHANGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g' | tr " " "\n" | sort -u | xargs -0)
# shellcheck disable=SC2001
UNMERGED=$(echo "${UNMERGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g' | tr " " "\n" | sort -u | xargs -0)
# shellcheck disable=SC2001
UNKNOWN=$(echo "${UNKNOWN_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g' | tr " " "\n" | sort -u | xargs -0)
# shellcheck disable=SC2001
ALL_CHANGED=$(echo "${ALL_CHANGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g' | tr " " "\n" | sort -u | xargs -0)
# shellcheck disable=SC2001
ALL_MODIFIED_FILES=$(echo "${ALL_MODIFIED_FILES_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g' | tr " " "\n" | sort -u | xargs -0)
ADDED=$(echo "${ADDED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " ")
COPIED=$(echo "${COPIED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " ")
DELETED=$(echo "${DELETED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " ")
MODIFIED=$(echo "${MODIFIED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " ")
RENAMED=$(echo "${RENAMED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " ")
TYPE_CHANGED=$(echo "${TYPE_CHANGED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " ")
UNMERGED=$(echo "${UNMERGED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " ")
UNKNOWN=$(echo "${UNKNOWN_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " ")
ALL_CHANGED=$(echo "${ALL_CHANGED_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " ")
ALL_MODIFIED_FILES=$(echo "${ALL_MODIFIED_FILES_ARRAY[*]}" | tr " " "\n" | sort -u | tr "\n" " ")
fi

ADDED=$(IFS=,;printf "%s" "${ADDED[*]}")
COPIED=$(IFS=,;printf "%s" "${COPIED[*]}")
DELETED=$(IFS=,;printf "%s" "${DELETED[*]}")
MODIFIED=$(IFS=,;printf "%s" "${MODIFIED[*]}")
RENAMED=$(IFS=,;printf "%s" "${RENAMED[*]}")
TYPE_CHANGED=$(IFS=,;printf "%s" "${TYPE_CHANGED[*]}")
UNMERGED=$(IFS=,;printf "%s" "${UNMERGED[*]}")
UNKNOWN=$(IFS=,;printf "%s" "${UNKNOWN[*]}")
ALL_CHANGED=$(IFS=,;printf "%s" "${ALL_CHANGED[*]}")
ALL_MODIFIED_FILES=$(IFS=,;printf "%s" "${ALL_MODIFIED_FILES[*]}")

echo "Added files: $ADDED"
echo "Copied files: $COPIED"
echo "Deleted files: $DELETED"
Expand All @@ -148,13 +149,11 @@ echo "All changed files: $ALL_CHANGED"
echo "All modified files: $ALL_MODIFIED_FILES"

if [[ -n "$UNIQUE_FILES" ]]; then
# shellcheck disable=SC2001
ALL_INPUT_FILES=$(echo "$UNIQUE_FILES" | tr "\n" " " | xargs -0)
ALL_OTHER_CHANGED_FILES=$(git diff --diff-filter="ACMR" --name-only "$PREVIOUS_SHA" "$CURRENT_SHA")

OTHER_CHANGED_FILES=$(echo "${ALL_OTHER_CHANGED_FILES[@]}" "${ALL_MODIFIED_FILES[@]}" | tr " " "\n" | sort | uniq -u | tr "\n" " " | xargs -0)

echo "Input files: ${ALL_INPUT_FILES[*]}"
echo "Input files: ${UNIQUE_FILES[*]}"
echo "Matching modified files: ${ALL_MODIFIED_FILES[*]}"

if [[ -n "$ALL_MODIFIED_FILES" ]]; then
Expand Down

0 comments on commit f4abeac

Please sign in to comment.