[rrm] Create start-release command, create git utils
This does the essentials for starting a new release on the stable branch
Paul O’Shannessy committed
Sep 8, 2016 at 15:18 UTC
0fbe92748654a1240d18b3847e4d532c70632a1b
3 files changed
+94
scripts/release-manager/cli.js
+1
@@ -42,6 +42,7 @@ const COMMANDS = [
42
'npm-publish',
43
'npm-check-access',
44
'npm-grant-access',
45
+ 'start-release',
46
];
47
48
scripts/release-manager/commands/start-release.js
new
+44
@@ -0,0 +1,44 @@
1
+// fetch upstream
2
+// checkout 15-dev, update
3
+// merge upstream/15-stable in
4
+// done
5
+
6
+'use strict';
7
+
8
+const chalk = require('chalk');
9
+
10
+var git = require('./utils/git');
11
+
12
+module.exports = function(vorpal, app) {
13
+ vorpal
14
+ .command('start-release')
15
+ .description('Start the process for shipping the next release')
16
+ .action(function(args) {
17
+ return new Promise((resolve, reject) => {
18
+ // TODO: ensure that repo has upstream remote, correct branches setup.
19
+
20
+ if (!git.isClean(app)) {
21
+ this.log('ERROR: repo not in clean state');
22
+ return reject();
23
+ }
24
+
25
+ // Fetch upstream - this ensures upstream/15-stable is updated and we
26
+ // won't rely on the local branch.
27
+ git.fetch(app, 'upstream');
28
+
29
+ // Checkout 15-dev
30
+ git.checkout(app, '15-dev');
31
+
32
+ // Update to ensure latest commits are in. Will hit network again but
33
+ // shouldn't need to get anything.
34
+ git.pull(app);
35
+
36
+ // Merge 15-stable in
37
+ git.merge(app, 'upstream/15-stable', false);
38
+
39
+ this.log(chalk.green.bold(`OK!`));
40
+ this.log(`You can now start cherry-picking commits to this branch using the "stable-prs" command.`);
41
+ resolve();
42
+ });
43
+ });
44
+};
scripts/release-manager/commands/utils/git.js
new
+49
@@ -0,0 +1,49 @@
1
+'use strict';
2
+
3
+function isClean(app) {
4
+ return getStatus(app) === '';
5
+}
6
+
7
+function getStatus(app) {
8
+ return app.execInRepo(`git status --untracked-files=no --porcelain`);
9
+}
10
+
11
+function getBranch(app) {
12
+ return app.execInRepo(`git symbolic-ref HEAD`);
13
+}
14
+
15
+function fetch(app, remote) {
16
+ return app.execInRepo(`git fetch ${remote}`);
17
+}
18
+
19
+function checkout(app, ref) {
20
+ return app.execInRepo(`git checkout ${ref}`);
21
+}
22
+
23
+function pull(app, ref) {
24
+ ref = ref || '';
25
+ return app.execInRepo(`git pull ${ref}`);
26
+}
27
+
28
+function merge(app, ref, ff, msg) {
29
+ let opts = [
30
+ ff ? '--ff-only' : '--no-ff',
31
+ ];
32
+ if (!msg) {
33
+ opts.push('--no-edit');
34
+ } else {
35
+ opts.push(`-m '${msg}''`);
36
+ }
37
+ return app.execInRepo(`git merge ${opts.join(' ')} ${ref}`);
38
+}
39
+
40
+module.exports = {
41
+ getBranch,
42
+ getStatus,
43
+ isClean,
44
+
45
+ checkout,
46
+ fetch,
47
+ pull,
48
+ merge,
49
+};