3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2024-12-16 09:27:57 +00:00

feat: add support for using the last remote commit

This commit is contained in:
Tonye Jack 2022-11-06 19:50:53 -07:00
parent f009ea4a47
commit 1e46f60599
3 changed files with 90 additions and 61 deletions

View file

@ -125,27 +125,27 @@ Support this project with a :star:
| OUTPUT | TYPE | DESCRIPTION |
|--------------------------------|--------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| added\_files | string | Returns only files that are<br>Added (A). |
| all\_changed\_and\_modified\_files | string | Returns all changed and modified<br>files i.e. *a combination of<br>(ACMRDTUX)* |
| all\_changed\_files | string | Returns all changed files i.e.<br>*a combination of all added,<br>copied, modified and renamed files<br>(ACMR)* |
| all\_modified\_files | string | Returns all changed files i.e.<br>*a combination of all added,<br>copied, modified, renamed and deleted<br>files (ACMRD)*. |
| all\_old\_new\_renamed\_files | string | Returns only files that are<br>Renamed and list their old<br>and new names. **NOTE:** This<br>requires setting `include_all_old_new_renamed_files` to `true`<br>(R) |
| any\_changed | string | Returns `true` when any of<br>the filenames provided using the<br>`files` input has changed. If<br>no `files` have been specified,an<br>empty string `''` is returned.<br>i.e. *using a combination of<br>all added, copied, modified and<br>renamed files (ACMR)*. |
| any\_deleted | string | Returns `true` when any of<br>the filenames provided using the<br>`files` input has been deleted.<br>If no `files` have been<br>specified,an empty string `''` is<br>returned. (D) |
| any\_modified | string | Returns `true` when any of<br>the filenames provided using the<br>`files` input has been modified.<br>If no `files` have been<br>specified,an empty string `''` is<br>returned. i.e. *using a combination<br>of all added, copied, modified,<br>renamed, and deleted files (ACMRD)*.<br> |
| copied\_files | string | Returns only files that are<br>Copied (C). |
| deleted\_files | string | Returns only files that are<br>Deleted (D). |
| modified\_files | string | Returns only files that are<br>Modified (M). |
| only\_changed | string | Returns `true` when only files<br>provided using the `files` input<br>has changed. If no `files`<br>have been specified,an empty string<br>`''` is returned. i.e. *using<br>a combination of all added,<br>copied, modified and renamed files<br>(ACMR)*. |
| only\_deleted | string | Returns `true` when only files<br>provided using the `files` input<br>has been deleted. If no<br>`files` have been specified,an empty<br>string `''` is returned. (D)<br> |
| only\_modified | string | Returns `true` when only files<br>provided using the `files` input<br>has been modified. If no<br>`files` have been specified,an empty<br>string `''` is returned.(ACMRD). |
| other\_changed\_files | string | Returns all other changed files<br>not listed in the files<br>input i.e. *using a combination<br>of all added, copied, modified<br>and renamed files (ACMR)*. |
| other\_deleted\_files | string | Returns all other deleted files<br>not listed in the files<br>input i.e. *a combination of<br>all deleted files (D)* |
| other\_modified\_files | string | Returns all other modified files<br>not listed in the files<br>input i.e. *a combination of<br>all added, copied, modified, and<br>deleted files (ACMRD)* |
| renamed\_files | string | Returns only files that are<br>Renamed (R). |
| type\_changed\_files | string | Returns only files that have<br>their file type changed (T).<br> |
| unknown\_files | string | Returns only files that are<br>Unknown (X). |
| unmerged\_files | string | Returns only files that are<br>Unmerged (U). |
| added_files | string | Returns only files that are<br>Added (A). |
| all_changed_and_modified_files | string | Returns all changed and modified<br>files i.e. *a combination of<br>(ACMRDTUX)* |
| all_changed_files | string | Returns all changed files i.e.<br>*a combination of all added,<br>copied, modified and renamed files<br>(ACMR)* |
| all_modified_files | string | Returns all changed files i.e.<br>*a combination of all added,<br>copied, modified, renamed and deleted<br>files (ACMRD)*. |
| all_old_new_renamed_files | string | Returns only files that are<br>Renamed and list their old<br>and new names. **NOTE:** This<br>requires setting `include_all_old_new_renamed_files` to `true`<br>(R) |
| any_changed | string | Returns `true` when any of<br>the filenames provided using the<br>`files` input has changed. If<br>no `files` have been specified,an<br>empty string `''` is returned.<br>i.e. *using a combination of<br>all added, copied, modified and<br>renamed files (ACMR)*. |
| any_deleted | string | Returns `true` when any of<br>the filenames provided using the<br>`files` input has been deleted.<br>If no `files` have been<br>specified,an empty string `''` is<br>returned. (D) |
| any_modified | string | Returns `true` when any of<br>the filenames provided using the<br>`files` input has been modified.<br>If no `files` have been<br>specified,an empty string `''` is<br>returned. i.e. *using a combination<br>of all added, copied, modified,<br>renamed, and deleted files (ACMRD)*.<br> |
| copied_files | string | Returns only files that are<br>Copied (C). |
| deleted_files | string | Returns only files that are<br>Deleted (D). |
| modified_files | string | Returns only files that are<br>Modified (M). |
| only_changed | string | Returns `true` when only files<br>provided using the `files` input<br>has changed. If no `files`<br>have been specified,an empty string<br>`''` is returned. i.e. *using<br>a combination of all added,<br>copied, modified and renamed files<br>(ACMR)*. |
| only_deleted | string | Returns `true` when only files<br>provided using the `files` input<br>has been deleted. If no<br>`files` have been specified,an empty<br>string `''` is returned. (D)<br> |
| only_modified | string | Returns `true` when only files<br>provided using the `files` input<br>has been modified. If no<br>`files` have been specified,an empty<br>string `''` is returned.(ACMRD). |
| other_changed_files | string | Returns all other changed files<br>not listed in the files<br>input i.e. *using a combination<br>of all added, copied, modified<br>and renamed files (ACMR)*. |
| other_deleted_files | string | Returns all other deleted files<br>not listed in the files<br>input i.e. *a combination of<br>all deleted files (D)* |
| other_modified_files | string | Returns all other modified files<br>not listed in the files<br>input i.e. *a combination of<br>all added, copied, modified, and<br>deleted files (ACMRD)* |
| renamed_files | string | Returns only files that are<br>Renamed (R). |
| type_changed_files | string | Returns only files that have<br>their file type changed (T).<br> |
| unknown_files | string | Returns only files that are<br>Unknown (X). |
| unmerged_files | string | Returns only files that are<br>Unmerged (U). |
<!-- AUTO-DOC-OUTPUT:END -->
@ -153,28 +153,29 @@ Support this project with a :star:
<!-- AUTO-DOC-INPUT:START - Do not remove or modify this section -->
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
|-----------------------------------|--------|----------|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| base\_sha | string | false | | Specify a different base commit<br>SHA used for comparing changes<br> |
| diff\_relative | string | false | | Exclude changes outside the current<br>directory and show pathnames relative<br>to it. **NOTE:** This requires<br>you to specify the top<br>level directory via the `path`<br>input. |
| dir\_names | string | false | `"false"` | Output unique changed directories instead<br>of filenames. **NOTE:** This returns<br>`.` for changed files located<br>in the root of the<br>project. |
| fetch\_depth | string | false | `"40"` | Limit depth of the branch<br>history fetched. **NOTE**: This can<br>be adjusted to resolve errors<br>with insufficient history. |
| files | string | false | | File and directory patterns to<br>detect changes using only these<br>list of file(s) (Defaults to<br>the entire repo) **NOTE:** Multiline<br>file/directory patterns should not include<br>qoutes. |
| files\_from\_source\_file | string | false | | Source file(s) used to populate<br>the `files` input. |
| files\_ignore | string | false | | Ignore changes to these file(s)<br>**NOTE:** Multiline file/directory patterns should<br>not include qoutes. |
| files\_ignore\_from\_source\_file | string | false | | Source file(s) used to populate<br>the `files_ignore` input |
| files\_ignore\_separator | string | false | `"\n"` | Separator used to split the<br>`files-ignore` input |
| files\_separator | string | false | `"\n"` | Separator used to split the<br>`files` input |
| include\_all\_old\_new\_renamed\_files | string | false | `"false"` | Include `all_old_new_renamed_files` output. Note this<br>can generate a large output<br>See: [#501](https://github.com/tj-actions/changed-files/issues/501). |
| json | string | false | `"false"` | Output list of changed files<br>in a JSON formatted string<br>which can be used for<br>matrix jobs. |
| old\_new\_files\_separator | string | false | `" "` | Split character for multiple old<br>and new filename pairs. |
| old\_new\_separator | string | false | `","` | Split character for old and<br>new filename pairs. |
| path | string | false | `"."` | Specify a relative path under<br>`$GITHUB_WORKSPACE` to locate the repository.<br> |
| quotepath | string | false | `"true"` | Use non ascii characters to<br>match files and output the<br>filenames completely verbatim by setting<br>this to `false` |
| separator | string | false | `" "` | Split character for output strings<br> |
| sha | string | false | `"${{ github.sha }}"` | Specify a different commit SHA<br>used for comparing changes |
| since | string | false | | Get changed files for commits<br>whose timestamp is older than<br>the given time. |
| until | string | false | | Get changed files for commits<br>whose timestamp is earlier than<br>the given time. |
| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION |
|-----------------------------------|--------|----------|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| base_sha | string | false | | Specify a different base commit<br>SHA used for comparing changes<br> |
| diff_relative | string | false | | Exclude changes outside the current<br>directory and show pathnames relative<br>to it. **NOTE:** This requires<br>you to specify the top<br>level directory via the `path`<br>input. |
| dir_names | string | false | `"false"` | Output unique changed directories instead<br>of filenames. **NOTE:** This returns<br>`.` for changed files located<br>in the root of the<br>project. |
| fetch_depth | string | false | `"40"` | Limit depth of the branch<br>history fetched. **NOTE**: This can<br>be adjusted to resolve errors<br>with insufficient history. |
| files | string | false | | File and directory patterns to<br>detect changes using only these<br>list of file(s) (Defaults to<br>the entire repo) **NOTE:** Multiline<br>file/directory patterns should not include<br>qoutes. |
| files_from_source_file | string | false | | Source file(s) used to populate<br>the `files` input. |
| files_ignore | string | false | | Ignore changes to these file(s)<br>**NOTE:** Multiline file/directory patterns should<br>not include qoutes. |
| files_ignore_from_source_file | string | false | | Source file(s) used to populate<br>the `files_ignore` input |
| files_ignore_separator | string | false | `"\n"` | Separator used to split the<br>`files-ignore` input |
| files_separator | string | false | `"\n"` | Separator used to split the<br>`files` input |
| include_all_old_new_renamed_files | string | false | `"false"` | Include `all_old_new_renamed_files` output. Note this<br>can generate a large output<br>See: [#501](https://github.com/tj-actions/changed-files/issues/501). |
| json | string | false | `"false"` | Output list of changed files<br>in a JSON formatted string<br>which can be used for<br>matrix jobs. |
| old_new_files_separator | string | false | `" "` | Split character for multiple old<br>and new filename pairs. |
| old_new_separator | string | false | `","` | Split character for old and<br>new filename pairs. |
| path | string | false | `"."` | Specify a relative path under<br>`$GITHUB_WORKSPACE` to locate the repository.<br> |
| quotepath | string | false | `"true"` | Use non ascii characters to<br>match files and output the<br>filenames completely verbatim by setting<br>this to `false` |
| separator | string | false | `" "` | Split character for output strings<br> |
| sha | string | false | `"${{ github.sha }}"` | Specify a different commit SHA<br>used for comparing changes |
| since | string | false | | Get changed files for commits<br>whose timestamp is older than<br>the given time. |
| since_last_remote_commit | string | true | `"false"` | Use the last commit on<br>the remote branch as the<br>`base_sha`. Defaults to the last<br>non merge commit on the<br>target branch for pull request<br>events and the previous commit<br>of the current branch for<br>push events. |
| until | string | false | | Get changed files for commits<br>whose timestamp is earlier than<br>the given time. |
<!-- AUTO-DOC-INPUT:END -->

View file

@ -81,6 +81,10 @@ inputs:
description: "Limit depth of the branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history."
required: false
default: "40"
since_last_remote_commit:
description: "Use the last commit on the remote branch as the `base_sha`. Defaults to the last non merge commit on the target branch for pull request events and the previous commit of the current branch for push events."
required: true
default: "false"
outputs:
added_files:
@ -173,6 +177,7 @@ runs:
INPUT_UNTIL: ${{ inputs.until }}
INPUT_PATH: ${{ inputs.path }}
INPUT_FETCH_DEPTH: ${{ inputs.fetch_depth }}
INPUT_SINCE_LAST_REMOTE_COMMIT: ${{ inputs.since_last_remote_commit }}
- name: Glob match
uses: tj-actions/glob@v15
id: glob

View file

@ -82,12 +82,20 @@ if [[ -z $GITHUB_BASE_REF ]]; then
exit 1
fi
else
PREVIOUS_SHA=$(git rev-list -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$?
if [[ -z "$PREVIOUS_SHA" ]]; then
if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then
PREVIOUS_SHA=""
if [[ "$GITHUB_EVENT_FORCED" == "false" || -z "$GITHUB_EVENT_FORCED" ]]; then
PREVIOUS_SHA=$GITHUB_EVENT_BEFORE
fi
else
PREVIOUS_SHA=$(git rev-list -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$?
if [[ -z "$PREVIOUS_SHA" ]]; then
if [[ "$GITHUB_EVENT_FORCED" == "false" || -z "$GITHUB_EVENT_FORCED" ]]; then
PREVIOUS_SHA=$GITHUB_EVENT_BEFORE
fi
fi
fi
if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "0000000000000000000000000000000000000000" ]]; then
@ -133,21 +141,23 @@ else
CURRENT_BRANCH=$GITHUB_HEAD_REF
echo "Fetching remote refs..."
git fetch --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH"
git branch --track "$TARGET_BRANCH" origin/"$TARGET_BRANCH" 2>/dev/null || true
depth=$INPUT_FETCH_DEPTH
while [ -z "$( git merge-base "$TARGET_BRANCH" HEAD )" ]; do
git fetch --deepen="$depth" origin "$TARGET_BRANCH" HEAD;
depth=$((depth * 10))
max_depth=5000
if [[ $depth -gt $max_depth ]]; then
echo "::error::Unable to find merge-base between $TARGET_BRANCH and HEAD."
fi
done
if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "false" ]]; then
git fetch --depth="$INPUT_FETCH_DEPTH" origin +refs/heads/"$TARGET_BRANCH":refs/remotes/origin/"$TARGET_BRANCH"
git branch --track "$TARGET_BRANCH" origin/"$TARGET_BRANCH" 2>/dev/null || true
depth=$INPUT_FETCH_DEPTH
while [ -z "$( git merge-base "$TARGET_BRANCH" HEAD )" ]; do
git fetch --deepen="$depth" origin "$TARGET_BRANCH" HEAD;
depth=$((depth * 10))
max_depth=5000
if [[ $depth -gt $max_depth ]]; then
echo "::error::Unable to find merge-base between $TARGET_BRANCH and HEAD."
fi
done
fi
echo "::debug::Getting HEAD SHA..."
if [[ -n "$INPUT_UNTIL" ]]; then
@ -178,7 +188,20 @@ else
fi
if [[ -z $INPUT_BASE_SHA ]]; then
PREVIOUS_SHA=$(git rev-list --no-merges -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$?
if [[ "$INPUT_SINCE_LAST_REMOTE_COMMIT" == "true" ]]; then
PREVIOUS_SHA=""
if [[ "$GITHUB_EVENT_FORCED" == "false" || -z "$GITHUB_EVENT_FORCED" ]]; then
PREVIOUS_SHA=$GITHUB_EVENT_BEFORE
fi
if [[ -z "$PREVIOUS_SHA" || "$PREVIOUS_SHA" == "0000000000000000000000000000000000000000" ]]; then
PREVIOUS_SHA=$(git rev-list --no-merges -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$?
fi
else
PREVIOUS_SHA=$(git rev-list --no-merges -n 1 "$TARGET_BRANCH" 2>&1) && exit_status=$? || exit_status=$?
fi
if [[ -z "$PREVIOUS_SHA" ]]; then
PREVIOUS_SHA=$GITHUB_EVENT_PULL_REQUEST_BASE_SHA && exit_status=$? || exit_status=$?
fi