Skip to content

Commit 7c3703b

Browse files
committed
Improve logs
1 parent 2beea40 commit 7c3703b

File tree

6 files changed

+110
-28
lines changed

6 files changed

+110
-28
lines changed

__tests__/monorepo.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { PackageJson } from 'type-fest'
44
import type { ActionInputs } from '../src/inputs'
55
import { listMonorepoProjects, type ProjectConfig } from '../src/monorepo'
66

7+
jest.mock('@actions/core')
8+
79
jest.mock('fs', () => {
810
const memfs: typeof import('memfs') = jest.requireActual('memfs')
911
return memfs.fs

dist/index.js

Lines changed: 63 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/annotations.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import * as core from '@actions/core'
22
import type { SourceFileIssue } from './issues'
33

44
export function createAnnotationsFromIssues(issues: SourceFileIssue[]): void {
5+
if (issues.length > 0) {
6+
core.info(`Creating annotations for ${issues.length} issues:`)
7+
}
8+
59
for (const issue of issues) {
610
const message = issue.message
711
const properties: core.AnnotationProperties = {

src/main.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ export async function run(
3434
let commentMdPath: string | undefined
3535

3636
if (inputs.monorepo) {
37-
core.debug('Running Code PushUp in monorepo mode')
37+
core.info('Running Code PushUp in monorepo mode')
3838
const projects = await listMonorepoProjects(inputs)
3939
const diffJsonPaths: string[] = []
4040
for (const project of projects) {
41-
core.debug(`Running Code PushUp on monorepo project ${project.name}`)
41+
core.info(`Running Code PushUp on monorepo project ${project.name}`)
4242
const comparisonFiles = await runOnProject(
4343
project,
4444
inputs,
@@ -67,7 +67,7 @@ export async function run(
6767
core.debug(`Uploaded report diff artifact (${size} bytes)`)
6868
}
6969
} else {
70-
core.debug('Running Code PushUp in standalone project mode')
70+
core.info('Running Code PushUp in standalone project mode')
7171
const comparisonFiles = await runOnProject(null, inputs, artifact, git)
7272
if (comparisonFiles) {
7373
commentMdPath = comparisonFiles.mdFilePath
@@ -77,7 +77,7 @@ export async function run(
7777
if (commentMdPath) {
7878
const commentId = await commentOnPR(commentMdPath, inputs)
7979
core.setOutput('comment-id', commentId)
80-
core.debug(`Commented on PR #${github.context.issue.number}`)
80+
core.info(`Commented on PR #${github.context.issue.number}`)
8181
}
8282
} catch (error) {
8383
core.setFailed(error instanceof Error ? error.message : `${error}`)
@@ -115,33 +115,39 @@ async function runOnProject(
115115
}
116116

117117
const { base } = github.context.payload.pull_request
118-
core.debug(`PR detected, preparing to compare base branch ${base.ref}`)
118+
core.info(`PR detected, preparing to compare base branch ${base.ref}`)
119119

120120
let prevReport: string
121121

122122
let cachedBaseReport: PersistedCliFiles | null = null
123123
if (inputs.artifacts) {
124124
cachedBaseReport = await downloadReportArtifact(artifact, base, inputs)
125-
core.debug(
126-
`Previous report artifact ${cachedBaseReport ? `found and downloaded to ${cachedBaseReport.jsonFilePath}` : `not found`}`
125+
core.info(
126+
`Previous report artifact ${cachedBaseReport ? 'found' : 'not found'}`
127127
)
128+
if (cachedBaseReport) {
129+
core.debug(
130+
`Previous report artifact downloaded to ${cachedBaseReport.jsonFilePath}`
131+
)
132+
}
128133
}
129134

130135
if (cachedBaseReport) {
131136
prevReport = await fs.readFile(cachedBaseReport.jsonFilePath, 'utf8')
132137
} else {
133138
await git.fetch('origin', base.ref, ['--depth=1'])
134139
await git.checkout(['-f', base.ref])
135-
core.debug(`Switched to base branch ${base.ref}`)
140+
core.info(`Switched to base branch ${base.ref}`)
136141

137142
try {
138-
await printConfig(ctx)
143+
await printConfig({ ...ctx, silent: !core.isDebug() })
139144
core.debug(
140145
`Executing print-config verified code-pushup installed in base branch ${base.ref}`
141146
)
142147
} catch (err) {
143-
core.debug(
144-
`Executing print-config failed, assuming code-pushup not installed in base branch ${base.ref} and skipping comparison - ${err}`
148+
core.debug(`Error from print-config - ${err}`)
149+
core.info(
150+
`Executing print-config failed, assuming code-pushup not installed in base branch ${base.ref} and skipping comparison`
145151
)
146152
return null
147153
}
@@ -151,7 +157,7 @@ async function runOnProject(
151157
core.debug(`Collected previous report at ${prevReportPath}`)
152158

153159
await git.checkout(['-f', '-'])
154-
core.debug('Switched back to current branch')
160+
core.info('Switched back to PR branch')
155161
}
156162

157163
const reportsDir = path.join(inputs.directory, '.code-pushup')
@@ -165,8 +171,9 @@ async function runOnProject(
165171
{ before: prevPath, after: currPath, label: project?.name },
166172
ctx
167173
)
174+
core.info('Compared reports and generated diff files')
168175
core.debug(
169-
`Compared reports and generated diff at ${comparisonFiles.jsonFilePath} and ${comparisonFiles.mdFilePath}`
176+
`Generated diff files at ${comparisonFiles.jsonFilePath} and ${comparisonFiles.mdFilePath}`
170177
)
171178

172179
if (inputs.annotations) {

src/monorepo/list-projects.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as core from '@actions/core'
12
import { glob } from 'fast-glob'
23
import { join } from 'node:path'
34
import type { ActionInputs } from '../inputs'
@@ -26,17 +27,33 @@ export async function listMonorepoProjects(
2627
inputs.monorepo === true
2728
? await detectMonorepoTool(options)
2829
: inputs.monorepo
30+
if (inputs.monorepo === true) {
31+
if (tool) {
32+
core.info(`Auto-detected monorepo tool ${tool}`)
33+
} else {
34+
core.info("Couldn't auto-detect any supported monorepo tool")
35+
}
36+
} else {
37+
core.info(`Using monorepo tool "${tool}" from inputs`)
38+
}
2939

3040
if (tool) {
3141
const handler = getToolHandler(tool)
32-
return handler.listProjects(options)
42+
const projects = await handler.listProjects(options)
43+
core.info(`Found ${projects.length} projects in ${tool} monorepo`)
44+
core.debug(`Projects: ${projects.map(({ name }) => name).join(', ')}`)
45+
return projects
3346
}
3447

3548
if (inputs.projects) {
3649
const directories = await glob(inputs.projects, {
3750
cwd: options.cwd,
3851
onlyDirectories: true
3952
})
53+
core.info(
54+
`Found ${directories.length} project folders matching "${inputs.projects}" from inputs`
55+
)
56+
core.debug(`Projects: ${directories.join(', ')}`)
4057
return directories.map(directory => ({
4158
name: directory,
4259
bin: inputs.bin,
@@ -45,6 +62,8 @@ export async function listMonorepoProjects(
4562
}
4663

4764
const packages = await listPackages(options.cwd)
65+
core.info(`Found ${packages.length} NPM packages in repository`)
66+
core.debug(`Projects: ${packages.map(({ name }) => name).join(', ')}`)
4867
return packages.map(({ name, directory }) => ({
4968
name,
5069
bin: inputs.bin,

0 commit comments

Comments
 (0)