Skip to content

Add --commit param to release scripts #20703

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
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;
Copy link
Member

Choose a reason for hiding this comment

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

Should we throw if we get here and this is still nulll?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in next PR

}

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