Skip to content

Commit

Permalink
feat: add support for matching files in gitignore.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Dec 15, 2022
1 parent 58485b4 commit 9d9aba2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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: ' ',
Expand Down Expand Up @@ -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)
})
7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export async function run(): Promise<void> {
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
Expand Down Expand Up @@ -206,9 +209,9 @@ export async function run(): Promise<void> {

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 =>
![
Expand Down

0 comments on commit 9d9aba2

Please sign in to comment.