diff --git a/action.yml b/action.yml index f0c2efa41..a3d5f1e44 100644 --- a/action.yml +++ b/action.yml @@ -41,6 +41,10 @@ inputs: description: 'Indicates whether to include match directories' default: "true" required: true + match-gitignore-files: + description: 'Indicates whether to match files in `.gitignore`' + default: "true" + required: true separator: description: 'Separator used for the paths output.' required: true diff --git a/src/__tests__/main.test.ts b/src/__tests__/main.test.ts index 91c7bed6e..67f8d0c91 100644 --- a/src/__tests__/main.test.ts +++ b/src/__tests__/main.test.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core' import {run} from '../main' +// eslint-disable-next-line @typescript-eslint/no-unused-vars import {normalizeSeparators, tempfile} from '../utils' const defaultEnv = { @@ -10,6 +11,7 @@ const defaultEnv = { 'INPUT_EXCLUDED-FILES-FROM-SOURCE-FILE-SEPARATOR': '\n', 'INPUT_FOLLOW-SYMBOLIC-LINKS': 'true', 'INPUT_MATCH-DIRECTORIES': 'true', + 'INPUT_MATCH-GITIGNORE-FILES': 'true', 'INPUT_ESCAPE-PATHS': 'false', 'INPUT_HEAD-REPO-FORK': 'false', INPUT_SEPARATOR: ' ', @@ -266,3 +268,29 @@ test('includes patterns provided in the files input that are excluded in the .gi expect(core.setOutput).toHaveBeenNthCalledWith(2, 'paths', EXPECTED_FILENAMES) }) + +test('excludes patterns provided in the files input that are excluded in the .gitignore file when match-gitignore-files is false', async () => { + mockedEnv({ + ...defaultEnv, + INPUT_FILES: 'coverage/clover.xml', + 'INPUT_FILES-FROM-SOURCE-FILE': 'src/__tests__/source-files.txt', + 'INPUT_MATCH-GITIGNORE-FILES': 'false' + }) + + const EXPECTED_FILENAMES = [ + '.github/workflows/greetings.yml', + 'CODE_OF_CONDUCT.md', + 'CONTRIBUTING.md', + 'HISTORY.md', + 'README.md' + ] + .map(fName => normalizeSeparators(fName)) + .join(process.env.INPUT_SEPARATOR) + + // @ts-ignore + core.setOutput = jest.fn() + + await run() + + expect(core.setOutput).toHaveBeenNthCalledWith(2, 'paths', EXPECTED_FILENAMES) +}) diff --git a/src/main.ts b/src/main.ts index f942e5696..3d712cf37 100644 --- a/src/main.ts +++ b/src/main.ts @@ -52,6 +52,9 @@ export async function run(): Promise { const matchDirectories = core.getBooleanInput('match-directories', { required: false }) + const matchGitignoreFiles = core.getBooleanInput('match-gitignore-files', { + required: true + }) const separator = core.getInput('separator', { required: true, trimWhitespace: false @@ -206,9 +209,9 @@ export async function run(): Promise { const gitignoreMatchingFiles = await gitIgnoreGlobber.glob() - if (allInclusive) { + if (allInclusive || !matchGitignoreFiles) { paths = paths.filter(p => !gitignoreMatchingFiles.includes(p)) - } else { + } else if (matchGitignoreFiles) { paths = paths.filter( p => ![