Skip to content

Commit

Permalink
Download error-codes from Circle CI after publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Nov 19, 2018
1 parent e624d14 commit 3585929
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ const run = async ({cwd, packages, version}, versionsMap) => {
writeFileSync(diffPath, diff, {cwd});
console.log(theme.header(`\n${numFilesModified} files have been updated.`));
console.log(
theme`A full diff is availbale at {path ${relative(cwd, diffPath)}}.`
theme`A full diff is available at {path ${relative(cwd, diffPath)}}.`
);
await confirm('Do changes changes look correct?');
await confirm('Do the changes above look correct?');
};

// Run this directly because logPromise would interfere with printing package dependencies.
Expand Down
51 changes: 51 additions & 0 deletions scripts/release/publish-commands/download-error-codes-from-ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env node

'use strict';

const http = require('request-promise-json');
const {exec} = require('child-process-promise');
const {readJsonSync} = require('fs-extra');
const {logPromise} = require('../utils');
const theme = require('../theme');

const run = async ({cwd, tags}) => {
if (!tags.includes('latest')) {
// Don't update error-codes for alphas.
return;
}

// All packages are built from a single source revision,
// so it is safe to read build info from any one of them.
const {buildNumber, environment} = readJsonSync(
`${cwd}/build/node_modules/react/build-info.json`
);

// If this release was created on Circle CI, grab the updated error codes from there.
// Else the user will have to manually regenerate them.
if (environment === 'ci') {
// https://circleci.com/docs/2.0/artifacts/#downloading-all-artifacts-for-a-build-on-circleci
// eslint-disable-next-line max-len
const metadataURL = `https://circleci.com/api/v1.1/project/github/facebook/react/${buildNumber}/artifacts?circle-token=${
process.env.CIRCLE_CI_API_TOKEN
}`;
const metadata = await http.get(metadataURL, true);

// Each container stores an "error-codes" artifact, unfortunately.
// We want to use the one that also ran `yarn build` since it may have modifications.
const {node_index} = metadata.find(
entry => entry.path === 'home/circleci/project/node_modules.tgz'
);
const {url} = metadata.find(
entry =>
entry.node_index === node_index &&
entry.path === 'home/circleci/project/scripts/error-codes/codes.json'
);

// Download and stage changers
await exec(`curl ${url} --output ${cwd}/scripts/error-codes/codes.json`);
}
};

module.exports = async params => {
return logPromise(run(params), theme`Retrieving error codes`);
};
22 changes: 21 additions & 1 deletion scripts/release/publish-commands/print-follow-up-instructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const theme = require('../theme');
const run = async ({cwd, packages, tags}) => {
// All packages are built from a single source revision,
// so it is safe to read the commit number from any one of them.
const {commit} = readJsonSync(
const {commit, environment} = readJsonSync(
`${cwd}/build/node_modules/react/build-info.json`
);

Expand Down Expand Up @@ -48,6 +48,26 @@ const run = async ({cwd, packages, tags}) => {
commit
);
console.log(theme.command` git push origin --tags`);

if (tags.includes('latest')) {
console.log();
console.log(
theme`{header Don't forget to commit the generated }{path scripts/error-codes/codes.json}`
);
if (environment === 'ci') {
console.log(
`This file has been updated locally. Please review it before committing.`
);
} else {
console.log(
`The release that was just published was created locally. ` +
`Because of this, you will need to update error codes manually with the following commands:`
);
console.log(theme` {command git checkout} {version ${commit}}`);
console.log(theme` {command yarn build -- --extract-errors}`);
}
}

console.log();
console.log(
theme`{header Don't forget to update and commit the }{path CHANGELOG}`
Expand Down
2 changes: 2 additions & 0 deletions scripts/release/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {getPublicPackages, handleError} = require('./utils');

const checkNPMPermissions = require('./publish-commands/check-npm-permissions');
const confirmVersionAndTags = require('./publish-commands/confirm-version-and-tags');
const downloadErrorCodesFromCI = require('./publish-commands/download-error-codes-from-ci');
const parseParams = require('./publish-commands/parse-params');
const printFollowUpInstructions = require('./publish-commands/print-follow-up-instructions');
const promptForOTP = require('./publish-commands/prompt-for-otp');
Expand All @@ -24,6 +25,7 @@ const run = async () => {
await checkNPMPermissions(params);
const otp = await promptForOTP(params);
await publishToNPM(params, otp);
await downloadErrorCodesFromCI(params);
await printFollowUpInstructions(params);
} catch (error) {
handleError(error);
Expand Down

0 comments on commit 3585929

Please sign in to comment.