-
Notifications
You must be signed in to change notification settings - Fork 15
/
release.js
executable file
·575 lines (448 loc) · 12.8 KB
/
release.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
#!/usr/bin/env node
var child_process = require('child_process'),
format = require('util').format,
fs = require('fs'),
os = require('os'),
path = require('path'),
resolve = require('path').resolve,
git = require('./lib/git'),
ver = require('./lib/version'),
tags = require('./lib/tags'),
relnotes = require('./lib/relnotes'),
changelog = require('./lib/changelog'),
argv = require('optimist').argv,
progress = require('./lib/progress'),
authors = require('./lib/authors');
var SCHEDULE = [
verifyTreeClean,
setReleaseVersion,
checkTagSanity,
getBaseVersion,
updateAuthorsAndMailmap,
updateVersionFiles,
checkAutogenVersions,
prepareReleaseNotes,
addReleaseNotesToChangeLog,
stageVersionFiles,
stageAutogen,
stageChangeLog,
stageAuthorsAndMailmap,
commitRelease,
tagRelease,
addSHASumsToChangeLog,
cloneDistRepo,
createDistDirectory,
createCMakeTarBall,
createAutotoolsTarBall,
signTarballs,
generateIndex,
commitReleaseFiles,
reviewTagAndCommits,
pushTarBalls,
pushTag,
pushBranch,
done,
updateVersionFiles,
stageVersionFiles,
done,
];
if (!argv.dir || !argv.version) {
logError('Usage: release.js --version <version> --dir <directory> [--continue | --abort ]');
return process.exit(1);
}
var dir = resolve(argv.dir),
disttopdir = path.join(dir, 'dist.libuv.org');
gitClient = git.createClient(dir),
distClient = git.createClient(disttopdir),
state = progress.state;
progress.read(gitClient, function(err) {
if (err)
throw err;
if (state.step === undefined) {
if (argv['abort'] || argv['continue']) {
logError('No release in progress.');
return process.exit(1);
}
state.step = 0;
state.argv = argv;
step();
} else {
if (argv['abort'])
abort();
else if (argv['continue'])
step();
else {
logError('Looks like release is in progress. Use the --continue or --abort option.');
return process.exit(1);
}
}
});
function step() {
var steps = SCHEDULE;
if (state.step >= steps.length) {
progress.destroy(gitClient, function(err) {
if (err)
throw err;
});
} else {
progress.write(gitClient, function(err, cb) {
if (err)
throw err;
try {
console.log('... %s', steps[state.step].name);
steps[state.step]();
} catch (err) {
abort(err);
}
})
}
}
function logError() {
if (!arguments.length)
return;
var args = Array.prototype.slice.call(arguments, 0);
args = args.map(function(arg) {
if (arg && arg.message && arg.stack)
return arg.message + '\n' + arg.stack;
return arg;
});
console.error.apply(console, args);
}
function pauseNext() {
var args = arguments;
state.step++;
progress.write(gitClient, function(err, cb) {
if (err)
throw err;
if (args.length) {
logError('');
logError.apply(null, args);
}
logError('Use `release.js --dir "%s" --continue` when done, or `--abort` to abort.',
dir);
});
}
function pauseRetry() {
var args = arguments;
progress.write(gitClient, function(err, cb) {
if (err)
throw err;
if (args.length) {
logError('');
logError.apply(null, args);
}
logError('Use `release.js --dir "%s" --continue` to retry, or `--abort` to abort.',
dir);
});
}
function next() {
state.step++;
step();
}
function abort() {
var args = arguments;
progress.destroy(gitClient, function(err) {
if (err)
throw err;
logError.apply(null, args);
logError('aborted');
});
}
function nextOrAbort(err) {
if (err)
return abort(err);
next();
}
function nextOrRetry(err) {
if (err)
return pauseRetry(err);
next();
}
function verifyTreeClean() {
gitClient.isClean(function(err, clean) {
if (err)
return abort(err);
if (!clean)
return abort("The working tree is not clean. Please stash or commit " +
"your work before making a release.");
next();
});
}
function setReleaseVersion() {
var version;
try {
version = ver.parse(state.argv.version);
} catch (e) {
return abort(e);
}
version.is_release = true;
state.releaseVersion = version;
state.version = clone(state.releaseVersion);
next();
}
function checkTagSanity() {
//tags.checkSanity(gitClient, state.version, nextOrAbort);
// TODO
next();
}
function getBaseVersion() {
tags.getBase(gitClient, state.version, function(err, baseTag) {
if (err)
return abort(err);
var baseVersion;
try {
var baseVersion = ver.parse(baseTag);
} catch (e) {
return abort(e);
}
state.baseVersion = baseVersion;
next();
});
}
function updateVersionFiles() {
gitClient.top(function(err, root) {
if (err)
return abort(err);
var waiting = 2,
failed = false;
ver.updateVersionFile(root + '/include/uv/version.h', state.version, afterUpdate);
ver.updateConfigureFile(root + '/configure.ac', state.version, afterUpdate);
function afterUpdate(err) {
if (failed)
return;
if (err)
return failed = true, abort(err);
if (!--waiting)
next();
}
});
}
function checkAutogenVersions() {
child_process.execFile('./autogen.sh', ['release'], { stdio: 'inherit', cwd: dir },
function(err, stdout, stderr) {
if (err) {
console.log(stdout);
console.log(stderr);
return pauseRetry(err);
}
next();
});
}
function updateAuthorsAndMailmap() {
authors.updateAuthors(gitClient, function(err, madeChanges) {
if (err)
return abort(err);
if (!madeChanges)
return next();
gitClient.top(function(err, dir) {
if (err)
return abort(err);
var cp = gitClient.spawn(['--no-pager', 'diff', 'AUTHORS', '.mailmap'], { cwd: dir, stdio: 'inherit' });
cp.on('close', function() {
pauseNext("Changes were made to AUTHORS or .mailmap. Please review these.");
});
});
});
}
function prepareReleaseNotes() {
relnotes.prepare(gitClient, state.version, state.baseVersion, function(err, text) {
if (err)
return abort(err);
state.releaseNotes = text;
next();
});
}
function addReleaseNotesToChangeLog() {
changelog.addReleaseNotes(gitClient, state.releaseNotes, nextOrRetry);
}
function addSHASumsToChangeLog() {
changelog.addSHASums(gitClient, function(err) {
if (err)
return abort(err);
gitClient.add(['ChangeLog'], function(err) {
if (err)
return abort(err);
gitClient.commit([], 'Add SHA to ChangeLog', nextOrRetry);
});
});
}
function commitRelease() {
var message = relnotes.reflow(state.releaseNotes, 72);
gitClient.commit([], message, nextOrRetry);
}
function tagRelease() {
var releaseTag = state.releaseTag = ver.format(state.version);
var message = relnotes.reflow(state.releaseNotes, 79);
gitClient.tag([releaseTag, '-as'], message, nextOrRetry);
}
function stageVersionFiles() {
var files = ['configure.ac', 'include/uv/version.h'];
gitClient.add(files, nextOrRetry);
}
function stageAuthorsAndMailmap() {
gitClient.add(['AUTHORS', '.mailmap'], nextOrRetry);
}
function stageChangeLog() {
gitClient.add(['ChangeLog'], nextOrRetry);
}
function stageAutogen() {
gitClient.add(['m4/libuv-check-versions.m4'], nextOrRetry);
}
function reviewTagAndCommits() {
gitClient.top(function(err, dir) {
if (err)
return abort(err);
var cp = gitClient.spawn(['--no-pager', 'show', state.releaseTag, 'HEAD'], { cwd: dir, stdio: 'inherit' });
cp.on('close', function() {
pauseNext('Please review the tag and the commits that are about to be pushed.');
});
});
}
function getDistDir(rel) {
var tag = ver.format(state.releaseVersion);
var distdir = path.join('dist.libuv.org', 'dist', tag);
if (!rel)
distdir = path.join(dir, distdir);
return distdir;
}
function cloneDistRepo() {
if (fs.existsSync(disttopdir)) {
distClient.exec(['pull', '--no-ff'], nextOrRetry);
} else {
child_process.execFile('git', ['clone', 'https://github.com/libuv/dist.libuv.org.git'], { stdio: 'inherit', cwd: dir }, nextOrRetry);
}
}
function createDistDirectory() {
var disttopdir = path.join(dir, 'dist.libuv.org');
distClient.isClean(function(err, clean) {
if (err)
return abort(err);
if (!clean)
return abort("The dist.libuv.org tree is not clean. Please stash or commit " +
"your work before making a release.");
var distdir = getDistDir(false);
fs.mkdir(distdir, function(err) {
if (err && err.code !== 'EEXIST')
return pauseRetry(err);
if (fs.readdirSync(distdir).length !== 0)
return pauseRetry("dist dir is not empty");
next();
});
});
}
function createCMakeTarBall() {
var distdir = getDistDir(true);
var tag = ver.format(state.releaseVersion);
var filename = format('libuv-%s.tar.gz', tag);
var prefix = format('libuv-%s/', tag);
var command = format('git archive %s --format=tar --prefix=%s | gzip -9 > %s',
tag,
prefix,
path.join(distdir, filename));
child_process.exec(command, { stdio: 'inherit', cwd: dir }, nextOrRetry);
}
function createAutotoolsTarBall() {
var tag = ver.format(state.releaseVersion);
var distver = format('%d.%d.%d',
state.releaseVersion.major,
state.releaseVersion.minor,
state.releaseVersion.patch);
child_process.execFile('./autogen.sh', ['release'], { stdio: 'inherit', cwd: dir },
function(err, stdout, stderr) {
if (err) {
console.log(stdout);
console.log(stderr);
return pauseRetry(err);
}
try {
var builddir = fs.mkdtempSync(path.join(os.tmpdir(), 'libuv-build-'));
console.log(' attempting build in %s', builddir);
} catch (err) {
return pauseRetry(err);
}
child_process.execFile(dir + '/configure', [],
{ stdio: 'inherit', cwd: builddir },
function(err, stdout, stderr) {
if (err) {
console.log(stdout);
console.log(stderr);
return pauseRetry(err);
}
child_process.execFile('make', ['dist', '-j' + os.cpus().length], // TODO: use distcheck here
{ stdio: 'pipe', cwd: builddir },
function(err, stdout, stderr) {
if (err) {
console.log(stdout);
console.log(stderr);
return pauseRetry(err);
}
var srcfilename = path.join(builddir, format('libuv-%s.tar.gz', distver));
var dstfilename = path.join(getDistDir(false), format('libuv-%s-dist.tar.gz', tag));
try {
fs.renameSync(srcfilename, dstfilename);
fs.rmdirSync(builddir, { recursive: true }); // in future nodejs, this will be called rmSync
} catch (err) {
return pauseRetry(err);
}
next();
});
});
});
}
function signTarballs() {
var tag = ver.format(state.releaseVersion);
var filename = format('libuv-%s.tar.gz', tag);
var distdir = getDistDir(false);
var signFilename = filename + ".sign";
var args = ['-a', '--output', signFilename, '--detach-sign', filename];
child_process.execFile('gpg', args, { stdio: 'inherit', cwd: distdir }, function(err) {
if (err)
return pauseRetry(err);
var filename = format('libuv-%s-dist.tar.gz', tag);
var signFilename = filename + ".sign";
var args = ['-a', '--output', signFilename, '--detach-sign', filename];
child_process.execFile('gpg', args, { stdio: 'inherit', cwd: distdir }, nextOrRetry);
});
}
function commitReleaseFiles() {
var tag = ver.format(state.releaseVersion);
distClient.add(['index.html', 'metadata.json', 'dist'], function(err) {
if (err)
return pauseRetry(err);
distClient.commit([], 'Release Version ' + tag.slice(1), nextOrRetry);
});
}
function generateIndex() {
child_process.execFile('node', ['generate-index.js'], { stdio: 'inherit', cwd: disttopdir }, nextOrRetry);
}
function pushTarBalls() {
distClient.exec(['push'], nextOrRetry);
}
function pushTag() {
var remote = state.argv.remote || 'origin';
gitClient.exec(['push', remote, state.releaseTag], nextOrRetry);
}
function pushBranch() {
var remote = state.argv.remote || 'origin';
gitClient.symbolicRef(function(err, ref) {
if (err)
return abort(err);
var branch = ref.replace(/^refs\/heads\//, '');
gitClient.exec(['push', remote, branch], nextOrRetry);
});
}
function done() {
logError('We\'re done!');
state.version.is_release = false;
state.version.patch++;
state.version.suffix = "dev";
next();
}
function clone(obj) {
var tgt = {};
for (var key in obj) {
if (obj.hasOwnProperty(key))
tgt[key] = obj[key]
}
return tgt;
}