Skip to content

Commit 3585929

Browse files
author
Brian Vaughn
committed
Download error-codes from Circle CI after publishing
1 parent e624d14 commit 3585929

File tree

4 files changed

+76
-3
lines changed

4 files changed

+76
-3
lines changed

scripts/release/prepare-stable-commands/update-stable-version-numbers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ const run = async ({cwd, packages, version}, versionsMap) => {
158158
writeFileSync(diffPath, diff, {cwd});
159159
console.log(theme.header(`\n${numFilesModified} files have been updated.`));
160160
console.log(
161-
theme`A full diff is availbale at {path ${relative(cwd, diffPath)}}.`
161+
theme`A full diff is available at {path ${relative(cwd, diffPath)}}.`
162162
);
163-
await confirm('Do changes changes look correct?');
163+
await confirm('Do the changes above look correct?');
164164
};
165165

166166
// Run this directly because logPromise would interfere with printing package dependencies.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const http = require('request-promise-json');
6+
const {exec} = require('child-process-promise');
7+
const {readJsonSync} = require('fs-extra');
8+
const {logPromise} = require('../utils');
9+
const theme = require('../theme');
10+
11+
const run = async ({cwd, tags}) => {
12+
if (!tags.includes('latest')) {
13+
// Don't update error-codes for alphas.
14+
return;
15+
}
16+
17+
// All packages are built from a single source revision,
18+
// so it is safe to read build info from any one of them.
19+
const {buildNumber, environment} = readJsonSync(
20+
`${cwd}/build/node_modules/react/build-info.json`
21+
);
22+
23+
// If this release was created on Circle CI, grab the updated error codes from there.
24+
// Else the user will have to manually regenerate them.
25+
if (environment === 'ci') {
26+
// https://circleci.com/docs/2.0/artifacts/#downloading-all-artifacts-for-a-build-on-circleci
27+
// eslint-disable-next-line max-len
28+
const metadataURL = `https://circleci.com/api/v1.1/project/github/facebook/react/${buildNumber}/artifacts?circle-token=${
29+
process.env.CIRCLE_CI_API_TOKEN
30+
}`;
31+
const metadata = await http.get(metadataURL, true);
32+
33+
// Each container stores an "error-codes" artifact, unfortunately.
34+
// We want to use the one that also ran `yarn build` since it may have modifications.
35+
const {node_index} = metadata.find(
36+
entry => entry.path === 'home/circleci/project/node_modules.tgz'
37+
);
38+
const {url} = metadata.find(
39+
entry =>
40+
entry.node_index === node_index &&
41+
entry.path === 'home/circleci/project/scripts/error-codes/codes.json'
42+
);
43+
44+
// Download and stage changers
45+
await exec(`curl ${url} --output ${cwd}/scripts/error-codes/codes.json`);
46+
}
47+
};
48+
49+
module.exports = async params => {
50+
return logPromise(run(params), theme`Retrieving error codes`);
51+
};

scripts/release/publish-commands/print-follow-up-instructions.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const theme = require('../theme');
99
const run = async ({cwd, packages, tags}) => {
1010
// All packages are built from a single source revision,
1111
// so it is safe to read the commit number from any one of them.
12-
const {commit} = readJsonSync(
12+
const {commit, environment} = readJsonSync(
1313
`${cwd}/build/node_modules/react/build-info.json`
1414
);
1515

@@ -48,6 +48,26 @@ const run = async ({cwd, packages, tags}) => {
4848
commit
4949
);
5050
console.log(theme.command` git push origin --tags`);
51+
52+
if (tags.includes('latest')) {
53+
console.log();
54+
console.log(
55+
theme`{header Don't forget to commit the generated }{path scripts/error-codes/codes.json}`
56+
);
57+
if (environment === 'ci') {
58+
console.log(
59+
`This file has been updated locally. Please review it before committing.`
60+
);
61+
} else {
62+
console.log(
63+
`The release that was just published was created locally. ` +
64+
`Because of this, you will need to update error codes manually with the following commands:`
65+
);
66+
console.log(theme` {command git checkout} {version ${commit}}`);
67+
console.log(theme` {command yarn build -- --extract-errors}`);
68+
}
69+
}
70+
5171
console.log();
5272
console.log(
5373
theme`{header Don't forget to update and commit the }{path CHANGELOG}`

scripts/release/publish.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {getPublicPackages, handleError} = require('./utils');
77

88
const checkNPMPermissions = require('./publish-commands/check-npm-permissions');
99
const confirmVersionAndTags = require('./publish-commands/confirm-version-and-tags');
10+
const downloadErrorCodesFromCI = require('./publish-commands/download-error-codes-from-ci');
1011
const parseParams = require('./publish-commands/parse-params');
1112
const printFollowUpInstructions = require('./publish-commands/print-follow-up-instructions');
1213
const promptForOTP = require('./publish-commands/prompt-for-otp');
@@ -24,6 +25,7 @@ const run = async () => {
2425
await checkNPMPermissions(params);
2526
const otp = await promptForOTP(params);
2627
await publishToNPM(params, otp);
28+
await downloadErrorCodesFromCI(params);
2729
await printFollowUpInstructions(params);
2830
} catch (error) {
2931
handleError(error);

0 commit comments

Comments
 (0)