-
Notifications
You must be signed in to change notification settings - Fork 65
/
release
executable file
·92 lines (74 loc) · 2.21 KB
/
release
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
#!/usr/bin/env node
// automate the release process
// pre-requisites:
// - real release repo is in a remote called "upstream"
// - on the branch "main"
// - repo clean (nothing pending vs. HEAD)
// - 2FA turned on in npm
"use strict";
const { spawn } = require("child_process");
const fs = require("fs").promises;
const path = require("path");
if (process.argv.length < 3) {
console.error(`usage: ${process.argv[1]} [--dry-run] <VERSION>`);
process.exit(1);
}
const args = process.argv.slice(2);
let DRY = false;
if (args[0] === "--dry-run") {
DRY = true;
args.shift();
}
const VERSION = args[0];
function e(cmd) {
console.log(`>>> ${cmd} <<<`);
return new Promise((resolve, reject) => {
const c = spawn(cmd, {
shell: true,
stdio: "inherit"
});
c.on("error", reject);
c.on("close", code => {
if (code === 0) {
resolve();
} else {
reject(new Error(`${cmd} failed, exit code ${code}`));
}
});
});
}
async function main() {
const root = path.resolve(__dirname, "..");
process.chdir(root);
// check that we're clean
await e("git diff-index --quiet HEAD");
// check that we're on main
await e("[[ `git branch --show-current` == main ]]");
// update version in package.json
const pkg = path.join(root, "package.json");
const ptxt = await fs.readFile(pkg, "utf8");
const pjson = JSON.parse(ptxt);
pjson.version = VERSION;
await fs.writeFile(pkg, JSON.stringify(pjson, null, 2));
// build
await e("npm run build");
// add files
await e(`git add ${pkg} lib/version.js lib/parser.js docs/js/benchmark-bundle.min.js docs/js/test-bundle.min.js docs/vendor/peggy/peggy.min.js`);
// check in
await e(`git commit -m "Update for v${VERSION}"`);
// check that we're clean
await e("git diff-index --quiet HEAD");
if (DRY) {
console.log("Stopping. Dry run. Reverse last commit with `git reset --hard HEAD~1`");
process.exit(0);
}
// tag
await e(`git tag "v${VERSION}"`);
// push tag
await e(`git push upstream main "v${VERSION}"`);
// publish
await e("npm publish");
// go to GitHub Release page
console.log("Go to https://github.com/peggyjs/peggy/releases/new");
}
main().catch(e => console.error(e.message));