forked from Https-www-quauntumdecaygames-de/codeql-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautobuild-action.ts
More file actions
104 lines (94 loc) · 2.71 KB
/
autobuild-action.ts
File metadata and controls
104 lines (94 loc) · 2.71 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
import * as core from "@actions/core";
import {
createStatusReportBase,
getTemporaryDirectory,
sendStatusReport,
StatusReportBase,
} from "./actions-util";
import { determineAutobuildLanguage, runAutobuild } from "./autobuild";
import * as config_utils from "./config-utils";
import { Language } from "./languages";
import { getActionsLogger } from "./logging";
import { initializeEnvironment, Mode } from "./util";
// eslint-disable-next-line import/no-commonjs
const pkg = require("../package.json");
interface AutobuildStatusReport extends StatusReportBase {
// Comma-separated set of languages being auto-built
autobuild_languages: string;
// Language that failed autobuilding (or undefined if all languages succeeded).
autobuild_failure?: string;
}
async function sendCompletedStatusReport(
startedAt: Date,
allLanguages: string[],
failingLanguage?: string,
cause?: Error
) {
initializeEnvironment(Mode.actions, pkg.version);
const status =
failingLanguage !== undefined || cause !== undefined
? "failure"
: "success";
const statusReportBase = await createStatusReportBase(
"autobuild",
status,
startedAt,
cause?.message,
cause?.stack
);
const statusReport: AutobuildStatusReport = {
...statusReportBase,
autobuild_languages: allLanguages.join(","),
autobuild_failure: failingLanguage,
};
await sendStatusReport(statusReport);
}
async function run() {
const logger = getActionsLogger();
const startedAt = new Date();
let language: Language | undefined = undefined;
try {
if (
!(await sendStatusReport(
await createStatusReportBase("autobuild", "starting", startedAt)
))
) {
return;
}
const config = await config_utils.getConfig(
getTemporaryDirectory(),
logger
);
if (config === undefined) {
throw new Error(
"Config file could not be found at expected location. Has the 'init' action been called?"
);
}
language = determineAutobuildLanguage(config, logger);
if (language !== undefined) {
await runAutobuild(language, config, logger);
}
} catch (error) {
core.setFailed(
`We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. ${error.message}`
);
console.log(error);
await sendCompletedStatusReport(
startedAt,
language ? [language] : [],
language,
error
);
return;
}
await sendCompletedStatusReport(startedAt, language ? [language] : []);
}
async function runWrapper() {
try {
await run();
} catch (error) {
core.setFailed(`autobuild action failed. ${error}`);
console.log(error);
}
}
void runWrapper();