Skip to content

Commit 02dd36c

Browse files
committed
fix: improve logging and remove try/catch block that prevents error from bubbling up
1 parent efd7f1e commit 02dd36c

File tree

3 files changed

+132
-134
lines changed

3 files changed

+132
-134
lines changed

dist/index.js

Lines changed: 54 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: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -21,100 +21,100 @@ 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+
// https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/troubleshooting-workflows/enabling-debug-logging
28+
if (
29+
process.env['ACTIONS_RUNNER_DEBUG'] === 'true' ||
30+
process.env['ACTIONS_STEP_DEBUG'] === 'true'
31+
) {
32+
options.debug = true
33+
}
3534

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-
}
35+
if (options.debug) {
36+
core.info(
37+
`${LOG_PREFIX} Debug in actions in enabled, setting CP_VERBOSE env variable to true`
38+
)
39+
process.env['CP_VERBOSE'] = 'true'
40+
}
4541

46-
const refs = parseGitRefs()
47-
const api = new GitHubApiClient(inputs.token, refs, artifact, getOctokit)
42+
const [nodeMajorString] = (
43+
process.version.startsWith('v') ? process.version.slice(1) : process.version
44+
).split('.')
45+
const majorVersion = parseInt(nodeMajorString, 10)
46+
const isUnsupportedVersion = majorVersion < 20
4847

49-
const result = await runInCI(refs, api, options, git)
48+
if (isUnsupportedVersion) {
49+
core.warning(
50+
`${LOG_PREFIX} Internal runner is using unsupported NodeJS version ${process.version}`
51+
)
52+
} else if (options.debug) {
53+
core.info(
54+
`${LOG_PREFIX} Internal runner is using NodeJS version ${process.version}`
55+
)
56+
}
5057

51-
if (result.commentId != null) {
52-
core.setOutput('comment-id', result.commentId)
53-
core.info(`Commented on PR #${github.context.issue.number}`)
54-
}
58+
const refs = parseGitRefs()
59+
const api = new GitHubApiClient(inputs.token, refs, artifact, getOctokit)
5560

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-
}
61+
const result = await runInCI(refs, api, options, git)
7062

71-
if (result.mode === 'standalone') {
72-
const id = await uploadArtifact(
63+
if (result.commentId != null) {
64+
core.setOutput('comment-id', result.commentId)
65+
core.info(`Commented on PR #${github.context.issue.number}`)
66+
}
67+
68+
const diffFiles =
69+
result.mode === 'standalone'
70+
? Object.values(result.files.diff ?? {})
71+
: result.diffPath
72+
? [result.diffPath]
73+
: []
74+
75+
if (diffFiles.length > 0) {
76+
await uploadArtifact(artifact, createDiffArtifactName(), diffFiles, inputs)
77+
}
78+
79+
if (result.mode === 'standalone') {
80+
const id = await uploadArtifact(
81+
artifact,
82+
createReportArtifactName(),
83+
Object.values(result.files.report),
84+
inputs
85+
)
86+
core.setOutput('artifact-id', id)
87+
} else {
88+
for (const project of result.projects) {
89+
await uploadArtifact(
7390
artifact,
74-
createReportArtifactName(),
75-
Object.values(result.files.report),
91+
createReportArtifactName(project.name),
92+
Object.values(project.files.report),
7693
inputs
7794
)
78-
core.setOutput('artifact-id', id)
79-
} else {
80-
for (const project of result.projects) {
95+
if (project.files.diff) {
8196
await uploadArtifact(
8297
artifact,
83-
createReportArtifactName(project.name),
84-
Object.values(project.files.report),
98+
createDiffArtifactName(project.name),
99+
Object.values(project.files.diff),
85100
inputs
86101
)
87-
if (project.files.diff) {
88-
await uploadArtifact(
89-
artifact,
90-
createDiffArtifactName(project.name),
91-
Object.values(project.files.diff),
92-
inputs
93-
)
94-
}
95102
}
96103
}
104+
}
97105

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-
}
106+
if (inputs.annotations) {
107+
const issues =
108+
result.mode === 'standalone'
109+
? (result.newIssues ?? [])
110+
: result.projects.flatMap(project => project.newIssues ?? [])
111+
if (issues.length > 0) {
112+
core.info(
113+
`Found ${issues.length} new issues, creating GitHub annotations`
114+
)
115+
createAnnotationsFromIssues(issues)
116+
} else {
117+
core.info('No new issues found, skipping GitHub annotations')
111118
}
112-
} catch (error) {
113-
const errorMessage = error instanceof Error ? error.message : `${error}`
114-
core.error(errorMessage)
115-
core.setFailed(errorMessage)
116-
return
117119
}
118-
119-
core.info(`${LOG_PREFIX} Finished running successfully`)
120120
}

0 commit comments

Comments
 (0)