Skip to content

Commit

Permalink
Add --commit param to release scripts (#20703)
Browse files Browse the repository at this point in the history
Alternative to `--build`. Uses same logic as sizebot and www
sync script.

Immediate motivation is I want sizebot to use the
`download-experimental-build` command in CI. Will do that next.
  • Loading branch information
acdlite authored Feb 1, 2021
1 parent bb1b795 commit f8b6969
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scripts/release/download-experimental-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const run = async () => {
try {
addDefaultParamValue('-r', '--releaseChannel', 'experimental');

const params = parseParams();
const params = await parseParams();
params.cwd = join(__dirname, '..', '..');
params.packages = await getPublicPackages(true);

Expand Down
34 changes: 34 additions & 0 deletions scripts/release/get-build-id-for-commit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const fetch = require('node-fetch');

async function getBuildIdForCommit(sha) {
let ciBuildId = null;
const statusesResponse = await fetch(
`https://api.github.com/repos/facebook/react/commits/${sha}/status`
);

if (!statusesResponse.ok) {
throw Error('Could not find commit for: ' + sha);
}

const {statuses, state} = await statusesResponse.json();
if (state === 'failure') {
throw new Error(`Base commit is broken: ${sha}`);
}
for (let i = 0; i < statuses.length; i++) {
const status = statuses[i];
if (status.context === `ci/circleci: process_artifacts_combined`) {
if (status.state === 'success') {
ciBuildId = /\/facebook\/react\/([0-9]+)/.exec(status.target_url)[1];
break;
}
if (status.state === 'pending') {
throw new Error(`Build job for base commit is still pending: ${sha}`);
}
}
}
return ciBuildId;
}

module.exports = getBuildIdForCommit;
2 changes: 1 addition & 1 deletion scripts/release/prepare-release-from-ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const testTracingFixture = require('./shared-commands/test-tracing-fixture');

const run = async () => {
try {
const params = parseParams();
const params = await parseParams();
params.cwd = join(__dirname, '..', '..');

if (!params.build) {
Expand Down
31 changes: 30 additions & 1 deletion scripts/release/shared-commands/parse-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
'use strict';

const commandLineArgs = require('command-line-args');
const getBuildIdForCommit = require('../get-build-id-for-commit');

const paramDefinitions = [
{
name: 'build',
type: Number,
description:
'Circle CI build identifier (e.g. https://circleci.com/gh/facebook/react/<build>)',
defaultValue: null,
},
{
name: 'commit',
type: String,
description:
'GitHub commit SHA. When provided, automatically finds corresponding CI build.',
defaultValue: null,
},
{
name: 'skipTests',
Expand All @@ -25,9 +34,29 @@ const paramDefinitions = [
},
];

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

if (params.build !== null) {
if (params.commit !== null) {
console.error(
'`build` and `commmit` params are mutually exclusive. Choose one or the other.`'
);
process.exit(1);
}
} else {
if (params.commit === null) {
console.error('Must provide either `build` or `commit`.');
process.exit(1);
}
try {
params.build = await getBuildIdForCommit(params.commit);
} catch (error) {
console.error(error.message);
process.exit(1);
}
}

const channel = params.releaseChannel;
if (channel !== 'experimental' && channel !== 'stable') {
console.error(
Expand Down

0 comments on commit f8b6969

Please sign in to comment.