From cdef9e913d77f3e6b98c833ae61dc9d808c318ed Mon Sep 17 00:00:00 2001 From: Jacob Smith Date: Sun, 13 Sep 2020 10:55:15 -0300 Subject: [PATCH] adding debug --- __tests__/main.test.ts | 16 ++++++++++++++-- src/main.ts | 37 +++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index fa492aa..42e8df2 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -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 } @@ -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' +// ) +// }) diff --git a/src/main.ts b/src/main.ts index d6f7004..6840c57 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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, @@ -175,6 +183,7 @@ function getChangedFiles< type: 'error' }) ).map(res => { + core.debug(`Found ${res.length} changed files`) return { ...o, changedFiles: res @@ -199,14 +208,6 @@ const isFileType = (status: string): status is FileType => export function sortChangedFiles( o: T ): Result { - core.debug( - `Here are the files I am changing: ${JSON.stringify( - o.changedFiles, - null, - 2 - )}` - ) - const sorted: SortedFiles = { added: [], removed: [], @@ -230,20 +231,13 @@ export function sortChangedFiles( }) } -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 { 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 @@ -251,6 +245,14 @@ async function run(): Promise { 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) @@ -259,7 +261,6 @@ async function run(): Promise { 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]) } @@ -273,7 +274,7 @@ async function run(): Promise { 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}`) }