Skip to content

Commit 45691c9

Browse files
committed
Add --commit param to release scripts
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.
1 parent bb1b795 commit 45691c9

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

scripts/release/download-experimental-build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const run = async () => {
1919
try {
2020
addDefaultParamValue('-r', '--releaseChannel', 'experimental');
2121

22-
const params = parseParams();
22+
const params = await parseParams();
2323
params.cwd = join(__dirname, '..', '..');
2424
params.packages = await getPublicPackages(true);
2525

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
const fetch = require('node-fetch');
4+
5+
async function getBuildIdForCommit(sha) {
6+
let ciBuildId = null;
7+
const statusesResponse = await fetch(
8+
`https://api.github.com/repos/facebook/react/commits/${sha}/status`
9+
);
10+
11+
if (!statusesResponse.ok) {
12+
throw Error('Could not find commit for: ' + sha);
13+
}
14+
15+
const {statuses, state} = await statusesResponse.json();
16+
if (state === 'failure') {
17+
throw new Error(`Base commit is broken: ${sha}`);
18+
}
19+
for (let i = 0; i < statuses.length; i++) {
20+
const status = statuses[i];
21+
if (status.context === `ci/circleci: process_artifacts_combined`) {
22+
if (status.state === 'success') {
23+
ciBuildId = /\/facebook\/react\/([0-9]+)/.exec(status.target_url)[1];
24+
break;
25+
}
26+
if (status.state === 'pending') {
27+
throw new Error(`Build job for base commit is still pending: ${sha}`);
28+
}
29+
}
30+
}
31+
return ciBuildId;
32+
}
33+
34+
module.exports = getBuildIdForCommit;

scripts/release/prepare-release-from-ci.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const testTracingFixture = require('./shared-commands/test-tracing-fixture');
1515

1616
const run = async () => {
1717
try {
18-
const params = parseParams();
18+
const params = await parseParams();
1919
params.cwd = join(__dirname, '..', '..');
2020

2121
if (!params.build) {

scripts/release/shared-commands/parse-params.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
'use strict';
44

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

78
const paramDefinitions = [
89
{
910
name: 'build',
1011
type: Number,
1112
description:
1213
'Circle CI build identifier (e.g. https://circleci.com/gh/facebook/react/<build>)',
14+
defaultValue: null,
15+
},
16+
{
17+
name: 'commit',
18+
type: String,
19+
description:
20+
'GitHub commit SHA. When provided, automatically finds corresponding CI build.',
21+
defaultValue: null,
1322
},
1423
{
1524
name: 'skipTests',
@@ -25,9 +34,29 @@ const paramDefinitions = [
2534
},
2635
];
2736

28-
module.exports = () => {
37+
module.exports = async () => {
2938
const params = commandLineArgs(paramDefinitions);
3039

40+
if (params.build !== null) {
41+
if (params.commit !== null) {
42+
console.error(
43+
'`build` and `commmit` params are mutually exclusive. Choose one or the other.`'
44+
);
45+
process.exit(1);
46+
}
47+
} else {
48+
if (params.commit === null) {
49+
console.error('Must provide either `build` or `commit`.');
50+
process.exit(1);
51+
}
52+
try {
53+
params.build = await getBuildIdForCommit(params.commit);
54+
} catch (error) {
55+
console.error(error.message);
56+
process.exit(1);
57+
}
58+
}
59+
3160
const channel = params.releaseChannel;
3261
if (channel !== 'experimental' && channel !== 'stable') {
3362
console.error(

0 commit comments

Comments
 (0)