-
Notifications
You must be signed in to change notification settings - Fork 355
/
Copy pathstart-proxy-action-post.ts
70 lines (61 loc) · 2.1 KB
/
start-proxy-action-post.ts
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
/**
* This file is the entry point for the `post:` hook of `start-proxy-action.yml`.
* It will run after the all steps in this job, in reverse order in relation to
* other `post:` hooks.
*/
import * as core from "@actions/core";
import * as actionsUtil from "./actions-util";
import { getGitHubVersion } from "./api-client";
import * as configUtils from "./config-utils";
import { getArtifactUploaderClient } from "./debug-artifacts";
import { getActionsLogger } from "./logging";
import { checkGitHubVersionInRange, getErrorMessage } from "./util";
async function runWrapper() {
const logger = getActionsLogger();
try {
// Restore inputs from `start-proxy` Action.
actionsUtil.restoreInputs();
// Kill the running proxy
const pid = core.getState("proxy-process-pid");
if (pid) {
process.kill(Number(pid));
}
const config = await configUtils.getConfig(
actionsUtil.getTemporaryDirectory(),
logger,
);
if ((config && config.debugMode) || core.isDebug()) {
const logFilePath = core.getState("proxy-log-file");
logger.info(
"Debug mode is on. Uploading proxy log as Actions debugging artifact...",
);
if (config?.gitHubVersion.type === undefined) {
logger.warning(
`Did not upload debug artifacts because cannot determine the GitHub variant running.`,
);
return;
}
const gitHubVersion = await getGitHubVersion();
checkGitHubVersionInRange(gitHubVersion, logger);
const artifactUploader = await getArtifactUploaderClient(
logger,
gitHubVersion.type,
);
await artifactUploader.uploadArtifact(
"proxy-log-file",
[logFilePath],
actionsUtil.getTemporaryDirectory(),
{
// ensure we don't keep the debug artifacts around for too long since they can be large.
retentionDays: 7,
},
);
}
} catch (error) {
// A failure in the post step should not fail the entire action.
logger.warning(
`start-proxy post-action step failed: ${getErrorMessage(error)}`,
);
}
}
void runWrapper();