Skip to content

Add basic release script snapshot test #14280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b55f38e
Download Circle CI artifact and prepare canary release
Nov 13, 2018
0240640
New create-canary script
Nov 15, 2018
c197be7
New prepare-canary release script
Nov 16, 2018
71c1046
Added release script README
Nov 16, 2018
341ebb3
Shuffled around and tidied up
Nov 16, 2018
bbb9d9e
Added publish command and slightly refactored some other command mess…
Nov 17, 2018
4d53087
Always log NPM commands (even if not dry run)
Nov 17, 2018
86d3036
Fixed resume check typo/bug
Nov 17, 2018
43ac899
Added check for build-info.json in files array
Nov 18, 2018
1018c30
Replaced chalk usage with shared theme for consistancy
Nov 18, 2018
baecb2e
Updated release script README
Nov 19, 2018
26a00aa
Store error codes JSON as a build artifact also
Nov 19, 2018
b3d1a81
Store Circle CI build number in build-info.json
Nov 19, 2018
e624d14
Revert (intentional) temporary error message change
Nov 19, 2018
3585929
Download error-codes from Circle CI after publishing
Nov 19, 2018
0bbdbdd
Add release script snapshot test
Nov 20, 2018
40dde41
Update package JSONs automatically after stable release is publish
Nov 20, 2018
03abe2a
Fixed a typo
Nov 23, 2018
8747fa6
Updated fixtures/packaging tests to use build/node_modules rather tha…
Nov 23, 2018
83745a7
Added note about --dry flag for publish script to README
Nov 23, 2018
02774ef
Added {cwd} options to NPM pack-and-unpack commends
Nov 23, 2018
d30f652
Fixed another relative path issue for prepare-canary script
Nov 23, 2018
38c8aca
Nit about pushstate-server usage
Nov 23, 2018
82d170a
Merge branch 'automated-release-scripts-part-4' into automated-releas…
Nov 23, 2018
694b6a9
Merge branch 'master' into automated-release-scripts-part-5
Nov 23, 2018
fce3353
Test script also supports running from non-root directory now
Nov 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion scripts/release/prepare-stable-commands/check-out-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
'use strict';

const {exec} = require('child-process-promise');
const {existsSync} = require('fs');
const {join} = require('path');
const {logPromise} = require('../utils');
const theme = require('../theme');

const run = async ({cwd, packages, version}) => {
const run = async ({cwd, local, packages, version}) => {
if (local) {
// Sanity test
if (!existsSync(join(cwd, 'build', 'node_modules', 'react'))) {
console.error(theme.error`No local build exists.`);
process.exit(1);
}
return;
}

// Cleanup from previous builds
await exec(`rm -rf ./build/node_modules*`, {cwd});
await exec(`mkdir ./build/node_modules`, {cwd});
Expand Down
7 changes: 7 additions & 0 deletions scripts/release/prepare-stable-commands/parse-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ const commandLineArgs = require('command-line-args');
const commandLineUsage = require('command-line-usage');

const paramDefinitions = [
{
name: 'local',
type: Boolean,
description:
'Skip NPM and use the build already present in "build/node_modules".',
defaultValue: false,
},
{
name: 'version',
type: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ const run = async ({cwd, packages, version}, versionsMap) => {
}
if (beforeContents !== afterContents) {
numFilesModified++;
diff += printDiff(path, beforeContents, afterContents);
// Using a relative path for diff helps with the snapshot test
diff += printDiff(relative(cwd, path), beforeContents, afterContents);
writeFileSync(path, afterContents, {cwd});
}
});
Expand Down
97 changes: 97 additions & 0 deletions scripts/release/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env node

'use strict';

const {exec, spawn} = require('child-process-promise');
const {join} = require('path');
const {readFileSync} = require('fs');
const theme = require('./theme');
const {logPromise, printDiff} = require('./utils');

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

const CIRCLE_CI_BUILD = 12707;
const COMMIT = 'b3d1a81a9';
const VERSION = '1.2.3';

const run = async () => {
const defaultOptions = {
cwd,
env: process.env,
};

try {
// Start with a known build/revision:
// https://circleci.com/gh/facebook/react/12707
let promise = spawn(
'node',
['./scripts/release/prepare-canary.js', `--build=${CIRCLE_CI_BUILD}`],
defaultOptions
);
logPromise(
promise,
theme`Checking out canary build {version ${CIRCLE_CI_BUILD}}`
);
await promise;

// Upgrade the above build top a known React version.
// Note that using the --local flag skips NPM checkout.
// This isn't totally necessary but is useful if we want to test an unpublished canary.
promise = spawn(
'node',
[
'./scripts/release/prepare-stable.js',
`--version=0.0.0-${COMMIT}`,
'--local',
],
defaultOptions
);
promise.childProcess.stdin.setEncoding('utf-8');
promise.childProcess.stdout.setEncoding('utf-8');
promise.childProcess.stdout.on('data', data => {
if (data.includes('✓ Version for')) {
// Update all packages to a stable version
promise.childProcess.stdin.write(VERSION);
} else if (data.includes('(y/N)')) {
// Accept all of the confirmation prompts
promise.childProcess.stdin.write('y');
}
});
logPromise(promise, theme`Preparing stable release {version ${VERSION}}`);
await promise;

const beforeContents = readFileSync(
join(cwd, 'scripts/release/test.snapshot'),
'utf-8'
);
await exec('cp build/temp.diff scripts/release/test.snapshot', {cwd});
const afterContents = readFileSync(
join(cwd, 'scripts/release/test.snapshot'),
'utf-8'
);

if (beforeContents === afterContents) {
console.log(theme.header`Snapshot test passed.`);
} else {
printDiff('scripts/release/test.snapshot', beforeContents, afterContents);
console.log();
console.error(theme.error('Snapshot test failed!'));
console.log();
console.log(
'If this failure was expected, please update the contents of the snapshot file:'
);
console.log(
theme` {command git add} {path scripts/release/test.snapshot}`
);
console.log(
theme` {command git commit -m "Updating release script snapshot file."}`
);
process.exit(1);
}
} catch (error) {
console.error(theme.error(error));
process.exit(1);
}
};

run();
Loading