From 4d660a61d586f1581182c282a68c67385e695c36 Mon Sep 17 00:00:00 2001 From: Jared Forsyth Date: Wed, 4 Aug 2021 10:46:38 -0500 Subject: [PATCH 1/2] Respect env.ALL_CHANGED_FILES if present If it's absent, the fall back to the method that might give false positives. Issue: https://khanacademy.atlassian.net/browse/FEI-3796 --- git-changed-files.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/git-changed-files.js b/git-changed-files.js index b35e0f6..d28a20a 100644 --- a/git-changed-files.js +++ b/git-changed-files.js @@ -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>*/ => { 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 }, From 346eb25f834737b589e28957bb94ba6974e1e1e8 Mon Sep 17 00:00:00 2001 From: Jared Forsyth Date: Wed, 4 Aug 2021 11:08:17 -0500 Subject: [PATCH 2/2] format --- git-changed-files.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-changed-files.js b/git-changed-files.js index d28a20a..7e4816a 100644 --- a/git-changed-files.js +++ b/git-changed-files.js @@ -88,8 +88,8 @@ const gitChangedFiles = async ( // 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 files = JSON.parse(process.env.ALL_CHANGED_FILES); + return files.filter((path) => !isFileIgnored(cwd, path)); } const { stdout } = await execProm(