generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmain.ts
119 lines (96 loc) · 3.13 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import {Installer} from './installer'
import {Report} from './report'
import {ReSharperSeverity} from './issue'
async function run(): Promise<void> {
try {
const installer = new Installer()
const version: string = core.getInput('version') ?? ''
await installer.install(version)
const solutionPath: string = core.getInput('solutionPath')
const outputPath = 'result.xml'
let command = `jb inspectcode --output=${outputPath} --absolute-paths ${solutionPath}`
const include: string = core.getInput('include')
if (include) {
command += ` --include="${include.trim().replace(/[\r\n]+/g, ';')}"`
}
const exclude = core.getInput('exclude') ?? ''
if (exclude !== '') {
command += ` --exclude=${exclude}`
}
const solutionWideAnalysis: string =
core.getInput('solutionWideAnalysis') ?? ''
if (solutionWideAnalysis !== '') {
command += ` --${
solutionWideAnalysis.toLowerCase() !== 'true' ? 'no-' : ''
}swea`
}
const minimumReportSeverity = getMinimumReportSeverity()
command += ` --severity=${minimumReportSeverity}`
const extensions: string = core.getInput('extensions')
if (extensions) {
command += ` --extensions=${extensions
.trim()
.replace(/(,\s?)|(;\s?)/g, ';')}`
}
const noBuild = core.getInput('noBuild') ?? ''
if (noBuild.toLowerCase() === 'true') {
command += ' --no-build'
} else {
command += ' --build'
}
const cachesHome = core.getInput('cachesHome') ?? ''
if (cachesHome !== '') {
command += ` --caches-home=${cachesHome}`
}
const properties: string = core.getInput('properties') ?? ''
if (properties) {
command += ` --properties:"${properties}"`
}
const dotnetVersion: string = core.getInput('dotnetVersion') ?? ''
if (dotnetVersion) {
command += ` --dotnetcoresdk=${dotnetVersion}`
}
const workingDir: string = core.getInput('workingDirectory')
if (workingDir) {
core.debug(`Changing to working directory: ${workingDir}`)
process.chdir(workingDir)
}
await exec.exec(command)
const ignoreIssueType = (core.getInput('ignoreIssueType') ?? '')
.trim()
.replace(/[\r\n]+/g, ',')
const report = new Report(outputPath, ignoreIssueType)
report.output()
const failOnIssue = core.getInput('failOnIssue')
const minimumSeverity = core.getInput('minimumSeverity') ?? 'notice'
if (failOnIssue !== '1') {
return
}
if (report.issueOverThresholdIsExists(minimumSeverity)) {
core.setFailed('Issues found.')
}
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message)
}
}
}
function getMinimumReportSeverity(): ReSharperSeverity {
const minimumReportSeverity =
core.getInput('minimumReportSeverity').toUpperCase() ?? ''
switch (minimumReportSeverity) {
case 'INFO':
return 'INFO'
case 'SUGGESTION':
return 'SUGGESTION'
case 'WARNING':
return 'WARNING'
case 'ERROR':
return 'ERROR'
default:
return 'HINT'
}
}
run()