Skip to content

Commit

Permalink
Respect env.ALL_CHANGED_FILES if present (#14)
Browse files Browse the repository at this point in the history
## Summary:
If it's absent, the fall back to the method that might give false positives.

Issue: https://khanacademy.atlassian.net/browse/FEI-3796

## Test plan:
This pull-request shows the new code in action https://github.com/Khan/eslint-action/pull/27/files

Author: jaredly

Reviewers: jeresig, jaredly

Required Reviewers: 

Approved by: jeresig

Checks: ⌛ autofix, ⌛ lint_and_unit

Pull request URL: #14
  • Loading branch information
jaredly authored Aug 4, 2021
1 parent 6d8556b commit b78e2ab
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions git-changed-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,36 @@ const isFileIgnored = (workingDirectory, file) => {
/**
* This lists the files that have changed when compared to `base` (a git ref),
* limited to the files that are a descendent of `cwd`.
* It also respects '.gitattributes', filtering out files that have been marked
* as "binary" or "linguist-generated=true".
*/
const gitChangedFiles = async (
base /*:string*/,
cwd /*:string*/,
) /*: Promise<Array<string>>*/ => {
cwd = path.resolve(cwd);

// Github actions jobs can run the following steps to get a fully accurate
// changed files list. Otherwise, we fallback to a simple diff between the
// current and base branch, which might give false positives if the base
// is ahead of the current branch.
//
// - name: Get All Changed Files
// uses: jaredly/get-changed-files@absolute
// id: changed
// with:
// format: 'json'
// absolute: true
//
// - uses: allenevans/set-env@v2.0.0
// with:
// ALL_CHANGED_FILES: '${{ steps.changed.outputs.added_modified }}'
//
if (process.env.ALL_CHANGED_FILES) {
const files = JSON.parse(process.env.ALL_CHANGED_FILES);
return files.filter((path) => !isFileIgnored(cwd, path));
}

const { stdout } = await execProm(
`git diff --name-only ${base} --relative`,
{ cwd, encoding: 'utf8', rejectOnError: true },
Expand Down

0 comments on commit b78e2ab

Please sign in to comment.