Add `--commit` param to release scripts (#20703)
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.
Andrew Clark committed
Feb 1, 2021 at 10:27 UTC
f8b6969da65457cd18b434616cb01ac1c7b0afcc
4 files changed
+66
-3
scripts/release/download-experimental-build.js
+1
-1
@@ -19,7 +19,7 @@ const run = async () => {
19
try {
20
addDefaultParamValue('-r', '--releaseChannel', 'experimental');
21
22
- const params = parseParams();
22
+ const params = await parseParams();
23
params.cwd = join(__dirname, '..', '..');
24
params.packages = await getPublicPackages(true);
25
scripts/release/get-build-id-for-commit.js
new
+34
@@ -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
+1
-1
@@ -15,7 +15,7 @@ const testTracingFixture = require('./shared-commands/test-tracing-fixture');
15
16
const run = async () => {
17
try {
18
- const params = parseParams();
18
+ const params = await parseParams();
19
params.cwd = join(__dirname, '..', '..');
20
21
if (!params.build) {
scripts/release/shared-commands/parse-params.js
+30
-1
@@ -3,6 +3,7 @@
3
'use strict';
4
5
const commandLineArgs = require('command-line-args');
6
+const getBuildIdForCommit = require('../get-build-id-for-commit');
7
8
const paramDefinitions = [
9
{
@@ -10,6 +11,14 @@ const paramDefinitions = [
11
type: Number,
12
description:
13
'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,
22
},
23
{
24
name: 'skipTests',
@@ -25,9 +34,29 @@ const paramDefinitions = [
34
},
35
];
36
28
-module.exports = () => {
37
+module.exports = async () => {
38
const params = commandLineArgs(paramDefinitions);
39
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
+
60
const channel = params.releaseChannel;
61
if (channel !== 'experimental' && channel !== 'stable') {
62
console.error(