-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathindex.ts
90 lines (80 loc) · 2.56 KB
/
index.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
79
80
81
82
83
84
85
86
87
88
89
90
import * as core from '@actions/core'
import * as artifact from '@actions/artifact'
import * as util from './util'
import * as sarif from './sarif'
import * as validator from './validator'
import * as annotations from './annotations'
const reportFormat = 'sarif'
const reportFile = 'pmd-report.sarif'
async function main(): Promise<void> {
let pmdInfo
let modifiedFiles
let execOutput
let violations
const token = core.getInput('token', { required: false })
const sourcePath = validator.validateSourcePath(
core.getInput('sourcePath', { required: false })
)
try {
pmdInfo = await util.downloadPmd(
validator.validateVersion(core.getInput('version', { required: false })),
token,
validator.validateDownloadUrl(
core.getInput('downloadUrl', { required: false })
)
)
if (
core.getInput('analyzeModifiedFilesOnly', { required: false }) === 'true'
) {
core.info(`Determining modified files in ${sourcePath}...`)
modifiedFiles = await util.determineModifiedFiles(token, sourcePath)
if (modifiedFiles !== undefined && modifiedFiles.length === 0) {
core.info(
`No modified files have been found in ${sourcePath} - exiting`
)
core.setOutput('violations', 0)
return
}
}
execOutput = await util.executePmd(
pmdInfo,
modifiedFiles || sourcePath,
validator.validateRulesets(core.getInput('rulesets', { required: true })),
reportFormat,
reportFile
)
core.info(`PMD exited with ${execOutput.exitCode}`)
sarif.relativizeReport(reportFile)
sarif.fixResults(reportFile)
violations = sarif.countViolations(reportFile)
core.setOutput('violations', violations)
core.info(`PMD detected ${violations} violations.`)
if (
core.getInput('createGitHubAnnotations', { required: false }) === 'true'
) {
const report = sarif.loadReport(reportFile)
if (report) {
annotations.processSarifReport(report)
}
}
if (core.getInput('uploadSarifReport', { required: false }) === 'true') {
const artifactName = 'PMD Report'
const artifactClient = new artifact.DefaultArtifactClient()
const { id, size } = await artifactClient.uploadArtifact(
'PMD Report',
[reportFile],
'.'
)
core.info(
`Created artifact ${artifactName} with id: ${id} (bytes: ${size})`
)
}
} catch (error: unknown) {
if (error instanceof Error) {
core.setFailed(error.message)
} else {
core.setFailed(String(error))
}
}
}
main()