Skip to content

Commit

Permalink
add support for minimatch options
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmith committed Aug 29, 2021
1 parent 92d2b19 commit 0fb7d0d
Show file tree
Hide file tree
Showing 8 changed files with 6,373 additions and 4,715 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"rules": {
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"i18n-text/no-en": "off",
"no-unused-vars": "off",
// "@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": [
Expand Down
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"editor.formatOnSave": true
"editor.formatOnSave": true,
"cSpell.words": [
"nobrace",
"nocase",
"nocomment",
"noext",
"noglobstar",
"nonegate",
"nonull"
]
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Do you do deployments when you push a new tag? Do you ever have multiple deploym

## Inputs

> NOTE: In addition to the inputs defined below, you can also pass in any of the minimatch options defined [here](https://github.com/isaacs/minimatch#options). For example, if you want to see the `dot` property, set `dot: true`.
### glob

**description**: The glob(s) of the files to check for changes (uses [`minimatch`](https://github.com/isaacs/minimatch)). All file changes that don't match at least one of the globs are filtered out. If you want to provide multiple globs, use a `,` between each glob. Defaults to `**`.
Expand Down
50 changes: 34 additions & 16 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@ const runAndExpect = (
renamed?: string[]
modified?: string[]
},
firstTag: boolean,
glob?: string,
repository?: string
{
firstTag,
glob,
repository
}: {firstTag?: boolean; glob?: string; repository?: string} = {},
env?: Record<string, string>
): void => {
firstTag = firstTag ?? false
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecSyncOptions = {
env: {
...process.env,
GITHUB_REPOSITORY:
repository ?? 'jsmith/changes-since-last-tag-test-repo',
GITHUB_REF: `refs/tags/${tag}`,
INPUT_GLOB: glob
INPUT_GLOB: glob,
...env
}
}

Expand All @@ -36,9 +41,9 @@ const runAndExpect = (
} catch (e) {
// Ensure that the output is actually printed
// eslint-disable-next-line no-console
console.error(e.stdout.toString())
console.error((e as any).stdout.toString())
// eslint-disable-next-line no-console
console.error(e.stderr.toString())
console.error((e as any).stderr.toString())
throw e
}
const expected = Object.entries(changed).map(
Expand All @@ -58,23 +63,36 @@ const runAndExpect = (
for (const line of expected) {
if (!output.match(new RegExp(escapeRegExp(line)))) {
throw Error(
`Expected "${expected}" in output using options. See output below.\n${output}`
`Expected "${line}" in output using options. See output below.\n${output}`
)
}
}
}

// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
runAndExpect('v0.1.0', {}, true)
runAndExpect('v0.2.0', {added: ['src/b.txt']}, false)
runAndExpect('v0.2.0', {added: ['src/b.txt']}, false, 'other/**,src/**')
runAndExpect('v0.3.0', {modified: ['a.txt']}, false)
runAndExpect('v0.3.0', {}, false, 'src/**')
runAndExpect('v0.4.0', {removed: ['src/b.txt']}, false)
runAndExpect('v0.4.0', {removed: ['src/b.txt']}, false, '**/*.txt')
runAndExpect('v0.4.0', {}, false, '*.py,*.js')
runAndExpect('v0.5.0', {renamed: ['b.txt']}, false)
runAndExpect('v0.1.0', {}, {firstTag: true})
runAndExpect('v0.2.0', {added: ['src/b.txt']})
runAndExpect('v0.2.0', {added: ['src/b.txt']}, {glob: 'other/**,src/**'})
runAndExpect('v0.3.0', {modified: ['a.txt']})
runAndExpect('v0.3.0', {}, {glob: 'src/**'})
runAndExpect('v0.4.0', {removed: ['src/b.txt']})
runAndExpect('v0.4.0', {removed: ['src/b.txt']}, {glob: '**/*.txt'})
runAndExpect('v0.4.0', {}, {glob: '*.py,*.js'})
runAndExpect('v0.5.0', {renamed: ['b.txt']})

// Assert that you can pass the dot option down to minimatch
// Also assert that it doesn't work without the option and that it
// does work with the option
runAndExpect('v0.6.0', {added: []}, {})
runAndExpect(
'v0.6.0',
{added: ['.hide/me.txt']},
{},
{
INPUT_DOT: 'true'
}
)
})

// test('big repository', () => {
Expand Down
Loading

0 comments on commit 0fb7d0d

Please sign in to comment.