Skip to content

Commit

Permalink
Merge pull request #342 from tj-actions/fix/bug-with-excludes
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 authored Aug 22, 2022
2 parents 24813da + 11fbde6 commit f3aadad
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
yarn install
- name: Run eslint on changed files
uses: tj-actions/eslint-changed-files@v13
uses: tj-actions/eslint-changed-files@v13.2
with:
token: ${{ secrets.PAT_TOKEN }}
config_path: ".eslintrc.json"
Expand Down
36 changes: 29 additions & 7 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import * as core from '@actions/core'
import * as path from 'path'
import {promises as fs} from 'fs'
import * as core from "@actions/core";
import { run } from "../src/main";

import {normalizeSeparators, tempfile} from '../src/utils'
import {run} from '../src/main'

const {GITHUB_WORKSPACE} = process.env
import { normalizeSeparators, tempfile } from "../src/utils";

const defaultEnv = {
'INPUT_FILES-SEPARATOR': '\n',
Expand Down Expand Up @@ -59,6 +55,32 @@ test('returns the paths of the filtered files (input files, input source files)'
expect(core.setOutput).toHaveBeenNthCalledWith(1, 'paths', EXPECTED_FILENAMES)
})

test('returns the paths of the all other files (input files)', async () => {
mockedEnv({
...defaultEnv,
INPUT_FILES: '!__tests__\n!*.md\n!dist\n!jest\n!.*\n!src\n!lib',
})

const EXPECTED_FILENAMES = [
'LICENSE',
'action.yml',
'jest.config.js',
'package.json',
'renovate.json',
'tsconfig.json',
'yarn.lock'
]
.map(fName => normalizeSeparators(fName))
.join(process.env.INPUT_SEPARATOR)

// @ts-ignore
core.setOutput = jest.fn()

await run()

expect(core.setOutput).toHaveBeenNthCalledWith(1, 'paths', EXPECTED_FILENAMES)
})

test('returns the paths of the filtered files (input files)', async () => {
mockedEnv({
...defaultEnv,
Expand Down
18 changes: 12 additions & 6 deletions dist/index.js

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

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

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export async function run(): Promise<void> {
let filePatterns = files
.split(filesSeparator)
.filter(p => p !== '')
.map(p => path.join(workingDirectory, p))
.join('\n')

core.debug(`file patterns: ${filePatterns}`)
Expand All @@ -86,7 +85,6 @@ export async function run(): Promise<void> {
}
return p
})
.map(p => `!${path.join(workingDirectory, p.replace(/^!/, ''))}`)
.join('\n')

core.debug(`excluded file patterns: ${excludedFilePatterns}`)
Expand Down Expand Up @@ -137,9 +135,20 @@ export async function run(): Promise<void> {
}
}

filePatterns += `\n${DEFAULT_EXCLUDED_FILES.map(
p => `!${path.join(workingDirectory, p.replace(/^!/, ''))}`
).join('\n')}`
filePatterns += `\n${DEFAULT_EXCLUDED_FILES.join('\n')}`

filePatterns = [...new Set(filePatterns.split('\n').filter(p => p !== ''))]
.map(p => {
if (p.startsWith('!')) {
return `!${workingDirectory}${path.sep}${p.substring(1)}`
}
return path.join(workingDirectory, p)
})
.join('\n')

if (filePatterns.split('\n').filter(p => !p.startsWith('!')).length === 0) {
filePatterns = `**\n${filePatterns}`
}

const globOptions = {followSymbolicLinks}
const globber = await glob.create(filePatterns, globOptions)
Expand Down
4 changes: 0 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,5 @@ export function tempfile(extension = ''): string {
}

export function escapeString(value: string): string {
if (typeof value !== 'string') {
throw new TypeError(`Expected a string instead got: ${typeof value}`)
}

return value.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
}

0 comments on commit f3aadad

Please sign in to comment.