FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql-action/src/setup-codeql-action.ts at main · github/codeql-action · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
codeql-action
Public
Notifications
You must be signed in to change notification settings
Fork
487
Star
1.6k
Code
Issues
158
Pull requests
35
Actions
Security and quality
2
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql-action
/
src
/
setup-codeql-action.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
236 lines (211 loc) · 6.98 KB
Breadcrumbs
codeql-action
/
src
/
setup-codeql-action.ts
Copy path
File metadata and controls
236 lines (211 loc) · 6.98 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import
*
as
core
from
"@actions/core"
;
import
{
Action
,
ActionState
,
runInActions
}
from
"./action-common"
;
import
{
getActionVersion
,
getOptionalInput
,
getRequiredInput
,
getTemporaryDirectory
,
}
from
"./actions-util"
;
import
{
AnalysisKind
,
getAnalysisKinds
}
from
"./analyses"
;
import
{
getGitHubVersion
}
from
"./api-client"
;
import
{
CodeQL
}
from
"./codeql"
;
import
{
ComputedInput
,
getToolsInput
}
from
"./config/inputs"
;
import
{
getRawLanguagesNoAutodetect
}
from
"./config-utils"
;
import
{
EnvVar
}
from
"./environment"
;
import
{
initFeatures
}
from
"./feature-flags"
;
import
{
loadRepositoryProperties
}
from
"./feature-flags/properties"
;
import
{
initCodeQL
}
from
"./init"
;
import
{
Logger
}
from
"./logging"
;
import
{
getRepositoryNwo
}
from
"./repository"
;
import
{
ToolsSource
}
from
"./setup-codeql"
;
import
{
ActionName
,
InitStatusReport
,
InitToolsDownloadFields
,
createStatusReportBase
,
getActionsStatus
,
sendStatusReport
,
}
from
"./status-report"
;
import
{
ToolsDownloadStatusReport
}
from
"./tools-download"
;
import
{
checkDiskUsage
,
checkForTimeout
,
checkGitHubVersionInRange
,
getRequiredEnvParam
,
initializeEnvironment
,
ConfigurationError
,
wrapError
,
checkActionVersion
,
}
from
"./util"
;
/**
* Helper function to send a full status report for this action.
*/
async
function
sendCompletedStatusReport
(
startedAt
:
Date
,
toolsInput
:
ComputedInput
|
undefined
,
toolsDownloadStatusReport
:
ToolsDownloadStatusReport
|
undefined
,
toolsFeatureFlagsValid
:
boolean
|
undefined
,
toolsSource
:
ToolsSource
,
toolsVersion
:
string
,
logger
:
Logger
,
error
?:
Error
,
)
:
Promise
<
void
>
{
const
statusReportBase
=
await
createStatusReportBase
(
ActionName
.
SetupCodeQL
,
getActionsStatus
(
error
)
,
startedAt
,
undefined
,
await
checkDiskUsage
(
logger
)
,
logger
,
error
?.
message
,
error
?.
stack
,
)
;
if
(
statusReportBase
===
undefined
)
{
return
;
}
const
initStatusReport
:
InitStatusReport
=
{
...
statusReportBase
,
tools_input
:
toolsInput
?.
value
||
""
,
tools_resolved_version
:
toolsVersion
,
tools_source
:
toolsSource
||
ToolsSource
.
Unknown
,
workflow_languages
:
""
,
}
;
if
(
toolsInput
!==
undefined
)
{
initStatusReport
.
computed_inputs
.
tools
=
toolsInput
;
}
const
initToolsDownloadFields
:
InitToolsDownloadFields
=
{
}
;
if
(
toolsDownloadStatusReport
?.
downloadDurationMs
!==
undefined
)
{
initToolsDownloadFields
.
tools_download_duration_ms
=
toolsDownloadStatusReport
.
downloadDurationMs
;
}
if
(
toolsDownloadStatusReport
?.
extractionDurationMs
!==
undefined
)
{
initToolsDownloadFields
.
tools_extraction_duration_ms
=
toolsDownloadStatusReport
.
extractionDurationMs
;
}
if
(
toolsDownloadStatusReport
?.
totalDurationMs
!==
undefined
)
{
initToolsDownloadFields
.
tools_total_duration_ms
=
toolsDownloadStatusReport
.
totalDurationMs
;
}
if
(
toolsFeatureFlagsValid
!==
undefined
)
{
initToolsDownloadFields
.
tools_feature_flags_valid
=
toolsFeatureFlagsValid
;
}
await
sendStatusReport
(
{
...
initStatusReport
,
...
initToolsDownloadFields
}
)
;
}
/** The main behaviour of this action. */
async
function
run
(
actionState
:
ActionState
<
[
"Base"
,
"Logger"
,
"Env"
,
"Actions"
]
>
,
)
:
Promise
<
void
>
{
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.
const
{
logger
,
startedAt
}
=
actionState
;
let
codeql
:
CodeQL
;
let
toolsInput
:
ComputedInput
|
undefined
;
let
toolsDownloadStatusReport
:
ToolsDownloadStatusReport
|
undefined
;
let
toolsFeatureFlagsValid
:
boolean
|
undefined
;
let
toolsSource
:
ToolsSource
;
let
toolsVersion
:
string
;
try
{
initializeEnvironment
(
getActionVersion
(
)
)
;
const
apiDetails
=
{
auth
:
getRequiredInput
(
"token"
)
,
externalRepoAuth
:
getOptionalInput
(
"external-repository-token"
)
,
url
:
getRequiredEnvParam
(
"GITHUB_SERVER_URL"
)
,
apiURL
:
getRequiredEnvParam
(
"GITHUB_API_URL"
)
,
}
;
const
gitHubVersion
=
await
getGitHubVersion
(
)
;
checkGitHubVersionInRange
(
gitHubVersion
,
logger
)
;
checkActionVersion
(
getActionVersion
(
)
,
gitHubVersion
)
;
const
repositoryNwo
=
getRepositoryNwo
(
)
;
const
features
=
initFeatures
(
gitHubVersion
,
repositoryNwo
,
getTemporaryDirectory
(
)
,
logger
,
)
;
// Fetch the values of known repository properties that affect us.
const
repositoryPropertiesResult
=
await
loadRepositoryProperties
(
repositoryNwo
,
logger
,
)
;
const
repositoryProperties
=
repositoryPropertiesResult
.
orElse
(
{
}
)
;
const
actionStateWithFeatures
=
{
...
actionState
,
features
}
;
const
statusReportBase
=
await
createStatusReportBase
(
ActionName
.
SetupCodeQL
,
"starting"
,
startedAt
,
undefined
,
await
checkDiskUsage
(
logger
)
,
logger
,
)
;
if
(
statusReportBase
!==
undefined
)
{
await
sendStatusReport
(
statusReportBase
)
;
}
// Get the computed `tools` input.
toolsInput
=
await
getToolsInput
(
actionStateWithFeatures
,
repositoryProperties
,
)
;
const
codeQLDefaultVersionInfo
=
await
features
.
getEnabledDefaultCliVersions
(
gitHubVersion
.
type
)
;
toolsFeatureFlagsValid
=
codeQLDefaultVersionInfo
.
toolsFeatureFlagsValid
;
const
rawLanguages
=
getRawLanguagesNoAutodetect
(
getOptionalInput
(
"languages"
)
,
)
;
const
analysisKinds
=
await
getAnalysisKinds
(
logger
,
features
)
;
const
initCodeQLResult
=
await
initCodeQL
(
toolsInput
?.
value
,
apiDetails
,
getTemporaryDirectory
(
)
,
gitHubVersion
.
type
,
codeQLDefaultVersionInfo
,
rawLanguages
,
analysisKinds
.
length
===
1
&&
analysisKinds
[
0
]
===
AnalysisKind
.
CodeScanning
,
features
,
logger
,
)
;
codeql
=
initCodeQLResult
.
codeql
;
toolsDownloadStatusReport
=
initCodeQLResult
.
toolsDownloadStatusReport
;
toolsVersion
=
initCodeQLResult
.
toolsVersion
;
toolsSource
=
initCodeQLResult
.
toolsSource
;
core
.
setOutput
(
"codeql-path"
,
codeql
.
getPath
(
)
)
;
core
.
setOutput
(
"codeql-version"
,
(
await
codeql
.
getVersion
(
)
)
.
version
)
;
core
.
exportVariable
(
EnvVar
.
SETUP_CODEQL_ACTION_HAS_RUN
,
"true"
)
;
}
catch
(
unwrappedError
)
{
const
error
=
wrapError
(
unwrappedError
)
;
core
.
setFailed
(
error
.
message
)
;
const
statusReportBase
=
await
createStatusReportBase
(
ActionName
.
SetupCodeQL
,
error
instanceof
ConfigurationError
?
"user-error"
:
"failure"
,
startedAt
,
undefined
,
await
checkDiskUsage
(
logger
)
,
logger
,
error
.
message
,
error
.
stack
,
)
;
if
(
statusReportBase
!==
undefined
)
{
await
sendStatusReport
(
statusReportBase
)
;
}
return
;
}
await
sendCompletedStatusReport
(
startedAt
,
toolsInput
,
toolsDownloadStatusReport
,
toolsFeatureFlagsValid
,
toolsSource
,
toolsVersion
,
logger
,
)
;
}
/** Defines the `setup-codeql` Action. */
const
setupCodeQL
:
Action
=
{
name
:
ActionName
.
SetupCodeQL
,
run
,
}
;
/** Run the action and catch any unhandled errors. */
export
async
function
runWrapper
(
)
:
Promise
<
void
>
{
await
runInActions
(
setupCodeQL
)
;
await
checkForTimeout
(
)
;
}
Back
|
FazBrowse Home
|
New Git URL