Skip to content

Commit

Permalink
now output all changed files in a single output
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmith committed Sep 13, 2020
1 parent f04f25a commit 3510bf2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ Ensure to set the step ID using the `id` attribute. See the [docs](https://docs.

### steps.<STED_ID>.outputs.added

**description**: The names of all of the added, modified, removed and renamed files (comma separated).
**example**: `a.txt, src/b.txt`

### steps.<STED_ID>.outputs.added

**description**: The names of the newly created files (comma separated).
**example**: `a.txt, src/b.txt`

Expand Down
4 changes: 4 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const runAndExpect = (
expected.push(`::set-output name=any_changed::${anyChanged}`)
expected.push(`::set-output name=first_tag::${firstTag}`)

const allFiles: string[] = []
for (const items of Object.values(changed)) allFiles.push(...(items ?? []))
expected.push(`::set-output name=files::${allFiles.join(', ')}`)

for (const line of expected) {
if (!output.match(new RegExp(escapeRegExp(line)))) {
throw Error(
Expand Down
7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ async function run(): Promise<void> {
.andThen(getChangedFiles)
.map(o => {
o.changedFiles = o.changedFiles.filter(file => {
// If every glob doesn't match, filter out the file
if (o.glob.every(glob => !minimatch(file.filename, glob))) return false
// If there isn't at least one match, filter out the file
if (!o.glob.some(glob => minimatch(file.filename, glob))) return false
core.debug(`Matched "${file.filename}"`)
return true
})
Expand All @@ -256,12 +256,15 @@ async function run(): Promise<void> {
.andThen(sortChangedFiles)
.andThen(({sorted, previousTag}) => {
let anyChanged = false
const allFiles: string[] = []
for (const status of filesTypes) {
anyChanged = anyChanged || sorted[status].length !== 0
core.debug(`Writing output ${status} with files ${sorted[status]}`)
core.setOutput(status, sorted[status].join(', '))
allFiles.push(...sorted[status])
}

core.setOutput('files', allFiles.join(', '))
core.setOutput('any_changed', anyChanged)
core.setOutput('first_tag', previousTag === undefined)
return ok({})
Expand Down

0 comments on commit 3510bf2

Please sign in to comment.