-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
69 lines (60 loc) · 2.23 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { generateSlug } = require('random-word-slugs');
const axios = require('axios');
const core = require('@actions/core');
const exec = require('@actions/exec');
const { execSync } = require('child_process');
execSync('npm install localtunnel -g');
const API_TOKEN = core.getInput('api_token');
const API_ROOT = core.getInput('api_root');
const EXPLORER_SUBDOMAIN = core.getInput('explorer_subdomain');
const NODE_PORT = core.getInput('node_port');
if (!API_TOKEN || !API_ROOT || !EXPLORER_SUBDOMAIN || !NODE_PORT)
return core.setFailed('Missing inputs');
const ETHERNAL_HEADERS = {
headers: {
'Authorization': `Bearer ${API_TOKEN}`,
'Content-Type': 'application/json'
}
};
async function createWorkspace(name, rpcServer) {
const payload = {
name: name,
workspaceData: {
chain: 'ethereum',
networkId: 31337,
rpcServer: rpcServer,
public: true,
tracing: 'disabled'
}
}
const workspace = (await axios.post(`${API_ROOT}/api/workspaces`, { data: payload }, ETHERNAL_HEADERS)).data;
return workspace;
}
async function createExplorer(name, rpcServer) {
const workspace = await createWorkspace(name, rpcServer);
const payload = {
workspaceId: workspace.id,
name: name,
rpcServer: rpcServer,
theme: {default:{}},
token: 'ether',
domain: `${workspace.name}.${EXPLORER_SUBDOMAIN}`,
slug: name,
chainId: parseInt(workspace.networkId)
}
const explorer = (await axios.post(`${API_ROOT}/api/explorers`, { data: payload }, ETHERNAL_HEADERS)).data;
return `https://${payload.domain}`;
}
async function main() {
const appBaseName = `${generateSlug(2)}-${Math.floor(Math.random() * 10000)}`;
await exec.exec('sh', [], { input: `npx localtunnel --port ${NODE_PORT} --subdomain ${appBaseName} &` });
await setTimeout(async () => {
const tunnelUrl = `https://${appBaseName}.loca.lt`;
const explorerUrl = await createExplorer(appBaseName, tunnelUrl);
core.setOutput('explorer_url', explorerUrl);
core.notice(`Explorer URL: ${explorerUrl}`);
core.setOutput('workspace', appBaseName);
process.exit();
}, 5000);
}
main();