-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
50 lines (45 loc) · 1.6 KB
/
main.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
const { get_info } = require("./src/get_info");
const { setVersion } = require("./src/version")
const { build } = require("./src/build");
const { write_output } = require("./src/write_output");
const fs = require("fs");
async function main() {
//Read env variables
const env = process.env;
if (typeof env.GH_REPO == "undefined") {
console.error(
'"GH_REPO" not found in the environment variables, you need to set it first. For example: "Codertocat/Hello-World"'
);
process.exit(1);
}
const test = env.TEST === "true";
//Try load config
const config = {}
try {
const config_path = "./config.json"
if(fs.existsSync(config_path)) {
const json = fs.readFileSync(config_path, { encoding: "utf-8" })
let config_parsed = JSON.parse(json)
config.VERSION = config_parsed.version
config.BUILD = config_parsed.build
console.log(`Found config.json, using version: ${config.VERSION || "latest" } build: ${config.BUILD || "latest"}`)
} else
console.log("No config.json found, using the latest version and build.")
} catch (e) {
console.error(e)
}
//Get info
let info = await get_info(env.GH_REPO, config.VERSION, config.BUILD);
console.log(
`Target Paper Version is: ${info.paper_release}, on commit: ${info.latest_commit}.\nRelease exists: ${info.release_exists}`
);
if (test || !info.release_exists) {
setVersion(info.latest_version)
build(info.latest_commit, info.latest_version, info.latest_build, test);
write_output(true, info);
} else {
console.log("Already at the latest build.");
write_output(false);
}
}
main();