-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathversion.js
More file actions
69 lines (58 loc) · 1.77 KB
/
version.js
File metadata and controls
69 lines (58 loc) · 1.77 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
import simpleGit from "simple-git";
import semver from "semver";
import dateFormat from "dateformat";
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const resolve = (...args) => path.resolve(__dirname, ...args);
const MAX_TAGS_LIMIT = 64;
function isGreater(a, b) {
const cmp = semver.compare(semver.coerce(a), semver.coerce(b));
return cmp === 0
? a.includes("nightly") && !b.includes("nightly")
: cmp > 0;
}
const createRepo = (path, regex, mapVersion) => ({
git: simpleGit(path),
filter: tag => {
const match = regex.exec(tag);
return match ? {
tag,
version: mapVersion(match),
} : null;
}
});
// see: https://github.com/WebAssembly/binaryen/issues/1156
const src = createRepo(resolve('../binaryen'), /^version_(\d+)(?:_.*)?$/, ([, maj]) => `${maj}.0.0`);
const dst = createRepo(resolve('..'), /^v(\d+\.\d+\.\d+)(?:\-|$)/, ([, ver]) => ver);
async function latest(repo) {
try {
const tagsRaw = await repo.git.raw(['tag', '--sort=-v:refname']);
const allTags = tagsRaw.split('\n').filter(Boolean).slice(0, MAX_TAGS_LIMIT);
for (let tag of allTags) {
const res = repo.filter(tag);
if (res !== null) {
return res;
}
}
return { version: null, tag: null };
} catch (err) {
console.error(err.stack);
process.exit(1);
}
}
async function main() {
if (process.argv[2] === "tag") {
const { tag } = await latest(src);
console.log(tag);
return;
}
let { version: srcVer } = await latest(src);
let { version: dstVer } = await latest(dst);
if (!dstVer || isGreater(srcVer, dstVer)) {
console.log(srcVer);
} else {
console.log(`${srcVer}-nightly.${dateFormat(Date.UTC(), "yyyymmdd")}`);
}
}
main();