-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
51 lines (46 loc) · 1.81 KB
/
index.js
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
const core = require('@actions/core')
const exec = require('@actions/exec')
const tc = require('@actions/tool-cache')
const fs = require('fs')
const os = require('os')
const path = require('path')
const process = require('process');
async function run() {
try {
const sdk = core.getInput('sdk')
const cacheKey = 'emscripten'
let emSdk = tc.find(cacheKey, sdk)
if (emSdk && !sdk.includes('latest')) {
core.info(`Using cached version ${sdk}`)
} else {
core.info(`Cloning emsdk from https://github.com/emscripten-core/emsdk.git`)
await exec.exec('rm', ['-rf', 'emsdk'])
await exec.exec('git', ['clone', 'https://github.com/emscripten-core/emsdk.git'])
if (sdk.includes('fastcomp')) {
// fast-comp is not supported anymore on the main branch, checkout an older branch
await process.chdir('emsdk');
await exec.exec('git', ['checkout', '3.1.29'])
await process.chdir('..');
}
core.info(`Installing emsdk ${sdk}`)
await exec.exec('./emsdk/emsdk', ['install', sdk])
core.info(`Activating emsdk ${sdk}`)
await exec.exec('./emsdk/emsdk', ['activate', sdk])
core.info(`Caching version ${sdk}`)
emSdk = await tc.cacheDir('emsdk', cacheKey, sdk)
}
core.exportVariable('EMSDK', emSdk)
core.addPath(emSdk)
const emConfPath = path.join(emSdk, '.emscripten')
core.exportVariable('EM_CONFIG', emConfPath)
const emConf = fs.readFileSync(emConfPath).toString()
const emRoot = path.join(emSdk, emConf.match(/EMSCRIPTEN_ROOT = emsdk_path \+ '(.*)'/)[1])
core.addPath(emRoot)
const emNode = path.join(emSdk, emConf.match(/NODE_JS = emsdk_path \+ '(.*)'/)[1])
core.exportVariable('EMSDK_NODE', emNode)
core.addPath(path.dirname(emNode))
} catch (error) {
core.setFailed(error.message)
}
}
run()