Skip to content

Commit

Permalink
adding debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmith committed Sep 13, 2020
1 parent 3510bf2 commit cdef9e9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
16 changes: 14 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ const runAndExpect = (
modified?: string[]
},
firstTag: boolean,
glob?: string
glob?: string,
repository?: string
): void => {
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecSyncOptions = {
env: {
...process.env,
GITHUB_REPOSITORY: 'jsmith/changes-since-last-tag-test-repo',
GITHUB_REPOSITORY:
repository ?? 'jsmith/changes-since-last-tag-test-repo',
GITHUB_REF: `refs/tags/${tag}`,
INPUT_GLOB: glob
}
Expand Down Expand Up @@ -74,3 +76,13 @@ test('test runs', () => {
runAndExpect('v0.4.0', {}, false, '*.py,*.js')
runAndExpect('v0.5.0', {renamed: ['b.txt']}, false)
})

// test('big repository', () => {
// runAndExpect(
// 'v0.5.0',
// {},
// false,
// 'packages/app/**,packages/functions/**,packages/firestore.rules,packages/storage.rules,packages/storage.json,packages/indexes.json',
// 'jsmith/relar'
// )
// })
37 changes: 19 additions & 18 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,15 @@ function getPreviousTag<
})
}

// This could be undefined
const previousTag = res[index + 1]

if (previousTag) {
core.debug(`Comparing ${previousTag}...${o.tag}`)
} else {
core.debug(`${o.tag} is the first tag`)
}

return ok({
...o,
currentTag: o.tag,
Expand Down Expand Up @@ -175,6 +183,7 @@ function getChangedFiles<
type: 'error'
})
).map(res => {
core.debug(`Found ${res.length} changed files`)
return {
...o,
changedFiles: res
Expand All @@ -199,14 +208,6 @@ const isFileType = (status: string): status is FileType =>
export function sortChangedFiles<T extends {changedFiles: GitHubFile[]}>(
o: T
): Result<T & {sorted: SortedFiles}, RuntimeError> {
core.debug(
`Here are the files I am changing: ${JSON.stringify(
o.changedFiles,
null,
2
)}`
)

const sorted: SortedFiles = {
added: [],
removed: [],
Expand All @@ -230,27 +231,28 @@ export function sortChangedFiles<T extends {changedFiles: GitHubFile[]}>(
})
}

export function writeOutput(key: string, files: string[]): void {
const fileName = key === 'files' ? key : `files_${key}`
core.debug(
`Writing output ${fileName} with files ${JSON.stringify(files, null, 2)}`
)
core.setOutput(fileName, files.join(', '))
}

async function run(): Promise<void> {
const result = await getInputs()
.andThen(initClient)
.asyncAndThen(getPreviousTag)
.andThen(getChangedFiles)
.map(o => {
const previousLength = o.changedFiles.length
o.changedFiles = o.changedFiles.filter(file => {
// 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
})

core.debug(
`Filtered out ${
previousLength - o.changedFiles.length
} file(s) using given blob`
)

core.debug(`There are ${o.changedFiles.length} files remaining`)

return o
})
.andThen(sortChangedFiles)
Expand All @@ -259,7 +261,6 @@ async function run(): Promise<void> {
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])
}
Expand All @@ -273,7 +274,7 @@ async function run(): Promise<void> {
if (result.isErr()) {
let error: string | undefined
try {
error = JSON.stringify(result.error)
error = JSON.stringify(result.error.error)
} catch (e) {
core.error(`Unable to stringify error object: ${result.error}`)
}
Expand Down

0 comments on commit cdef9e9

Please sign in to comment.