Skip to content

Commit

Permalink
Stashing changes to test CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Nov 17, 2018
1 parent 75f0f8e commit 200f17b
Show file tree
Hide file tree
Showing 22 changed files with 360 additions and 97 deletions.
3 changes: 2 additions & 1 deletion scripts/release/ci-add-build-info-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const run = async () => {

const cwd = join(__dirname, '..', '..');

const {checksum, commit, branch} = await getBuildInfo();
const {branch, checksum, commit, reactVersion} = await getBuildInfo();

const packages = getPackages(join(cwd, 'packages'));
const packagesDir = join(cwd, 'packages');
Expand All @@ -26,6 +26,7 @@ const run = async () => {
checksum,
commit,
environment: 'ci',
reactVersion,
};

for (let i = 0; i < packages.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/release/ci-update-package-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const run = async () => {

const cwd = join(__dirname, '..', '..');

const {version} = await getBuildInfo();
const {reactVersion, version} = await getBuildInfo();

await updateVersionsForCanary(cwd, version);
await updateVersionsForCanary(cwd, reactVersion, version);
};

// Install (or update) release script dependencies before proceeding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {writeJson} = require('fs-extra');
const {join} = require('path');
const {getPackages, logPromise} = require('../utils');

const run = async ({branch, checksum, commit, tempDirectory}) => {
const run = async ({branch, checksum, commit, reactVersion, tempDirectory}) => {
const packages = getPackages(join(tempDirectory, 'packages'));
const packagesDir = join(tempDirectory, 'packages');

Expand All @@ -16,6 +16,7 @@ const run = async ({branch, checksum, commit, tempDirectory}) => {
checksum,
commit,
environment: 'local',
reactVersion,
};

for (let i = 0; i < packages.length; i++) {
Expand Down
10 changes: 9 additions & 1 deletion scripts/release/create-canary-commands/build-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ const run = async ({cwd, dry, tempDirectory}) => {
};

await exec('yarn install', defaultOptions);
await exec('yarn build -- --extract-errors', defaultOptions);

// We run rollup directly to avoid the version check.
// It's expected that canary package version and renderer version mismatch.
// Canaries version numbers use the format of 0.0.0-<sha> to be easily recognized (e.g. 0.0.0-57239eac8).
// A separate "React version" is used for the embedded renderer version to support DevTools,
// since it needs to distinguish between different version ranges of React.
// It is based on the version of React in the local package.json (e.g. 16.6.1-canary-57239eac8).
// Both numbers will be replaced if the canary is promoted to a stable release.
await exec('node ./scripts/rollup/build.js --extract-errors', defaultOptions);

const tempNodeModulesPath = join(tempDirectory, 'build', 'node_modules');
const buildPath = join(cwd, 'build');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env node

'use strict';

const chalk = require('chalk');
const clear = require('clear');
const {confirm} = require('../utils');

const run = async () => {
clear();

console.log(
chalk.red(
'This script does not run any automated tests.' +
'You should run them manually before creating a canary release.'
)
);

await confirm('Do you want to proceed?');

clear();
};

module.exports = run;
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const run = async ({cwd, dry, tempDirectory}) => {
`cp -r ${tempDirectory}/build/node_modules/*.tgz ${cwd}/build/node_modules/`
);

// Unpack packages and parepare to publish.
// Unpack packages and prepare to publish.
const compressedPackages = readdirSync('build/node_modules/');
for (let i = 0; i < compressedPackages.length; i++) {
await exec(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
const chalk = require('chalk');
const {logPromise, updateVersionsForCanary} = require('../utils');

module.exports = async ({tempDirectory, version}) => {
module.exports = async ({reactVersion, tempDirectory, version}) => {
return logPromise(
updateVersionsForCanary(tempDirectory, version),
updateVersionsForCanary(tempDirectory, reactVersion, version),
`Updating version numbers (${chalk.yellow.bold(version)})`
);
};
22 changes: 19 additions & 3 deletions scripts/release/create-canary.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ const {getBuildInfo, handleError} = require('./utils');

// This script is an escape hatch!
// It exists for special case manual builds.
// The typical suggesgted release process is to create a canary from a CI artifact.
// The typical suggested release process is to create a canary from a CI artifact.
// This build script is optimized for speed and simplicity.
// It doesn't run all of the tests that the CI environment runs.
// You're expected to run those manually before publishing a release.

const addBuildInfoJSON = require('./create-canary-commands/add-build-info-json');
const buildArtifacts = require('./create-canary-commands/build-artifacts');
const confirmAutomatedTesting = require('./create-canary-commands/confirm-automated-testing');
const copyRepoToTempDirectory = require('./create-canary-commands/copy-repo-to-temp-directory');
const npmPackAndUnpack = require('./create-canary-commands/npm-pack-and-unpack');
const printPrereleaseSummary = require('./shared-commands/print-prerelease-summary');
Expand All @@ -23,10 +24,25 @@ const updateVersionNumbers = require('./create-canary-commands/update-version-nu
const run = async () => {
try {
const cwd = join(__dirname, '..', '..');
const {branch, checksum, commit, version} = await getBuildInfo();
const {
branch,
checksum,
commit,
reactVersion,
version,
} = await getBuildInfo();
const tempDirectory = join(tmpdir(), `react-${commit}`);
const params = {branch, checksum, commit, cwd, tempDirectory, version};
const params = {
branch,
checksum,
commit,
cwd,
reactVersion,
tempDirectory,
version,
};

await confirmAutomatedTesting(params);
await copyRepoToTempDirectory(params);
await updateVersionNumbers(params);
await addBuildInfoJSON(params);
Expand Down
1 change: 1 addition & 0 deletions scripts/release/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dependencies": {
"chalk": "^2.1.0",
"child-process-promise": "^2.2.1",
"clear": "^0.1.0",
"cli-spinners": "^1.1.0",
"command-line-args": "^4.0.7",
"command-line-usage": "^4.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const run = async ({build, cwd}) => {
`tar zxvf ${cwd}/build/node_modules.tgz -C ${cwd}/build/node_modules/`
);

// Unpack packages and parepare to publish
// Unpack packages and prepare to publish
const compressedPackages = readdirSync('build/node_modules/');
for (let i = 0; i < compressedPackages.length; i++) {
await exec(
Expand Down
1 change: 0 additions & 1 deletion scripts/release/prepare-canary-commands/parse-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const paramDefinitions = [
type: Number,
description:
'Circle CI build identifier (e.g. https://circleci.com/gh/facebook/react/<build>)',
defaultValue: false,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'use strict';

const chalk = require('chalk');
const clear = require('clear');
const {readFileSync, writeFileSync} = require('fs');
const {readJson, writeJson} = require('fs-extra');
const {join} = require('path');
Expand Down Expand Up @@ -50,7 +51,7 @@ const run = async ({cwd, packages, version}, versionsMap) => {
// If the source dependency's version and the constraint match,
// we will need to update the constraint to point at the dependency's new release version,
// (e.g. scheduler@^0.11.0 becomes scheduler@^0.12.0 when we release scheduler 0.12.0).
// Othewise we leave the constraint alone (e.g. react@^16.0.0 doesn't change between releases).
// Otherwise we leave the constraint alone (e.g. react@^16.0.0 doesn't change between releases).
// Note that in both cases, we must update the target package JSON,
// since canary releases are all locked to the canary version (e.g. 0.0.0-ddaf2b07c).
if (
Expand All @@ -74,7 +75,7 @@ const run = async ({cwd, packages, version}, versionsMap) => {
// Update all package JSON versions and their dependencies/peerDependencies.
// This must be done in a way that respects semver constraints (e.g. 16.7.0, ^16.7.0, ^16.0.0).
// To do this, we use the dependencies defined in the source package JSONs,
// because the canary dependencies have already been falttened to an exact match (e.g. 0.0.0-ddaf2b07c).
// because the canary dependencies have already been flattened to an exact match (e.g. 0.0.0-ddaf2b07c).
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i];
const packageJSONPath = join(nodeModulesPath, packageName, 'package.json');
Expand All @@ -87,6 +88,8 @@ const run = async ({cwd, packages, version}, versionsMap) => {
await writeJson(packageJSONPath, packageJSON, {spaces: 2});
}

clear();

// Print the map of versions and their dependencies for confirmation.
const printDependencies = (maybeDependency, label) => {
if (maybeDependency) {
Expand Down Expand Up @@ -115,6 +118,8 @@ const run = async ({cwd, packages, version}, versionsMap) => {
}
await confirm('Do the versions above look correct?');

clear();

// Find-and-replace hard coded version (in built JS) for renderers.
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i];
Expand All @@ -131,6 +136,7 @@ const run = async ({cwd, packages, version}, versionsMap) => {
new RegExp(version, 'g'),
versionsMap.get(packageName)
);
// TODO Replace buildInfo.reactVersion too
if (beforeContents !== afterContents) {
printDiff(beforeContents, afterContents);
writeFileSync(path, afterContents, {cwd});
Expand Down
40 changes: 40 additions & 0 deletions scripts/release/publish-commands/check-npm-permissions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env node

'use strict';

const chalk = require('chalk');
const {execRead, logPromise} = require('../utils');

const run = async ({cwd, packages, version}) => {
const currentUser = await execRead('npm whoami');
const failedProjects = [];

const checkProject = async project => {
const owners = (await execRead(`npm owner ls ${project}`))
.split('\n')
.filter(owner => owner)
.map(owner => owner.split(' ')[0]);

if (!owners.includes(currentUser)) {
failedProjects.push(project);
}
};

await logPromise(
Promise.all(packages.map(checkProject)),
`Checking ${chalk.yellow.bold(currentUser)}'s NPM permissions`
);

if (failedProjects.length) {
throw Error(
chalk`
Insufficient NPM permissions
{white NPM user {yellow.bold ${currentUser}} is not an owner for:}
{red ${failedProjects.join(', ')}}
{white Please contact a React team member to be added to the above project(s).}
`
);
}
};

module.exports = run;
47 changes: 47 additions & 0 deletions scripts/release/publish-commands/confirm-version-and-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env node

'use strict';

const chalk = require('chalk');
const clear = require('clear');
const {readJson} = require('fs-extra');
const {join} = require('path');
const {confirm} = require('../utils');

const run = async ({cwd, packages, tags}) => {
clear();

if (tags.length === 1) {
console.log(
chalk`{green ✓} You are about the publish the following packages under the tag {yellow ${tags}}`
);
} else {
console.log(
chalk`{green ✓} You are about the publish the following packages under the tags {yellow ${tags.join(
', '
)}}`
);
}

// Cache all package JSONs for easy lookup below.
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i];
const packageJSONPath = join(
cwd,
'build/node_modules',
packageName,
'package.json'
);
const packageJSON = await readJson(packageJSONPath);
console.log(
chalk`• {green ${packageName}} @ {yellow ${chalk.yellow(
packageJSON.version
)}}`
);
}
await confirm('Do you want to proceed?');
};

// Run this directly because it's fast,
// and logPromise would interfere with console prompting.
module.exports = run;
16 changes: 13 additions & 3 deletions scripts/release/publish-commands/parse-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const commandLineUsage = require('command-line-usage');
const figlet = require('figlet');

const paramDefinitions = [
{
name: 'dry',
type: Boolean,
description: 'Dry run command without actually publishing to NPM.',
defaultValue: false,
},
{
name: 'tags',
type: String,
Expand All @@ -19,7 +25,7 @@ const paramDefinitions = [
module.exports = () => {
const params = commandLineArgs(paramDefinitions);

if (!params.tags) {
if (!params.tags || params.tags.length === 0) {
const usage = commandLineUsage([
{
content: chalk
Expand All @@ -29,7 +35,7 @@ module.exports = () => {
},
{
content:
'Publishes the current contents of "build/node_modules" to NPM.',
'Publishes the current contents of "build/node_modules" to NPM.}',
},
{
header: 'Options',
Expand All @@ -39,7 +45,11 @@ module.exports = () => {
header: 'Examples',
content: [
{
desc: 'Example:',
desc: 'Dry run test:',
example: '$ scripts/release/publish.js --dry --tags next',
},
{
desc: 'Publish a new stable:',
example: '$ scripts/release/publish.js --tags next latest',
},
],
Expand Down
Loading

0 comments on commit 200f17b

Please sign in to comment.