-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
102 lines (88 loc) · 3.06 KB
/
main.ts
File metadata and controls
102 lines (88 loc) · 3.06 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
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 { REPORT_ARTIFACT_NAME, uploadArtifact } from './artifact'
import { authenticate } from './auth'
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 token = await authenticate(github.context.repo, inputs.token)
const api = new GitHubApiClient(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 artifactFiles =
result.mode === 'standalone'
? [
...Object.values(result.files.current),
...Object.values(result.files.previous ?? {}),
...Object.values(result.files.comparison ?? {})
]
: [
...Object.values(result.files?.comparison ?? {}),
...result.projects.flatMap(({ files }) => [
...Object.values(files.current),
...Object.values(files.previous ?? {}),
...Object.values(files.comparison ?? {})
])
]
if (artifactFiles.length > 0) {
const id = await uploadArtifact(
artifact,
REPORT_ARTIFACT_NAME,
artifactFiles,
inputs
)
core.setOutput('artifact-id', id)
}
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`)
}