forked from asacolips-projects/pbta
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-build-tags.js
More file actions
74 lines (68 loc) · 2.73 KB
/
update-build-tags.js
File metadata and controls
74 lines (68 loc) · 2.73 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
const yargs = require("yargs");
const fs = require("fs");
const argv = yargs
.option("branch", {
type: "string",
description: "specifies the branch (CI_COMMIT_BRANCH)"
})
.option("gitlabpath", {
type: "string",
description: "The path on gitlab where this branch is stored (CI_PROJECT_PATH)"
})
.option("jobname", {
type: "string",
description: "specifies the job name (CI_JOB_NAME)"
})
.option("tag", {
type: "string",
description: "The git tag used for this version (CI_COMMIT_TAG)"
})
.option("bucket", {
type: "string",
description: "The s3 bucket used for this build (S3_BUCKET)"
})
.option("versionpost", {
type: "string",
description: "specifies the timestamp as a prefix on beta builds (CI_PIPELINE_IID)"
})
.demandOption(["branch", "gitlabpath", "jobname"])
.argv;
const systemRaw = fs.readFileSync("./dist/system.json");
let system = JSON.parse(systemRaw);
// Set the artifact path.
let artifactBranch = argv.branch ? argv.branch : "master";
let artifactVersion = argv.tag ? argv.tag : argv.branch;
let versionParsed = "master";
let bucket = argv.bucket ? argv.bucket : "";
// Calculate the version.
if (argv.branch && argv.branch == "beta" && argv.versionpost) {
let newVersionSplit = system.version.split(".");
// Set the beta version.
// newVersionSplit[1]++;
// newVersionSplit[2] = 0;
let newVersion = newVersionSplit.join(".");
system.version = `${newVersion}-beta${argv.versionpost ? argv.versionpost : ""}`;
} else if (argv.tag) {
system.version = argv.tag;
// Determine if this is a pre-release version tag.
versionParsed = system.version.match(/beta|alpha/);
if (versionParsed && versionParsed[0]) {
artifactBranch = versionParsed[0];
}
}
// Update URLs.
system.url = `https://gitlab.com/${argv.gitlabpath}`;
if (versionParsed == "beta" || versionParsed == "alpha") {
system.manifest = `https://${bucket}.s3.amazonaws.com/${system.name}/${artifactBranch}/system.json`;
system.download = `https://${bucket}.s3.amazonaws.com/${system.name}/${artifactVersion}/${system.name}.zip`;
} else if (artifactBranch == "master") {
system.manifest = `https://${bucket}.s3.amazonaws.com/${system.name}/${artifactBranch}/system.json`;
system.download = `https://${bucket}.s3.amazonaws.com/${system.name}/${artifactVersion}/${system.name}.zip`;
} else {
system.manifest = `https://gitlab.com/${argv.gitlabpath}/-/jobs/artifacts/${artifactVersion}/raw/system.json?job=${argv.jobname}`;
system.download = `https://gitlab.com/${argv.gitlabpath}/-/jobs/artifacts/${artifactVersion}/raw/${system.name}.zip?job=${argv.jobname}`;
}
fs.writeFileSync("./dist/system.json", JSON.stringify(system, null, 2));
console.log(`Build: ${system.version}`);
console.log(`Manifest: ${system.manifest}`);
console.log(`Download: ${system.download}`);