From fd30e95c05a3a33d8bb4620924975dce0e126aff Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 14 May 2022 14:33:40 -0400 Subject: [PATCH] Added support for returning old and new names of renamed files --- README.md | 8 ++++---- action.yml | 12 ++++++++++-- entrypoint.sh | 8 +++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 85fc018c..1d49fb90 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ Support this project with a :star: | Input | type | required | default | description | |:---------------------------------:|:----------------------:|:--------:|:---------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| | token | `string` | `false` | `${{ github.token }}` | [GITHUB\_TOKEN](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#using-the-github_token-in-a-workflow)
or a repo scoped
[Personal Access Token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) | -| separator | `string` | `true` | `' '` | Output string separator | +| separator | `string` | `false` | `' '` | Output string separator | | files | `string` OR `string[]` | `false` | | Check for changes
using only these
list of file(s)
(Defaults to the
entire repo) | | files\_separator | string | `false` | `'\n'` | Separator used to split the
`files` input | | files\_from\_source\_file | `string` | `false` | | Source file(s)
used to populate
the `files` input | @@ -138,9 +138,9 @@ Support this project with a :star: | sha | `string` | `true` | `${{ github.sha }}` | Specify a different
commit SHA
used for
comparing changes | | base\_sha | `string` | `false` | | Specify a different
base commit SHA
used for
comparing changes | | path | `string` | `false` | | Relative path under
`GITHUB_WORKSPACE`
to the repository | -| since\_last\_remote\_commit | `string` | `false` | `false` | Use the last commit on the remote
branch as the `base_sha`
(Defaults to the last commit
on the target branch for Pull requests
or the previous commit
on the current branch
for push events).
NOTE: This requires
`fetch-depth: 0`
with `actions/checkout@v2` | -| use\_fork\_point | `string` | `false` | `false` | Finds best common ancestor
between two commits
to use in a three-way merge
as the `base_sha`
See: [git merge-base](https://git-scm.com/docs/git-merge-base#Documentation/git-merge-base.txt---fork-point).
NOTE: This pulls the entire commit history of the base branch | -| quotepath | `string` | `false` | `true` | Output filenames completely verbatim by setting this to `false` | +| since\_last\_remote\_commit | `string` | `false` | `false` | Use the last commit on the remote
branch as the `base_sha`
(Defaults to the last commit
on the target branch for Pull requests
or the previous commit
on the current branch
for push events).
NOTE: This requires
`fetch-depth: 0`
with `actions/checkout@v2` | +| use\_fork\_point | `string` | `false` | `false` | Finds best common ancestor
between two commits
to use in a three-way merge
as the `base_sha`
See: [git merge-base](https://git-scm.com/docs/git-merge-base#Documentation/git-merge-base.txt---fork-point).
NOTE: This pulls the entire commit history of the base branch | +| quotepath | `string` | `false` | `true` | Output filenames completely verbatim by setting this to `false` | ## Example diff --git a/action.yml b/action.yml index d59b9339..e1d85d9c 100644 --- a/action.yml +++ b/action.yml @@ -5,12 +5,16 @@ author: tj-actions inputs: token: description: 'Github token' - required: true + required: false default: ${{ github.token }} separator: description: 'Split character for array output' - required: true + required: false default: " " + old_new_files_separator: + description: 'Split character for old and new filename pairs' + required: false + default: "," files_from_source_file: description: 'Source file(s) to populate the files input' required: false @@ -74,6 +78,9 @@ outputs: renamed_files: description: List of renamed files. value: ${{ steps.changed-files.outputs.renamed_files }} + old_new_files: + description: List of old and new names of renamed files. + value: ${{ steps.changed-files.outputs.old_new_files }} type_changed_files: description: List of files that had type changes. value: ${{ steps.changed-files.outputs.type_changed_files }} @@ -182,6 +189,7 @@ runs: INPUT_TARGET_BRANCH: ${{ steps.changed-files-diff-sha.outputs.target_branch }} INPUT_CURRENT_BRANCH: ${{ steps.changed-files-diff-sha.outputs.current_branch }} INPUT_QUOTEPATH: ${{ inputs.quotepath }} + INPUT_OLD_NEW_FILES_SEPARATOR: ${{ inputs.old_new_files_separator }} branding: icon: file-text diff --git a/entrypoint.sh b/entrypoint.sh index d15f1f0d..60d7b203 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,6 +16,7 @@ function get_diff() { base="$1" sha="$2" filter="$3" + type="${4:-name-only}" 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}')" @@ -28,7 +29,7 @@ function get_diff() { ) fi done < <(git submodule | awk '{print $2}') - git diff --diff-filter="$filter" --name-only --ignore-submodules=all "$base" "$sha" + git diff --diff-filter="$filter" --"$type" --ignore-submodules=all "$base" "$sha" } function get_renames() { @@ -78,6 +79,7 @@ if [[ -z "$INPUT_FILES_PATTERN_FILE" ]]; then ALL_CHANGED_AND_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "*ACDMRTUX" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') ALL_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMR" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') ALL_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMRD" | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') + OLD_NEW=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" R "name-status" | grep -E "^R" | awk -v d="$INPUT_SEPARATOR" '{print $2d$3}' | awk -v d="$INPUT_OLD_NEW_FILES_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') else ADDED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" A | grep -x -E -f "$INPUT_FILES_PATTERN_FILE" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') COPIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" C | grep -x -E -f "$INPUT_FILES_PATTERN_FILE" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') @@ -90,6 +92,7 @@ else ALL_CHANGED_AND_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "*ACDMRTUX" | grep -x -E -f "$INPUT_FILES_PATTERN_FILE" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') ALL_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMR" | grep -x -E -f "$INPUT_FILES_PATTERN_FILE" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') ALL_MODIFIED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMRD" | grep -x -E -f "$INPUT_FILES_PATTERN_FILE" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') + OLD_NEW=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" R "name-status" | grep -x -E -f "$INPUT_FILES_PATTERN_FILE" | awk -v d="$INPUT_SEPARATOR" '{print $2d$3}' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') ALL_OTHER_CHANGED=$(get_diff "$INPUT_PREVIOUS_SHA" "$INPUT_CURRENT_SHA" "ACMR" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') UNIQUE_ALL_CHANGED=$(echo "${ALL_CHANGED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk '!a[$0]++' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') @@ -192,6 +195,7 @@ else ALL_CHANGED_AND_MODIFIED=$(echo "${ALL_CHANGED_AND_MODIFIED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') ALL_CHANGED=$(echo "${ALL_CHANGED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') ALL_MODIFIED=$(echo "${ALL_MODIFIED}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') + OLD_NEW=$(echo "${OLD_NEW}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}') fi git remote remove temp_changed_files @@ -201,6 +205,7 @@ echo "Copied files: $COPIED" echo "Deleted files: $DELETED" echo "Modified files: $MODIFIED" echo "Renamed files: $RENAMED" +echo "Old new files: $OLD_NEW" echo "Type Changed files: $TYPE_CHANGED" echo "Unmerged files: $UNMERGED" echo "Unknown files: $UNKNOWN" @@ -213,6 +218,7 @@ 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=old_new_files::$OLD_NEW" echo "::set-output name=type_changed_files::$TYPE_CHANGED" echo "::set-output name=unmerged_files::$UNMERGED" echo "::set-output name=unknown_files::$UNKNOWN"