Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tj-actions/changed-files
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v36.1.0
Choose a base ref
...
head repository: tj-actions/changed-files
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v36.2.0
Choose a head ref
  • 18 commits
  • 18 files changed
  • 7 contributors

Commits on Jun 8, 2023

  1. Copy the full SHA
    7d1d4d2 View commit details
  2. chore: Update README.md (#1237)

    Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
    tj-actions-bot and repo-ranger[bot] authored Jun 8, 2023
    Copy the full SHA
    8ec721e View commit details
  3. Updated README.md (#1246)

    Co-authored-by: repo-ranger[bot] <repo-ranger[bot]@users.noreply.github.com>
    tj-actions-bot and repo-ranger[bot] authored Jun 8, 2023
    Copy the full SHA
    9333a5c View commit details
  4. Upgraded to v36.1.0 (#1245)

    Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
    Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
    3 people authored Jun 8, 2023
    Copy the full SHA
    ab84931 View commit details

Commits on Jun 9, 2023

  1. chore(deps): update dependency @types/uuid to v9.0.2 (#1247)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jun 9, 2023
    Copy the full SHA
    b60e479 View commit details
  2. chore: Update README.md

    jackton1 authored Jun 9, 2023
    Copy the full SHA
    b27dcc2 View commit details
  3. chore: Update README.md

    jackton1 authored Jun 9, 2023
    Copy the full SHA
    6d9ee62 View commit details

Commits on Jun 10, 2023

  1. Update action.yml

    jackton1 authored Jun 10, 2023
    Copy the full SHA
    7b64c76 View commit details
  2. Updated README.md (#1248)

    Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
    Co-authored-by: Tonye Jack <jtonye@ymail.com>
    3 people authored Jun 10, 2023
    Copy the full SHA
    752970e View commit details
  3. Updated README.md (#1249)

    Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
    tj-actions-bot and jackton1 authored Jun 10, 2023
    Copy the full SHA
    a625ca3 View commit details

Commits on Jun 11, 2023

  1. chore(deps): lock file maintenance (#1250)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jun 11, 2023
    Copy the full SHA
    c51a48d View commit details
  2. chore(deps): update tj-actions/verify-changed-files action to v15 (#1251

    )
    
    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jun 11, 2023
    Copy the full SHA
    417f924 View commit details

Commits on Jun 12, 2023

  1. chore(deps): lock file maintenance (#1252)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jun 12, 2023
    Copy the full SHA
    61845c2 View commit details

Commits on Jun 13, 2023

  1. Update action.yml

    jackton1 authored Jun 13, 2023
    Copy the full SHA
    17ca5bb View commit details
  2. Updated README.md (#1255)

    Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
    tj-actions-bot and jackton1 authored Jun 13, 2023
    Copy the full SHA
    2c6893c View commit details
  3. chore(deps): update typescript-eslint monorepo to v5.59.11 (#1253)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jun 13, 2023
    Copy the full SHA
    d0e3a7c View commit details

Commits on Jun 14, 2023

  1. chore(deps): update peter-evans/create-pull-request action to v5.0.2 (#…

    …1256)
    
    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Jun 14, 2023
    Copy the full SHA
    2d0b52f View commit details
  2. feat: switch to use name status (#1230)

    Co-authored-by: tj-actions[bot] <109116665+tj-actions-bot@users.noreply.github.com>
    Co-authored-by: GitHub Action <action@github.com>
    3 people authored Jun 14, 2023
    Copy the full SHA
    174a2a6 View commit details
Showing with 1,719 additions and 1,081 deletions.
  1. +2 −0 .eslintrc.json
  2. +1 −1 .github/workflows/submodule-sync.yml
  3. +1 −1 .github/workflows/sync-release-version.yml
  4. +1 −1 .github/workflows/test.yml
  5. +1 −1 .github/workflows/update-readme.yml
  6. +29 −0 HISTORY.md
  7. +25 −24 README.md
  8. +7 −7 action.yml
  9. +637 −133 dist/index.js
  10. +1 −1 dist/index.js.map
  11. +51 −0 dist/licenses.txt
  12. +5 −3 package.json
  13. +106 −23 src/changedFiles.ts
  14. +13 −2 src/commitSha.ts
  15. +85 −95 src/main.ts
  16. +64 −25 src/utils.ts
  17. +1 −1 test/test-è.txt
  18. +689 −763 yarn.lock
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -60,6 +60,8 @@
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",
"semi": "off",
"filenames/match-regex": [
"error",
2 changes: 1 addition & 1 deletion .github/workflows/submodule-sync.yml
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ jobs:
git submodule update --remote --recursive
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5.0.1
uses: peter-evans/create-pull-request@v5.0.2
with:
title: "Updated submodule"
labels: "merge when passing"
2 changes: 1 addition & 1 deletion .github/workflows/sync-release-version.yml
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ jobs:
- name: Run git-cliff
uses: tj-actions/git-cliff@v1
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5.0.1
uses: peter-evans/create-pull-request@v5.0.2
with:
base: "main"
labels: "merge when passing"
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ jobs:
yarn all
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v14
uses: tj-actions/verify-changed-files@v15
id: changed_files
if: github.event_name != 'push'
with:
2 changes: 1 addition & 1 deletion .github/workflows/update-readme.yml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ jobs:
uses: tj-actions/remark@v3

- name: Verify Changed files
uses: tj-actions/verify-changed-files@v14
uses: tj-actions/verify-changed-files@v15
id: verify_changed_files
with:
files: |
29 changes: 29 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Changelog

# [36.1.0](https://github.com/tj-actions/changed-files/compare/v36.0.18...v36.1.0) - (2023-06-08)

## <!-- 0 -->🚀 Features

- Improve warning message ([#1241](https://github.com/tj-actions/changed-files/issues/1241)) ([f41e41f](https://github.com/tj-actions/changed-files/commit/f41e41fa3fdcbdf47c5f73526be7d81e413f832e)) - (Tonye Jack)

## <!-- 1 -->🐛 Bug Fixes

- Bug with errors from fork prs ([#1239](https://github.com/tj-actions/changed-files/issues/1239)) ([e208eb4](https://github.com/tj-actions/changed-files/commit/e208eb429a6a5b3444af0a2099bdbbfcd705fae6)) - (Tonye Jack)
- Bug with only_(changed|modified|deleted) outputs ([#1238](https://github.com/tj-actions/changed-files/issues/1238)) ([6dc4095](https://github.com/tj-actions/changed-files/commit/6dc409580193a9e2e52aa4a647684c2ea5a99ddb)) - (Tonye Jack)

## <!-- 26 -->🔄 Update

- Update test.yml ([37e5be9](https://github.com/tj-actions/changed-files/commit/37e5be95e281cd60c1d89e92bb25242b37e9db3c)) - (Tonye Jack)

## <!-- 7 -->⚙️ Miscellaneous Tasks

- Fix bug with nx set shas ([#1244](https://github.com/tj-actions/changed-files/issues/1244)) ([fb20f4d](https://github.com/tj-actions/changed-files/commit/fb20f4d24890fadc539505b1746d260504b213d0)) - (Tonye Jack)
- Update test ([#1243](https://github.com/tj-actions/changed-files/issues/1243)) ([b2a0ba4](https://github.com/tj-actions/changed-files/commit/b2a0ba40a4106c5de8de8ac8b0732f404d084f00)) - (Tonye Jack)
- Update event name ([#1242](https://github.com/tj-actions/changed-files/issues/1242)) ([c467712](https://github.com/tj-actions/changed-files/commit/c467712045a1fb370c4f8a2ce40f93c718e7888e)) - (Tonye Jack)
- Update test.yml ([f490eea](https://github.com/tj-actions/changed-files/commit/f490eeaa59c0a3957b24214e86c462a2e9a6c7fa)) - (tj-actions[bot])
- Improve test coverage ([#1235](https://github.com/tj-actions/changed-files/issues/1235)) ([c784b6f](https://github.com/tj-actions/changed-files/commit/c784b6f1c4775e3db7ddc38d464ae017e41b1576)) - (Tonye Jack)

## <!-- 9 -->⬆️ Upgrades

- Upgraded to v36.0.18 ([#1234](https://github.com/tj-actions/changed-files/issues/1234))

Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([a522bdb](https://github.com/tj-actions/changed-files/commit/a522bdb715e8ee0e5814bc94f576ebc24cebbfd3)) - (tj-actions[bot])

# [36.0.18](https://github.com/tj-actions/changed-files/compare/v36.0.17...v36.0.18) - (2023-06-06)

## <!-- 0 -->🚀 Features
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ Retrieve all changed files and directories relative to a target branch, preceedi
> * For monorepos where pulling all the branch history might not be desired, you can omit [`actions/checkout`](https://github.com/actions/checkout#usage) - `fetch-depth` for `pull_request` events.
> * All multiline inputs should not use double or single quotes since the value is already a string seperated by a newline character. See [Examples](#examples) for more information.
> * Ensure that `persist-credentials` is set to `true` when configuring [`actions/checkout`](https://github.com/actions/checkout#usage) if `fetch-depth` isn't set to `0`.
> * For repositories that have PR's generated from forks when configuring [`actions/checkout`](https://github.com/actions/checkout#usage) set the `repository` to `${{ github.event.pull_request.head.repo.full_name }}`. See: [Example](https://github.com/tj-actions/changed-files/blob/main/.github/workflows/test.yml#L47-L51)
```yaml
name: CI
@@ -171,29 +172,29 @@ Support this project with a :star:
<!-- AUTO-DOC-OUTPUT:START - Do not remove or modify this section -->
| 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 (ACMRDTUX)* |
| all\_changed\_files | string | Returns all changed files i.e. <br>*a combination of all added, copied, modified and renamed files (ACMR)* |
| all\_modified\_files | string | Returns all changed files i.e. <br>*a combination of all added, copied, modified, renamed and deleted 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. i.e. <br>*using a combination of all added, copied, modified and renamed files (ACMR)*. |
| any\_deleted | string | Returns `true` when any of <br>the filenames provided using the <br>`files` input has been deleted. <br>(D) |
| any\_modified | string | Returns `true` when any of <br>the filenames provided using the <br>`files` input has been modified. <br>i.e. *using a combination of all added, copied, modified, renamed, and deleted files (ACMRD)*. |
| 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. i.e. *using a combination of all added, copied, modified and renamed files (ACMR)*. |
| only\_deleted | string | Returns `true` when only files <br>provided using the `files` input <br>has been deleted. (D) |
| only\_modified | string | Returns `true` when only files <br>provided using the `files` input <br>has been modified. (ACMRD). |
| other\_changed\_files | string | Returns all other changed files <br>not listed in the files <br>input i.e. *using a combination of all added, copied, modified 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 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 all added, copied, modified, and 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). |
| unknown\_files | string | Returns only files that are <br>Unknown (X). |
| unmerged\_files | string | Returns only files that are <br>Unmerged (U). |
| 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 (ACMRDTUX)* |
| all\_changed\_files | string | Returns all changed files i.e. <br>*a combination of all added, copied, modified and renamed files (ACMR)* |
| all\_modified\_files | string | Returns all changed files i.e. <br>*a combination of all added, copied, modified, renamed and deleted 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*` or `files_ignore*` inputs has changed. i.e. <br>*using a combination of all added, copied, modified and renamed files (ACMR)*. |
| any\_deleted | string | Returns `true` when any of <br>the filenames provided using the <br>`files*` or `files_ignore*` inputs has been deleted. <br>(D) |
| any\_modified | string | Returns `true` when any of <br>the filenames provided using the <br>`files*` or `files_ignore*` inputs has been modified. <br>i.e. *using a combination of all added, copied, modified, renamed, and deleted files (ACMRD)*. |
| 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*` or `files_ignore*` inputs <br>has changed. i.e. *using a combination of all added, copied, modified and renamed files (ACMR)*. |
| only\_deleted | string | Returns `true` when only files <br>provided using the `files*` or `files_ignore*` inputs <br>has been deleted. (D) |
| only\_modified | string | Returns `true` when only files <br>provided using the `files*` or `files_ignore*` inputs <br>has been modified. (ACMRD). |
| other\_changed\_files | string | Returns all other changed files <br>not listed in the files <br>input i.e. *using a combination of all added, copied, modified 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 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 all added, copied, modified, and 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). |
| 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 -->

@@ -231,7 +232,7 @@ Support this project with a :star:
| since | string | false | | Get changed files for commits <br>whose timestamp is older than <br>the given time. |
| since\_last\_remote\_commit | string | false | `"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 remote <br>commit of the current branch <br>for push events. |
| until | string | false | | Get changed files for commits <br>whose timestamp is earlier than <br>the given time. |
| write\_output\_files | string | false | `"false"` | Write outputs to files in <br>the `.github/outputs` folder by default. |
| write\_output\_files | string | false | `"false"` | Write outputs to the `output_dir` <br>defaults to `.github/outputs` folder. **NOTE:** <br>This creates a `.txt` file <br>by default and a `.json` <br>file if `json` is set <br>to `true`. |

<!-- AUTO-DOC-INPUT:END -->

14 changes: 7 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
@@ -110,7 +110,7 @@ inputs:
required: false
default: "false"
write_output_files:
description: "Write outputs to files in the `.github/outputs` folder by default."
description: "Write outputs to the `output_dir` defaults to `.github/outputs` folder. **NOTE:** This creates a `.txt` file by default and a `.json` file if `json` is set to `true`."
required: false
default: "false"
output_dir:
@@ -142,23 +142,23 @@ outputs:
all_changed_files:
description: "Returns all changed files i.e. *a combination of all added, copied, modified and renamed files (ACMR)*"
any_changed:
description: "Returns `true` when any of the filenames provided using the `files` input has changed. i.e. *using a combination of all added, copied, modified and renamed files (ACMR)*."
description: "Returns `true` when any of the filenames provided using the `files*` or `files_ignore*` inputs has changed. i.e. *using a combination of all added, copied, modified and renamed files (ACMR)*."
only_changed:
description: "Returns `true` when only files provided using the `files` input has changed. i.e. *using a combination of all added, copied, modified and renamed files (ACMR)*."
description: "Returns `true` when only files provided using the `files*` or `files_ignore*` inputs has changed. i.e. *using a combination of all added, copied, modified and renamed files (ACMR)*."
other_changed_files:
description: "Returns all other changed files not listed in the files input i.e. *using a combination of all added, copied, modified and renamed files (ACMR)*."
all_modified_files:
description: "Returns all changed files i.e. *a combination of all added, copied, modified, renamed and deleted files (ACMRD)*."
any_modified:
description: "Returns `true` when any of the filenames provided using the `files` input has been modified. i.e. *using a combination of all added, copied, modified, renamed, and deleted files (ACMRD)*."
description: "Returns `true` when any of the filenames provided using the `files*` or `files_ignore*` inputs has been modified. i.e. *using a combination of all added, copied, modified, renamed, and deleted files (ACMRD)*."
only_modified:
description: "Returns `true` when only files provided using the `files` input has been modified. (ACMRD)."
description: "Returns `true` when only files provided using the `files*` or `files_ignore*` inputs has been modified. (ACMRD)."
other_modified_files:
description: "Returns all other modified files not listed in the files input i.e. *a combination of all added, copied, modified, and deleted files (ACMRD)*"
any_deleted:
description: "Returns `true` when any of the filenames provided using the `files` input has been deleted. (D)"
description: "Returns `true` when any of the filenames provided using the `files*` or `files_ignore*` inputs has been deleted. (D)"
only_deleted:
description: "Returns `true` when only files provided using the `files` input has been deleted. (D)"
description: "Returns `true` when only files provided using the `files*` or `files_ignore*` inputs has been deleted. (D)"
other_deleted_files:
description: "Returns all other deleted files not listed in the files input i.e. *a combination of all deleted files (D)*"

770 changes: 637 additions & 133 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions dist/licenses.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -34,15 +34,17 @@
"dependencies": {
"@actions/core": "1.10.0",
"@actions/exec": "1.1.1",
"lodash": "^4.17.15",
"micromatch": "^4.0.5"
},
"devDependencies": {
"@types/jest": "29.5.2",
"@types/lodash": "^4.14.195",
"@types/micromatch": "^4.0.2",
"@types/node": "20.2.1",
"@types/uuid": "9.0.1",
"@typescript-eslint/eslint-plugin": "5.59.9",
"@typescript-eslint/parser": "5.59.9",
"@types/uuid": "9.0.2",
"@typescript-eslint/eslint-plugin": "5.59.11",
"@typescript-eslint/parser": "5.59.11",
"@vercel/ncc": "0.36.1",
"eslint": "8.42.0",
"eslint-plugin-github": "4.8.0",
129 changes: 106 additions & 23 deletions src/changedFiles.ts
Original file line number Diff line number Diff line change
@@ -4,11 +4,12 @@ import {DiffResult} from './commitSha'
import {Inputs} from './inputs'
import {
getDirnameMaxDepth,
gitDiff,
gitRenamedFiles,
gitSubmoduleDiffSHA,
jsonOutput
jsonOutput,
getAllChangedFiles
} from './utils'
import flatten from 'lodash/flatten'

export const getRenamedFiles = async ({
inputs,
@@ -68,30 +69,37 @@ export const getRenamedFiles = async ({
return renamedFiles.join(inputs.oldNewFilesSeparator)
}

export const getDiffFiles = async ({
inputs,
export enum ChangeTypeEnum {
Added = 'A',
Copied = 'C',
Deleted = 'D',
Modified = 'M',
Renamed = 'R',
TypeChanged = 'T',
Unmerged = 'U',
Unknown = 'X'
}

export type ChangedFiles = {
[key in ChangeTypeEnum]: string[]
}

export const getAllDiffFiles = async ({
workingDirectory,
hasSubmodule,
diffResult,
diffFilter,
filePatterns = [],
submodulePaths
}: {
inputs: Inputs
workingDirectory: string
hasSubmodule: boolean
diffResult: DiffResult
diffFilter: string
filePatterns?: string[]
submodulePaths: string[]
}): Promise<string> => {
let files = await gitDiff({
}): Promise<ChangedFiles> => {
const files = await getAllChangedFiles({
cwd: workingDirectory,
sha1: diffResult.previousSha,
sha2: diffResult.currentSha,
diff: diffResult.diff,
diffFilter,
filePatterns
diff: diffResult.diff
})

if (hasSubmodule) {
@@ -110,32 +118,107 @@ export const getDiffFiles = async ({
)

if (submoduleShaResult.currentSha && submoduleShaResult.previousSha) {
const submoduleFiles = await gitDiff({
const submoduleFiles = await getAllChangedFiles({
cwd: submoduleWorkingDirectory,
sha1: submoduleShaResult.previousSha,
sha2: submoduleShaResult.currentSha,
diff: diffResult.diff,
diffFilter,
isSubmodule: true,
filePatterns,
parentDir: submodulePath
})
files.push(...submoduleFiles)

for (const changeType of Object.keys(
submoduleFiles
) as ChangeTypeEnum[]) {
if (!files[changeType]) {
files[changeType] = []
}
files[changeType].push(...submoduleFiles[changeType])
}
}
}
}

if (inputs.dirNames) {
files = files.map(file =>
getDirnameMaxDepth({
return files
}

function* getChangeTypeFilesGenerator({
inputs,
changedFiles,
changeTypes
}: {
inputs: Inputs
changedFiles: ChangedFiles
changeTypes: ChangeTypeEnum[]
}): Generator<string> {
for (const changeType of changeTypes) {
const files = changedFiles[changeType] || []
for (const file of files) {
if (inputs.dirNames) {
yield getDirnameMaxDepth({
pathStr: file,
dirNamesMaxDepth: inputs.dirNamesMaxDepth,
excludeCurrentDir:
inputs.dirNamesExcludeRoot || inputs.dirNamesExcludeCurrentDir
})
} else {
yield file
}
}
}
}

export const getChangeTypeFiles = async ({
inputs,
changedFiles,
changeTypes
}: {
inputs: Inputs
changedFiles: ChangedFiles
changeTypes: ChangeTypeEnum[]
}): Promise<string> => {
const files = [
...new Set(getChangeTypeFilesGenerator({inputs, changedFiles, changeTypes}))
]

if (inputs.json) {
return jsonOutput({value: files, shouldEscape: inputs.escapeJson})
}

return files.join(inputs.separator)
}

function* getAllChangeTypeFilesGenerator({
inputs,
changedFiles
}: {
inputs: Inputs
changedFiles: ChangedFiles
}): Generator<string> {
for (const file of flatten(Object.values(changedFiles))) {
if (inputs.dirNames) {
yield getDirnameMaxDepth({
pathStr: file,
dirNamesMaxDepth: inputs.dirNamesMaxDepth,
excludeCurrentDir:
inputs.dirNamesExcludeRoot || inputs.dirNamesExcludeCurrentDir
})
)
files = [...new Set(files)]
} else {
yield file
}
}
}

export const getAllChangeTypeFiles = async ({
inputs,
changedFiles
}: {
inputs: Inputs
changedFiles: ChangedFiles
}): Promise<string> => {
const files = [
...new Set(getAllChangeTypeFilesGenerator({inputs, changedFiles}))
]

if (inputs.json) {
return jsonOutput({value: files, shouldEscape: inputs.escapeJson})
15 changes: 13 additions & 2 deletions src/commitSha.ts
Original file line number Diff line number Diff line change
@@ -370,11 +370,22 @@ export const getSHAForPullRequestEvent = async (

if (!previousSha) {
if (inputs.sinceLastRemoteCommit) {
previousSha = env.GITHUB_EVENT_BEFORE
previousSha =
env.GITHUB_EVENT_BEFORE ||
(await getRemoteBranchHeadSha({
cwd: workingDirectory,
branch: currentBranch
}))

if (
(await verifyCommitSha({sha: previousSha, cwd: workingDirectory})) !== 0
!previousSha ||
(previousSha &&
(await verifyCommitSha({sha: previousSha, cwd: workingDirectory})) !==
0)
) {
core.warning(
'Unable to locate the remote branch head sha. Falling back to the pull request base sha.'
)
previousSha = env.GITHUB_EVENT_PULL_REQUEST_BASE_SHA
}
} else {
180 changes: 85 additions & 95 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import * as core from '@actions/core'
import path from 'path'
import {getDiffFiles, getRenamedFiles} from './changedFiles'
import {
getAllChangeTypeFiles,
getAllDiffFiles,
getChangeTypeFiles,
getRenamedFiles,
ChangeTypeEnum
} from './changedFiles'
import {
DiffResult,
getSHAForPullRequestEvent,
getSHAForPushEvent,
DiffResult
getSHAForPushEvent
} from './commitSha'
import {getEnv} from './env'
import {getInputs} from './inputs'
import {
getFilePatterns,
getFilteredChangedFiles,
getSubmodulePath,
isRepoShallow,
setOutput,
@@ -105,31 +112,38 @@ export async function run(): Promise<void> {
inputs,
workingDirectory
})
core.debug(`File patterns: ${filePatterns}`)

const addedFiles = await getDiffFiles({
inputs,
const allDiffFiles = await getAllDiffFiles({
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'A',
filePatterns,
submodulePaths
})
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)

const allFilteredDiffFiles = await getFilteredChangedFiles({
allDiffFiles,
filePatterns
})
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`)

const addedFiles = await getChangeTypeFiles({
inputs,
changedFiles: allFilteredDiffFiles,
changeTypes: [ChangeTypeEnum.Added]
})
core.debug(`Added files: ${addedFiles}`)
await setOutput({
key: 'added_files',
value: addedFiles,
inputs
})

const copiedFiles = await getDiffFiles({
const copiedFiles = await getChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'C',
filePatterns,
submodulePaths
changedFiles: allFilteredDiffFiles,
changeTypes: [ChangeTypeEnum.Copied]
})
core.debug(`Copied files: ${copiedFiles}`)
await setOutput({
@@ -138,14 +152,10 @@ export async function run(): Promise<void> {
inputs
})

const modifiedFiles = await getDiffFiles({
const modifiedFiles = await getChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'M',
filePatterns,
submodulePaths
changedFiles: allFilteredDiffFiles,
changeTypes: [ChangeTypeEnum.Modified]
})
core.debug(`Modified files: ${modifiedFiles}`)
await setOutput({
@@ -154,14 +164,10 @@ export async function run(): Promise<void> {
inputs
})

const renamedFiles = await getDiffFiles({
const renamedFiles = await getChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'R',
filePatterns,
submodulePaths
changedFiles: allFilteredDiffFiles,
changeTypes: [ChangeTypeEnum.Renamed]
})
core.debug(`Renamed files: ${renamedFiles}`)
await setOutput({
@@ -170,14 +176,10 @@ export async function run(): Promise<void> {
inputs
})

const typeChangedFiles = await getDiffFiles({
const typeChangedFiles = await getChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'T',
filePatterns,
submodulePaths
changedFiles: allFilteredDiffFiles,
changeTypes: [ChangeTypeEnum.TypeChanged]
})
core.debug(`Type changed files: ${typeChangedFiles}`)
await setOutput({
@@ -186,14 +188,10 @@ export async function run(): Promise<void> {
inputs
})

const unmergedFiles = await getDiffFiles({
const unmergedFiles = await getChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'U',
filePatterns,
submodulePaths
changedFiles: allFilteredDiffFiles,
changeTypes: [ChangeTypeEnum.Unmerged]
})
core.debug(`Unmerged files: ${unmergedFiles}`)
await setOutput({
@@ -202,14 +200,10 @@ export async function run(): Promise<void> {
inputs
})

const unknownFiles = await getDiffFiles({
const unknownFiles = await getChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'X',
filePatterns,
submodulePaths
changedFiles: allFilteredDiffFiles,
changeTypes: [ChangeTypeEnum.Unknown]
})
core.debug(`Unknown files: ${unknownFiles}`)
await setOutput({
@@ -218,14 +212,9 @@ export async function run(): Promise<void> {
inputs
})

const allChangedAndModifiedFiles = await getDiffFiles({
const allChangedAndModifiedFiles = await getAllChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'ACDMRTUX',
filePatterns,
submodulePaths
changedFiles: allFilteredDiffFiles
})
core.debug(`All changed and modified files: ${allChangedAndModifiedFiles}`)
await setOutput({
@@ -234,14 +223,15 @@ export async function run(): Promise<void> {
inputs
})

const allChangedFiles = await getDiffFiles({
const allChangedFiles = await getChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'ACMR',
filePatterns,
submodulePaths
changedFiles: allFilteredDiffFiles,
changeTypes: [
ChangeTypeEnum.Added,
ChangeTypeEnum.Copied,
ChangeTypeEnum.Modified,
ChangeTypeEnum.Renamed
]
})
core.debug(`All changed files: ${allChangedFiles}`)
await setOutput({
@@ -256,13 +246,15 @@ export async function run(): Promise<void> {
inputs
})

const allOtherChangedFiles = await getDiffFiles({
const allOtherChangedFiles = await getChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'ACMR',
submodulePaths
changedFiles: allDiffFiles,
changeTypes: [
ChangeTypeEnum.Added,
ChangeTypeEnum.Copied,
ChangeTypeEnum.Modified,
ChangeTypeEnum.Renamed
]
})
core.debug(`All other changed files: ${allOtherChangedFiles}`)

@@ -289,14 +281,16 @@ export async function run(): Promise<void> {
inputs
})

const allModifiedFiles = await getDiffFiles({
const allModifiedFiles = await getChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'ACMRD',
filePatterns,
submodulePaths
changedFiles: allFilteredDiffFiles,
changeTypes: [
ChangeTypeEnum.Added,
ChangeTypeEnum.Copied,
ChangeTypeEnum.Modified,
ChangeTypeEnum.Renamed,
ChangeTypeEnum.Deleted
]
})
core.debug(`All modified files: ${allModifiedFiles}`)
await setOutput({
@@ -311,13 +305,16 @@ export async function run(): Promise<void> {
inputs
})

const allOtherModifiedFiles = await getDiffFiles({
const allOtherModifiedFiles = await getChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'ACMRD',
submodulePaths
changedFiles: allDiffFiles,
changeTypes: [
ChangeTypeEnum.Added,
ChangeTypeEnum.Copied,
ChangeTypeEnum.Modified,
ChangeTypeEnum.Renamed,
ChangeTypeEnum.Deleted
]
})

const otherModifiedFiles = allOtherModifiedFiles
@@ -343,14 +340,10 @@ export async function run(): Promise<void> {
inputs
})

const deletedFiles = await getDiffFiles({
const deletedFiles = await getChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'D',
filePatterns,
submodulePaths
changedFiles: allFilteredDiffFiles,
changeTypes: [ChangeTypeEnum.Deleted]
})
core.debug(`Deleted files: ${deletedFiles}`)
await setOutput({
@@ -365,13 +358,10 @@ export async function run(): Promise<void> {
inputs
})

const allOtherDeletedFiles = await getDiffFiles({
const allOtherDeletedFiles = await getChangeTypeFiles({
inputs,
workingDirectory,
hasSubmodule,
diffResult,
diffFilter: 'D',
submodulePaths
changedFiles: allDiffFiles,
changeTypes: [ChangeTypeEnum.Deleted]
})

const otherDeletedFiles = allOtherDeletedFiles
89 changes: 64 additions & 25 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import {createReadStream, promises as fs} from 'fs'
import mm from 'micromatch'
import * as path from 'path'
import {createInterface} from 'readline'
import {ChangedFiles, ChangeTypeEnum} from './changedFiles'

import {Inputs} from './inputs'

@@ -403,32 +404,28 @@ export const gitRenamedFiles = async ({
})
}

export const gitDiff = async ({
export const getAllChangedFiles = async ({
cwd,
sha1,
sha2,
diff,
diffFilter,
filePatterns = [],
isSubmodule = false,
parentDir = ''
}: {
cwd: string
sha1: string
sha2: string
diffFilter: string
diff: string
filePatterns?: string[]
isSubmodule?: boolean
parentDir?: string
}): Promise<string[]> => {
}): Promise<ChangedFiles> => {
const {exitCode, stdout, stderr} = await exec.getExecOutput(
'git',
[
'diff',
'--name-only',
'--name-status',
'--ignore-submodules=all',
`--diff-filter=${diffFilter}`,
`--diff-filter=ACDMRTUX`,
`${sha1}${diff}${sha2}`
],
{
@@ -437,6 +434,16 @@ export const gitDiff = async ({
silent: process.env.RUNNER_DEBUG !== '1'
}
)
const changedFiles: ChangedFiles = {
[ChangeTypeEnum.Added]: [],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
}

if (exitCode !== 0) {
if (isSubmodule) {
@@ -453,28 +460,60 @@ export const gitDiff = async ({
)
}

return []
return changedFiles
}

const files = stdout
.split('\n')
.filter(Boolean)
.map((p: string) => {
if (isSubmodule) {
return normalizePath(path.join(parentDir, p))
}
return normalizePath(p)
})
const lines = stdout.split('\n').filter(Boolean)

if (filePatterns.length === 0) {
return files
for (const line of lines) {
const [changeType, filePath] = line.split('\t')
const normalizedFilePath = isSubmodule
? normalizePath(path.join(parentDir, filePath))
: normalizePath(filePath)

if (changeType.startsWith('R')) {
changedFiles[ChangeTypeEnum.Renamed].push(normalizedFilePath)
} else {
changedFiles[changeType as ChangeTypeEnum].push(normalizedFilePath)
}
}
return changedFiles
}

return mm(files, filePatterns, {
dot: true,
windows: IS_WINDOWS,
noext: true
})
export const getFilteredChangedFiles = async ({
allDiffFiles,
filePatterns
}: {
allDiffFiles: ChangedFiles
filePatterns: string[]
}): Promise<ChangedFiles> => {
const changedFiles: ChangedFiles = {
[ChangeTypeEnum.Added]: [],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
}

for (const changeType of Object.keys(allDiffFiles)) {
const files = allDiffFiles[changeType as ChangeTypeEnum]
const hasFilePatterns = filePatterns.length > 0

if (hasFilePatterns) {
changedFiles[changeType as ChangeTypeEnum] = mm(files, filePatterns, {
dot: true,
windows: IS_WINDOWS,
noext: true
})
} else {
changedFiles[changeType as ChangeTypeEnum] = files
}
}

return changedFiles
}

export const gitLog = async ({
2 changes: 1 addition & 1 deletion test/test-è.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This is a test file with non ascii character in the filename.
This is a test file with non ASCII character in the filename.
1,452 changes: 689 additions & 763 deletions yarn.lock

Large diffs are not rendered by default.