Skip to content

Commit 7e986bb

Browse files
committed
fix: improve logging & remove try/catch block preventing error
1 parent efd7f1e commit 7e986bb

File tree

4 files changed

+139
-133
lines changed

4 files changed

+139
-133
lines changed

dist/index.js

Lines changed: 58 additions & 56 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/main.ts

Lines changed: 69 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -21,99 +21,93 @@ export async function run(
2121
getOctokit = github.getOctokit,
2222
git = simpleGit()
2323
): Promise<void> {
24-
try {
25-
const inputs = parseInputs()
26-
const options = createOptions(inputs)
24+
const inputs = parseInputs()
25+
const options = createOptions(inputs)
2726

28-
const [nodeMajorString] = (
29-
process.version.startsWith('v')
30-
? process.version.slice(1)
31-
: process.version
32-
).split('.')
33-
const majorVersion = parseInt(nodeMajorString, 10)
34-
const isUnsupportedVersion = majorVersion < 20
27+
if (options.debug) {
28+
core.info(
29+
`${LOG_PREFIX} Debug in actions in enabled, setting CP_VERBOSE env variable to true`
30+
)
31+
process.env['CP_VERBOSE'] = 'true'
32+
}
3533

36-
if (isUnsupportedVersion) {
37-
core.warning(
38-
`${LOG_PREFIX} Internal runner is using unsupported NodeJS version ${process.version}`
39-
)
40-
} else if (options.debug) {
41-
core.info(
42-
`${LOG_PREFIX} Internal runner is using NodeJS version ${process.version}`
43-
)
44-
}
34+
const [nodeMajorString] = (
35+
process.version.startsWith('v') ? process.version.slice(1) : process.version
36+
).split('.')
37+
const majorVersion = parseInt(nodeMajorString, 10)
38+
const isUnsupportedVersion = majorVersion < 20
4539

46-
const refs = parseGitRefs()
47-
const api = new GitHubApiClient(inputs.token, refs, artifact, getOctokit)
40+
if (isUnsupportedVersion) {
41+
core.warning(
42+
`${LOG_PREFIX} Internal runner is using unsupported NodeJS version ${process.version}`
43+
)
44+
} else if (options.debug) {
45+
core.info(
46+
`${LOG_PREFIX} Internal runner is using NodeJS version ${process.version}`
47+
)
48+
}
4849

49-
const result = await runInCI(refs, api, options, git)
50+
const refs = parseGitRefs()
51+
const api = new GitHubApiClient(inputs.token, refs, artifact, getOctokit)
5052

51-
if (result.commentId != null) {
52-
core.setOutput('comment-id', result.commentId)
53-
core.info(`Commented on PR #${github.context.issue.number}`)
54-
}
53+
const result = await runInCI(refs, api, options, git)
5554

56-
const diffFiles =
57-
result.mode === 'standalone'
58-
? Object.values(result.files.diff ?? {})
59-
: result.diffPath
60-
? [result.diffPath]
61-
: []
62-
if (diffFiles.length > 0) {
63-
await uploadArtifact(
64-
artifact,
65-
createDiffArtifactName(),
66-
diffFiles,
67-
inputs
68-
)
69-
}
55+
if (result.commentId != null) {
56+
core.setOutput('comment-id', result.commentId)
57+
core.info(`Commented on PR #${github.context.issue.number}`)
58+
}
59+
60+
const diffFiles =
61+
result.mode === 'standalone'
62+
? Object.values(result.files.diff ?? {})
63+
: result.diffPath
64+
? [result.diffPath]
65+
: []
66+
67+
if (diffFiles.length > 0) {
68+
await uploadArtifact(artifact, createDiffArtifactName(), diffFiles, inputs)
69+
}
7070

71-
if (result.mode === 'standalone') {
72-
const id = await uploadArtifact(
71+
if (result.mode === 'standalone') {
72+
const id = await uploadArtifact(
73+
artifact,
74+
createReportArtifactName(),
75+
Object.values(result.files.report),
76+
inputs
77+
)
78+
core.setOutput('artifact-id', id)
79+
} else {
80+
for (const project of result.projects) {
81+
await uploadArtifact(
7382
artifact,
74-
createReportArtifactName(),
75-
Object.values(result.files.report),
83+
createReportArtifactName(project.name),
84+
Object.values(project.files.report),
7685
inputs
7786
)
78-
core.setOutput('artifact-id', id)
79-
} else {
80-
for (const project of result.projects) {
87+
if (project.files.diff) {
8188
await uploadArtifact(
8289
artifact,
83-
createReportArtifactName(project.name),
84-
Object.values(project.files.report),
90+
createDiffArtifactName(project.name),
91+
Object.values(project.files.diff),
8592
inputs
8693
)
87-
if (project.files.diff) {
88-
await uploadArtifact(
89-
artifact,
90-
createDiffArtifactName(project.name),
91-
Object.values(project.files.diff),
92-
inputs
93-
)
94-
}
9594
}
9695
}
96+
}
9797

98-
if (inputs.annotations) {
99-
const issues =
100-
result.mode === 'standalone'
101-
? (result.newIssues ?? [])
102-
: result.projects.flatMap(project => project.newIssues ?? [])
103-
if (issues.length > 0) {
104-
core.info(
105-
`Found ${issues.length} new issues, creating GitHub annotations`
106-
)
107-
createAnnotationsFromIssues(issues)
108-
} else {
109-
core.info('No new issues found, skipping GitHub annotations')
110-
}
98+
if (inputs.annotations) {
99+
const issues =
100+
result.mode === 'standalone'
101+
? (result.newIssues ?? [])
102+
: result.projects.flatMap(project => project.newIssues ?? [])
103+
if (issues.length > 0) {
104+
core.info(
105+
`Found ${issues.length} new issues, creating GitHub annotations`
106+
)
107+
createAnnotationsFromIssues(issues)
108+
} else {
109+
core.info('No new issues found, skipping GitHub annotations')
111110
}
112-
} catch (error) {
113-
const errorMessage = error instanceof Error ? error.message : `${error}`
114-
core.error(errorMessage)
115-
core.setFailed(errorMessage)
116-
return
117111
}
118112

119113
core.info(`${LOG_PREFIX} Finished running successfully`)

src/options.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ import * as core from '@actions/core'
22
import type { Options } from '@code-pushup/ci'
33
import type { ActionInputs } from './inputs'
44

5+
function isDebugActive(): boolean {
6+
return (
7+
// checks just RUNNER_DEBUG env variable
8+
core.isDebug() ||
9+
// docs mention ACTIONS prefixed debug variables https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/troubleshooting-workflows/enabling-debug-logging
10+
process.env['ACTIONS_RUNNER_DEBUG'] === 'true' ||
11+
process.env['ACTIONS_STEP_DEBUG'] === 'true'
12+
)
13+
}
14+
515
export function createOptions(inputs: ActionInputs): Required<Options> {
616
return {
717
monorepo: inputs.monorepo,
@@ -15,7 +25,7 @@ export function createOptions(inputs: ActionInputs): Required<Options> {
1525
detectNewIssues: inputs.annotations,
1626
skipComment: inputs.skipComment,
1727
silent: inputs.silent,
18-
debug: core.isDebug(),
28+
debug: isDebugActive(),
1929
logger: {
2030
error: core.error,
2131
warn: core.warning,

0 commit comments

Comments
 (0)