This repository was archived by the owner on Nov 13, 2020. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
96 lines (80 loc) · 2.26 KB
/
Copy pathindex.js
File metadata and controls
96 lines (80 loc) · 2.26 KB
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
const { Toolkit } = require("actions-toolkit");
const path = require("path");
const fs = require("fs");
const exec = require("child_process").exec;
const YAML = require("yaml");
Toolkit.run(async (tools) => {
// Ensure that we have our required inputs defined
const entrypoint = tools.inputs.main;
if (!entrypoint) {
tools.exit.failure("Missing input: main");
}
// And that the entrypoint exists
const entrypointPath = path.join(tools.workspace, entrypoint);
if (!fs.existsSync(entrypoint)) {
tools.exit.failure(`Main '${entrypoint}' does not exist`);
}
tools.log.info(`Main ${entrypoint} detected`);
// Run npm ci
await new Promise((resolve, reject) => {
exec(
"npm ci",
{ cwd: tools.workspace, maxBuffer: 200 * 1024 },
(error, stdout, stderr) => {
if (error) {
reject(error);
} else {
resolve(true);
}
}
);
});
tools.log.complete("NPM install run");
const { code } = await require("@zeit/ncc")(
path.join(tools.workspace, entrypoint),
{
debugLog: true,
}
);
tools.log.complete("Code compiled");
const actionDef = YAML.parse(tools.getFile("action.yml"));
actionDef.runs.using = "node12";
actionDef.runs.main = "index.dist.js";
delete actionDef.runs.image;
tools.log.complete("Action YAML rewritten");
const tree = await tools.github.git.createTree({
...tools.context.repo,
tree: [
{
path: "action.yml",
mode: "100644",
type: "blob",
content: YAML.stringify(actionDef),
base_tree: tools.context.sha,
},
{
path: "index.dist.js",
mode: "100644",
type: "blob",
content: code,
base_tree: tools.context.sha,
},
],
});
tools.log.complete("Tree created");
const commit = await tools.github.git.createCommit({
...tools.context.repo,
message: "Automatic compilation",
tree: tree.data.sha,
parents: [tools.context.sha],
});
tools.log.complete("Commit created");
const ref = await tools.github.git.updateRef({
...tools.context.repo,
ref: `tags/${tools.context.payload.release.tag_name}`,
force: true,
sha: commit.data.sha,
});
tools.log.complete("Tag updated");
tools.exit.success("All done");
});