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 1 commit
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
6 changes: 3 additions & 3 deletions scripts/release/build-commands/print-post-build-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ module.exports = ({cwd, dry, path, version}) => {
1. Open {yellow.bold ${standaloneFixturePath}} in the browser.
2. It should say {italic "Hello world!"}
3. Next go to {yellow.bold ${packagingFixturesPath}} and run {bold node build-all.js}
4. Install the "serve" module ({bold npm install -g serve})
5. Go to the repo root and {bold serve -s .}
6. Open {blue.bold http://localhost:5000/fixtures/packaging}
4. Install the "pushstate-server" module ({bold npm install -g pushstate-server})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you considered using npx for one off things like this? you could merge steps 4 and 5 with
npx pushstate-server . 9000

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah maybe that's a good improvement :)

5. Go to the repo root and {bold pushstate-server -s .}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-s isn't a pushstate-server option though? also, you need a port, so this should probably be pushstate-server . 9000

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9000 is the default port.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, fair. it throws an error with -s tho.

6. Open {blue.bold http://localhost:9000/fixtures/packaging}
7. Verify every iframe shows {italic "Hello world!"}

After completing the above steps, resume the release process by running:
Expand Down
19 changes: 3 additions & 16 deletions scripts/release/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ const {exec} = require('child_process');

// Follows the steps outlined in github.com/facebook/react/issues/10620
const run = async () => {
const chalk = require('chalk');
const logUpdate = require('log-update');
const {getPublicPackages, getPackages} = require('./utils');
const {getPublicPackages, getPackages, handleError} = require('./utils');

const addGitTag = require('./build-commands/add-git-tag');
const buildArtifacts = require('./build-commands/build-artifacts');
const checkCircleCiStatus = require('./build-commands/check-circle-ci-status');
const checkEnvironmentVariables = require('./build-commands/check-environment-variables');
const checkEnvironmentVariables = require('./shared-commands/check-environment-variables');
const checkNpmPermissions = require('./build-commands/check-npm-permissions');
const checkPackageDependencies = require('./build-commands/check-package-dependencies');
const checkUncommittedChanges = require('./build-commands/check-uncommitted-changes');
Expand Down Expand Up @@ -55,18 +53,7 @@ const run = async () => {
await addGitTag(params);
await printPostBuildSummary(params);
} catch (error) {
logUpdate.clear();

const message = error.message.trim().replace(/\n +/g, '\n');
const stack = error.stack.replace(error.message, '');

console.log(
`${chalk.bgRed.white(' ERROR ')} ${chalk.red(message)}\n\n${chalk.gray(
stack
)}`
);

process.exit(1);
handleError(error);
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env node

'use strict';

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

const run = async ({build, cwd}) => {
// https://circleci.com/docs/2.0/artifacts/#downloading-all-artifacts-for-a-build-on-circleci
const metadataURL = `https://circleci.com/api/v1.1/project/github/facebook/react/${build}/artifacts?circle-token=${
process.env.CIRCLE_CI_API_TOKEN
}`;
const metadata = await http.get(metadataURL, true);
const nodeModulesURL = metadata.find(
entry => entry.path === 'home/circleci/project/node_modules.tgz'
).url;

// Download and extract artifact
await exec(`rm -rf ${cwd}/build/node_modules*`);
await exec(`curl ${nodeModulesURL} --output ${cwd}/build/node_modules.tgz`);
await exec(`mkdir ${cwd}/build/node_modules`);
await exec(
`tar zxvf ${cwd}/build/node_modules.tgz -C ${cwd}/build/node_modules/`
);

// Unpack packages and parepare to publish
const compressedPackages = readdirSync('build/node_modules/');
for (let i = 0; i < compressedPackages.length; i++) {
await exec(
`tar zxvf ${cwd}/build/node_modules/${
compressedPackages[i]
} -C ${cwd}/build/node_modules/`
);
const packageJSON = readJsonSync(
`${cwd}/build/node_modules/package/package.json`
);
await exec(
`mv ${cwd}/build/node_modules/package ${cwd}/build/node_modules/${
packageJSON.name
}`
);
}

// Cleanup
await exec(`rm ${cwd}/build/node_modules.tgz`);
await exec(`rm ${cwd}/build/node_modules/*.tgz`);
};

module.exports = async ({build, cwd}) => {
return logPromise(
run({build, cwd}),
`Downloading artifacts from Circle CI for build ${chalk.yellow.bold(
`${build}`
)}`
);
};
65 changes: 65 additions & 0 deletions scripts/release/prepare-canary-commands/parse-params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env node

'use strict';

const chalk = require('chalk');
const commandLineArgs = require('command-line-args');
const commandLineUsage = require('command-line-usage');
const figlet = require('figlet');

const paramDefinitions = [
{
name: 'build',
type: Number,
description:
'Circle CI build identifier (e.g. https://circleci.com/gh/facebook/react/<build>)',
defaultValue: false,
},
{
name: 'path',
type: String,
alias: 'p',
description:
'Location of React repository to release; defaults to [bold]{cwd}',
defaultValue: '.',
},
];

module.exports = () => {
const params = commandLineArgs(paramDefinitions);

if (!params.build) {
const usage = commandLineUsage([
{
content: chalk
.hex('#61dafb')
.bold(figlet.textSync('react', {font: 'Graffiti'})),
raw: true,
},
{
content:
'Prepare a Circle CI build to be published to NPM as a canary.',
},
{
header: 'Options',
optionList: paramDefinitions,
},
{
header: 'Examples',
content: [
{
desc: 'Example:',
example: '$ ./prepare-canary.js [bold]{--build=}[underline]{12639}',
},
],
},
]);
console.log(usage);
process.exit(1);
}

return {
...params,
cwd: params.path, // For script convenience
};
};
40 changes: 40 additions & 0 deletions scripts/release/prepare-canary-commands/print-summary.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 {join, relative} = require('path');

module.exports = ({cwd, build, path}) => {
const publishPath = relative(
process.env.PWD,
join(__dirname, '../publish.js')
);
const command = `${publishPath}` + (path ? ` -p ${path}` : '');

const packagingFixturesPath = join(cwd, 'fixtures/packaging');
const standaloneFixturePath = join(
cwd,
'fixtures/packaging/babel-standalone/dev.html'
);

console.log(
chalk`
{green.bold A potential canary has been prepared!}
Next there are a couple of manual steps:

{bold.underline Smoke test the packages}

1. Open {yellow.bold ${standaloneFixturePath}} in the browser.
2. It should say {italic "Hello world!"}
3. Next go to {yellow.bold ${packagingFixturesPath}} and run {bold node build-all.js}
4. Install the "pushstate-server" module ({bold npm install -g pushstate-server})
5. Go to the repo root and {bold pushstate-server -s .}
6. Open {blue.bold http://localhost:9000/fixtures/packaging}
7. Verify every iframe shows {italic "Hello world!"}

After completing the above steps, you can publish this canary by running:
{yellow.bold ${command}}
`.replace(/\n +/g, '\n')
);
};
24 changes: 24 additions & 0 deletions scripts/release/prepare-canary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env node

'use strict';

const {handleError} = require('./utils');

const checkEnvironmentVariables = require('./shared-commands/check-environment-variables');
const downloadBuildArtifacts = require('./prepare-canary-commands/download-build-artifacts');
const parseParams = require('./prepare-canary-commands/parse-params');
const printSummary = require('./prepare-canary-commands/print-summary');

const run = async () => {
try {
const params = parseParams();

await checkEnvironmentVariables(params);
await downloadBuildArtifacts(params);
await printSummary(params);
} catch (error) {
handleError(error);
}
};

run();
17 changes: 2 additions & 15 deletions scripts/release/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

'use strict';

const chalk = require('chalk');
const logUpdate = require('log-update');
const {getPublicPackages} = require('./utils');
const {getPublicPackages, handleError} = require('./utils');

const checkBuildStatus = require('./publish-commands/check-build-status');
const commitChangelog = require('./publish-commands/commit-changelog');
Expand All @@ -27,18 +25,7 @@ const run = async () => {
await publishToNpm(params);
await printPostPublishSummary(params);
} catch (error) {
logUpdate.clear();

const message = error.message.trim().replace(/\n +/g, '\n');
const stack = error.stack.replace(error.message, '');

console.log(
`${chalk.bgRed.white(' ERROR ')} ${chalk.red(message)}\n\n${chalk.gray(
stack
)}`
);

process.exit(1);
handleError(error);
}
};

Expand Down
16 changes: 16 additions & 0 deletions scripts/release/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ const getUnexecutedCommands = () => {
}
};

const handleError = error => {
logUpdate.clear();

const message = error.message.trim().replace(/\n +/g, '\n');
const stack = error.stack.replace(error.message, '');

console.log(
`${chalk.bgRed.white(' ERROR ')} ${chalk.red(message)}\n\n${chalk.gray(
stack
)}`
);

process.exit(1);
};

const logPromise = async (promise, text, isLongRunningTask = false) => {
const {frames, interval} = dots;

Expand Down Expand Up @@ -119,6 +134,7 @@ module.exports = {
getPackages,
getPublicPackages,
getUnexecutedCommands,
handleError,
logPromise,
runYarnTask,
};