Skip to content

Commit af08b5c

Browse files
authored
Release script follow-up work after 16.1.0-beta release (#11437)
* Build script creates git tag * Build script post instructions print better relative paths * Pre-release (<1.0) version numbers also include pre-release suffix (eg '-beta.0') * Post-NPM-publish step properly handles minor rev comparison check * Release script also updates @next tag when publishing @latest * Fixed a typo. Improved inline comment.
1 parent 43a1e0d commit af08b5c

File tree

5 files changed

+76
-14
lines changed

5 files changed

+76
-14
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const chalk = require('chalk');
6+
const {execUnlessDry, logPromise} = require('../utils');
7+
8+
const run = async ({cwd, dry, version}) => {
9+
await execUnlessDry(`git tag -a ${version} -m "Tagging ${version} release"`, {
10+
cwd,
11+
dry,
12+
});
13+
};
14+
15+
module.exports = async ({cwd, dry, version}) => {
16+
return logPromise(
17+
run({cwd, dry, version}),
18+
`Creating git tag ${chalk.yellow.bold(version)}`
19+
);
20+
};

scripts/release/build-commands/print-post-build-summary.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,27 @@
33
'use strict';
44

55
const chalk = require('chalk');
6+
const {join, relative} = require('path');
67
const {getUnexecutedCommands} = require('../utils');
78

89
const CHANGELOG_PATH =
910
'https://github.com/facebook/react/edit/master/CHANGELOG.md';
1011

11-
module.exports = params => {
12+
module.exports = ({cwd, dry, path, version}) => {
13+
const publishPath = relative(
14+
process.env.PWD,
15+
join(__dirname, '../publish.js')
16+
);
1217
const command =
13-
`./publish.js -v ${params.version}` +
14-
(params.path ? ` -p ${params.path}` : '') +
15-
(params.dry ? ' --dry' : '');
18+
`${publishPath} -v ${version}` +
19+
(path ? ` -p ${path}` : '') +
20+
(dry ? ' --dry' : '');
21+
22+
const packagingFixturesPath = join(cwd, 'fixtures/packaging');
23+
const standaloneFixturePath = join(
24+
cwd,
25+
'fixtures/packaging/babel-standalone/dev.html'
26+
);
1627

1728
console.log(
1829
chalk`
@@ -29,9 +40,9 @@ module.exports = params => {
2940
3041
{bold.underline Step 2: Smoke test the packages}
3142
32-
1. Open {yellow.bold fixtures/packaging/babel-standalone/dev.html} in the browser.
43+
1. Open {yellow.bold ${standaloneFixturePath}} in the browser.
3344
2. It should say {italic "Hello world!"}
34-
3. Next go to {yellow.bold fixtures/packaging} and run {bold node build-all.js}
45+
3. Next go to {yellow.bold ${packagingFixturesPath}} and run {bold node build-all.js}
3546
4. Install the "serve" module ({bold npm install -g serve})
3647
5. Go to the repo root and {bold serve -s .}
3748
6. Open {blue.bold http://localhost:5000/fixtures/packaging}

scripts/release/build-commands/update-package-versions.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@ const update = async ({cwd, dry, version}) => {
3232
const path = join(cwd, 'packages', project, 'package.json');
3333
const json = await readJson(path);
3434

35-
// Unstable packages (eg version < 1.0) are treated differently.
36-
// In order to simplify DX for the release engineer,
37-
// These packages are auto-incremented by a minor version number.
35+
// Unstable packages (eg version < 1.0) are treated specially:
36+
// Rather than use the release version (eg 16.1.0)-
37+
// We just auto-increment the minor version (eg 0.1.0 -> 0.2.0).
38+
// If we're doing a prerelease, we also append the suffix (eg 0.2.0-beta).
3839
if (semver.lt(json.version, '1.0.0')) {
39-
json.version = `0.${semver.minor(json.version) + 1}.0`;
40+
const prerelease = semver.prerelease(version);
41+
let suffix = '';
42+
if (prerelease) {
43+
suffix = `-${prerelease.join('.')}`;
44+
}
45+
46+
json.version = `0.${semver.minor(json.version) + 1}.0${suffix}`;
4047
} else {
4148
json.version = version;
4249
}

scripts/release/build.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const run = async () => {
99
const chalk = require('chalk');
1010
const logUpdate = require('log-update');
1111

12+
const addGitTag = require('./build-commands/add-git-tag');
1213
const buildArtifacts = require('./build-commands/build-artifacts');
1314
const checkCircleCiStatus = require('./build-commands/check-circle-ci-status');
1415
const checkEnvironmentVariables = require('./build-commands/check-environment-variables');
@@ -39,6 +40,7 @@ const run = async () => {
3940
await runAutomatedTests(params);
4041
await updatePackageVersions(params);
4142
await buildArtifacts(params);
43+
await addGitTag(params);
4244
await printPostBuildSummary(params);
4345
} catch (error) {
4446
logUpdate.clear();

scripts/release/publish-commands/publish-to-npm.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,54 @@
33
'use strict';
44

55
const chalk = require('chalk');
6+
const {readJson} = require('fs-extra');
67
const {join} = require('path');
78
const semver = require('semver');
89
const {execRead, execUnlessDry, logPromise} = require('../utils');
910
const {projects} = require('../config');
1011

1112
const push = async ({cwd, dry, version}) => {
1213
const errors = [];
13-
const tag = semver.prerelease(version) ? 'next' : 'latest';
14+
const isPrerelease = semver.prerelease(version);
15+
const tag = isPrerelease ? 'next' : 'latest';
1416

1517
const publishProject = async project => {
1618
try {
1719
const path = join(cwd, 'build', 'packages', project);
1820
await execUnlessDry(`npm publish --tag ${tag}`, {cwd: path, dry});
1921

22+
const packagePath = join(
23+
cwd,
24+
'build',
25+
'packages',
26+
project,
27+
'package.json'
28+
);
29+
const packageJSON = await readJson(packagePath);
30+
const packageVersion = packageJSON.version;
31+
2032
if (!dry) {
2133
const status = JSON.parse(
2234
await execRead(`npm info ${project} dist-tags --json`)
2335
);
2436
const remoteVersion = status[tag];
2537

26-
if (remoteVersion !== version) {
38+
// Compare remote version to package.json version,
39+
// To better handle the case of pre-release versions.
40+
if (remoteVersion !== packageVersion) {
2741
throw Error(
28-
chalk`Publised version {yellow.bold ${version}} for ` +
42+
chalk`Publised version {yellow.bold ${packageVersion}} for ` +
2943
`{bold ${project}} but NPM shows {yellow.bold ${remoteVersion}}`
3044
);
3145
}
46+
47+
// If we've just published a stable release,
48+
// Update the @next tag to also point to it (so @next doens't lag behind).
49+
if (!isPrerelease) {
50+
await execUnlessDry(
51+
`npm dist-tag add ${project}@${packageVersion} next`
52+
);
53+
}
3254
}
3355
} catch (error) {
3456
errors.push(error.message);
@@ -48,5 +70,5 @@ const push = async ({cwd, dry, version}) => {
4870
};
4971

5072
module.exports = async params => {
51-
return logPromise(push(params), 'Pushing to git remote');
73+
return logPromise(push(params), 'Publishing packages to NPM');
5274
};

0 commit comments

Comments
 (0)