generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmain.ts
115 lines (98 loc) · 4 KB
/
main.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
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
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as tc from '@actions/tool-cache';
import * as cache from '@actions/cache';
import * as io from '@actions/io';
import * as os from 'os';
import * as fs from 'fs';
import * as path from 'path';
import { envRegex, pathRegex } from './matchers'
async function run() {
try {
const emArgs = {
version: await core.getInput("version"),
noInstall: await core.getInput("no-install"),
noCache: await core.getInput("no-cache"),
actionsCacheFolder: await core.getInput("actions-cache-folder"),
// XXX: update-tags is deprecated and used for backwards compatibility.
update: await core.getInput("update") || await core.getInput("update-tags")
};
let emsdkFolder;
let foundInCache = false;
if (emArgs.version !== "latest" && emArgs.version !== "tot" && emArgs.noCache === "false" && !emArgs.actionsCacheFolder) {
emsdkFolder = await tc.find('emsdk', emArgs.version, os.arch());
}
const cacheKey = `${emArgs.version}-${ os.platform() }-${os.arch()}-master`;
if (emArgs.actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, emArgs.actionsCacheFolder);
try {
try {
fs.accessSync(path.join(fullCachePath, 'emsdk-main', 'emsdk'), fs.constants.X_OK);
} catch {
await cache.restoreCache([emArgs.actionsCacheFolder], cacheKey);
}
fs.accessSync(path.join(fullCachePath, 'emsdk-main', 'emsdk'), fs.constants.X_OK);
emsdkFolder = fullCachePath;
foundInCache = true;
} catch {
core.warning(`No cached files found at path "${fullCachePath}" - downloading and caching emsdk.`);
await io.rmRF(fullCachePath);
// core.debug(fs.readdirSync(fullCachePath + '/emsdk-main').toString());
}
}
if (!emsdkFolder) {
const emsdkArchive = await tc.downloadTool("https://github.com/emscripten-core/emsdk/archive/main.zip");
emsdkFolder = await tc.extractZip(emsdkArchive);
} else {
foundInCache = true;
}
let emsdk = path.join(emsdkFolder, 'emsdk-main', 'emsdk');
if (os.platform() === "win32") {
emsdk = `powershell ${path.join(emsdkFolder, 'emsdk-main', 'emsdk.ps1')}`;
}
if (emArgs.noInstall === "true") {
core.addPath(path.join(emsdkFolder, 'emsdk-main'));
core.exportVariable("EMSDK", path.join(emsdkFolder, 'emsdk-main'));
return;
}
if (!foundInCache) {
if (emArgs.update) {
await exec.exec(`${emsdk} update`);
}
await exec.exec(`${emsdk} install ${emArgs.version}`);
if (emArgs.version !== "latest" && emArgs.version !== "tot" && emArgs.noCache === "false" && !emArgs.actionsCacheFolder) {
await tc.cacheDir(emsdkFolder, 'emsdk', emArgs.version, os.arch());
}
}
await exec.exec(`${emsdk} activate ${emArgs.version}`);
const envListener = (message) => {
const pathResult = pathRegex.exec(message);
if (pathResult) {
core.addPath(pathResult[1]);
return;
}
const envResult = envRegex.exec(message);
if (envResult) {
core.exportVariable(envResult[1], envResult[2]);
return;
}
};
await exec.exec(`${emsdk} construct_env`, [], {listeners: {stdline: envListener, errline: envListener}})
if (emArgs.actionsCacheFolder && !foundInCache && process.env.GITHUB_WORKSPACE) {
fs.mkdirSync(path.join(process.env.GITHUB_WORKSPACE, emArgs.actionsCacheFolder), { recursive: true });
await io.cp(path.join(emsdkFolder, 'emsdk-main'), path.join(process.env.GITHUB_WORKSPACE, emArgs.actionsCacheFolder), { recursive: true })
await cache.saveCache([emArgs.actionsCacheFolder], cacheKey);
}
} catch (error) {
if (error &&
typeof error === "object" &&
"message" in error &&
(
typeof error.message === "string" ||
error.message instanceof Error
)) {
core.setFailed(error.message);
}
}
}
run();