-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
114 lines (101 loc) · 3.19 KB
/
main.ts
File metadata and controls
114 lines (101 loc) · 3.19 KB
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
import { DefaultArtifactClient } from '@actions/artifact'
import * as core from '@actions/core'
import * as github from '@actions/github'
import { runInCI } from '@code-pushup/ci'
import { simpleGit } from 'simple-git'
import { createAnnotationsFromIssues } from './annotations'
import { GitHubApiClient } from './api'
import {
createDiffArtifactName,
createReportArtifactName,
uploadArtifact
} from './artifact'
import { parseInputs } from './inputs'
import { createOptions } from './options'
import { parseGitRefs } from './refs'
const LOG_PREFIX = '[Code PushUp GitHub action]'
export async function run(
artifact = new DefaultArtifactClient(),
getOctokit = github.getOctokit,
git = simpleGit()
): Promise<void> {
const inputs = parseInputs()
const options = createOptions(inputs)
if (options.debug) {
core.info(
`${LOG_PREFIX} Debug in actions in enabled, setting CP_VERBOSE env variable to true`
)
process.env['CP_VERBOSE'] = 'true'
}
const [nodeMajorString] = (
process.version.startsWith('v') ? process.version.slice(1) : process.version
).split('.')
const majorVersion = parseInt(nodeMajorString, 10)
const isUnsupportedVersion = majorVersion < 20
if (isUnsupportedVersion) {
core.warning(
`${LOG_PREFIX} Internal runner is using unsupported NodeJS version ${process.version}`
)
} else if (options.debug) {
core.info(
`${LOG_PREFIX} Internal runner is using NodeJS version ${process.version}`
)
}
const refs = parseGitRefs()
const api = new GitHubApiClient(inputs.token, refs, artifact, getOctokit)
const result = await runInCI(refs, api, options, git)
if (result.commentId != null) {
core.setOutput('comment-id', result.commentId)
core.info(`Commented on PR #${github.context.issue.number}`)
}
const diffFiles =
result.mode === 'standalone'
? Object.values(result.files.diff ?? {})
: result.diffPath
? [result.diffPath]
: []
if (diffFiles.length > 0) {
await uploadArtifact(artifact, createDiffArtifactName(), diffFiles, inputs)
}
if (result.mode === 'standalone') {
const id = await uploadArtifact(
artifact,
createReportArtifactName(),
Object.values(result.files.report),
inputs
)
core.setOutput('artifact-id', id)
} else {
for (const project of result.projects) {
await uploadArtifact(
artifact,
createReportArtifactName(project.name),
Object.values(project.files.report),
inputs
)
if (project.files.diff) {
await uploadArtifact(
artifact,
createDiffArtifactName(project.name),
Object.values(project.files.diff),
inputs
)
}
}
}
if (inputs.annotations) {
const issues =
result.mode === 'standalone'
? (result.newIssues ?? [])
: result.projects.flatMap(project => project.newIssues ?? [])
if (issues.length > 0) {
core.info(
`Found ${issues.length} new issues, creating GitHub annotations`
)
createAnnotationsFromIssues(issues)
} else {
core.info('No new issues found, skipping GitHub annotations')
}
}
core.info(`${LOG_PREFIX} Finished running successfully`)
}