|
1 | 1 | import * as core from "@actions/core"; |
2 | 2 |
|
3 | | -import { checkForTimeout, wrapError } from "./util"; |
| 3 | +import { |
| 4 | + createStatusReportBase, |
| 5 | + getRequiredInput, |
| 6 | + getTemporaryDirectory, |
| 7 | + sendStatusReport, |
| 8 | +} from "./actions-util"; |
| 9 | +import { getGitHubVersion } from "./api-client"; |
| 10 | +import * as configUtils from "./config-utils"; |
| 11 | +import { Language, resolveAlias } from "./languages"; |
| 12 | +import { getActionsLogger } from "./logging"; |
| 13 | +import { runResolveBuildEnvironment } from "./resolve-environment"; |
| 14 | +import { checkForTimeout, checkGitHubVersionInRange, wrapError } from "./util"; |
| 15 | +import { validateWorkflow } from "./workflow"; |
| 16 | + |
| 17 | +const actionName = "resolve-environment"; |
4 | 18 |
|
5 | 19 | async function run() { |
6 | | - return; |
| 20 | + const startedAt = new Date(); |
| 21 | + const logger = getActionsLogger(); |
| 22 | + const language: Language = resolveAlias(getRequiredInput("language")); |
| 23 | + |
| 24 | + try { |
| 25 | + const workflowErrors = await validateWorkflow(logger); |
| 26 | + |
| 27 | + if ( |
| 28 | + !(await sendStatusReport( |
| 29 | + await createStatusReportBase( |
| 30 | + actionName, |
| 31 | + "starting", |
| 32 | + startedAt, |
| 33 | + workflowErrors |
| 34 | + ) |
| 35 | + )) |
| 36 | + ) { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + const gitHubVersion = await getGitHubVersion(); |
| 41 | + checkGitHubVersionInRange(gitHubVersion, logger); |
| 42 | + |
| 43 | + const config = await configUtils.getConfig(getTemporaryDirectory(), logger); |
| 44 | + if (config === undefined) { |
| 45 | + throw new Error( |
| 46 | + "Config file could not be found at expected location. Has the 'init' action been called?" |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + const result = await runResolveBuildEnvironment(config.codeQLCmd, logger, language); |
| 51 | + core.setOutput("configuration", result); |
| 52 | + } catch (unwrappedError) { |
| 53 | + const error = wrapError(unwrappedError); |
| 54 | + core.setFailed(error.message); |
| 55 | + await sendStatusReport( |
| 56 | + await createStatusReportBase( |
| 57 | + actionName, |
| 58 | + "aborted", |
| 59 | + startedAt, |
| 60 | + error.message, |
| 61 | + error.stack |
| 62 | + ) |
| 63 | + ); |
| 64 | + return; |
| 65 | + } |
7 | 66 | } |
8 | 67 |
|
9 | 68 | async function runWrapper() { |
10 | 69 | try { |
11 | 70 | await run(); |
12 | 71 | } catch (error) { |
13 | | - core.setFailed( |
14 | | - `resolve environment action failed: ${wrapError(error).message}` |
15 | | - ); |
| 72 | + core.setFailed(`${actionName} action failed: ${wrapError(error).message}`); |
16 | 73 | } |
17 | 74 | await checkForTimeout(); |
18 | 75 | } |
|
0 commit comments