-
Notifications
You must be signed in to change notification settings - Fork 33
/
main.ts
78 lines (74 loc) · 2.27 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import * as core from '@actions/core'
import * as io from '@actions/io'
import {
FAIL_THRESHOLD_OUTPUT,
QODANA_SARIF_NAME,
QodanaExitCode,
isExecutionSuccessful
} from '../../common/qodana'
import {
getInputs,
prepareAgent,
qodana,
restoreCaches,
uploadCaches,
uploadReport
} from './utils'
import {publishAnnotations} from './annotations'
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
// throw an uncaught exception. Instead of failing this action, just warn.
process.on('uncaughtException', e => core.warning(e.message))
function setFailed(message: string): void {
core.setFailed(message)
}
/**
* Main Qodana GitHub Action entrypoint.
* - gathers all action inputs
* - loads caches
* - creates the directories for Qodana results to ensure the correct permissions
* - runs the Qodana image
* - uploads the report as the job artifact
* - saves caches
* - uploads action annotations
* Every step except the Qodana image run is optional.
*/
async function main(): Promise<void> {
try {
const inputs = getInputs()
await io.mkdirP(inputs.resultsDir)
await io.mkdirP(inputs.cacheDir)
await Promise.all([
prepareAgent(inputs.args),
restoreCaches(
inputs.cacheDir,
inputs.additionalCacheHash,
inputs.useCaches
)
])
const exitCode = await qodana()
await Promise.all([
uploadReport(inputs.resultsDir, inputs.artifactName, inputs.uploadResult),
uploadCaches(
inputs.cacheDir,
inputs.additionalCacheHash,
inputs.useCaches && isExecutionSuccessful(exitCode)
),
publishAnnotations(
exitCode === QodanaExitCode.FailThreshold,
inputs.githubToken,
`${inputs.resultsDir}/${QODANA_SARIF_NAME}`,
inputs.useAnnotations && isExecutionSuccessful(exitCode)
)
])
if (!isExecutionSuccessful(exitCode)) {
setFailed(`qodana scan failed with exit code ${exitCode}`)
} else if (exitCode === QodanaExitCode.FailThreshold) {
setFailed(FAIL_THRESHOLD_OUTPUT)
}
} catch (error) {
setFailed((error as Error).message)
}
}
// noinspection JSIgnoredPromiseFromCall
main()