-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
86 lines (72 loc) · 2.03 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const core = require("@actions/core");
const exec = require("@actions/exec");
const jsonfile = require("jsonfile");
const commands = {
uploadDir: "arweave deploy-dir",
};
const flags = {
deploy: {
keyFile: "--key-file",
skipConfirmation: "--force-skip-confirmation",
ignoreIndex: "--ignore-index",
},
};
const paths = {
keyFile: "keyfile.json",
};
const outputs = {
arweaveUrl: "arweave_url",
cost: "cost",
};
async function run() {
try {
const inputs = {
keyFileContent: JSON.parse(core.getInput("KEY_FILE_CONTENT")),
dirPath: core.getInput("DIR_PATH"),
ignoreIndex: core.getInput("IGNORE_INDEX").toLowerCase() === "true",
};
jsonfile
.writeFile(paths.keyFile, inputs.keyFileContent)
.then(async () => {
const args = [
inputs.dirPath,
flags.deploy.keyFile,
paths.keyFile,
flags.deploy.skipConfirmation,
...(inputs.ignoreIndex ? [flags.deploy.ignoreIndex] : []),
];
let commandOutput = "";
const options = {
listeners: {
stdout: (data) => {
commandOutput += data.toString();
},
},
};
await exec.exec(commands.uploadDir, args, options);
const result = getResults(commandOutput);
core.setOutput(outputs.arweaveUrl, result.arweaveUrl);
core.setOutput(outputs.cost, result.cost);
})
.catch((error) => {
core.setFailed(error.message);
});
} catch (error) {
core.setFailed(error.message);
}
}
function getResults(output) {
// Ugly function, but the output data is not structured, just a huuge string
const splittedOutput = output.split("\n");
const indexes = {
arweaveUrlIndex: splittedOutput.findIndex((e) =>
e.includes("https://arweave.net")
),
costIndex: splittedOutput.findIndex((e) => e.includes("Total price")),
};
return {
arweaveUrl: splittedOutput[indexes.arweaveUrlIndex],
cost: splittedOutput[indexes.costIndex].split(" ")[2],
};
}
run();