Release script auto-determine the latest Canary build if none specified (#14339)
* Release script auto-determine the latest Canary build if none specified
Brian Vaughn committed
Nov 28, 2018 at 13:56 UTC
88ada98198b22d2b8cd056cfba5ffb113c6a50d3
3 files changed
+29
-25
scripts/release/prepare-canary-commands/get-latest-master-build-number.js
new
+24
@@ -0,0 +1,24 @@
1
+#!/usr/bin/env node
2
+
3
+'use strict';
4
+
5
+const http = require('request-promise-json');
6
+const {logPromise} = require('../utils');
7
+
8
+const run = async () => {
9
+ // https://circleci.com/docs/api/#recent-builds-for-a-project-branch
10
+ const metadataURL = `https://circleci.com/api/v1.1/project/github/facebook/react/tree/master`;
11
+ const metadata = await http.get(metadataURL, true);
12
+ const build = metadata.find(
13
+ entry => entry.branch === 'master' && entry.status === 'success'
14
+ ).build_num;
15
+
16
+ return build;
17
+};
18
+
19
+module.exports = async params => {
20
+ return logPromise(
21
+ run(params),
22
+ 'Determining latest Circle CI for the master branch'
23
+ );
24
+};
scripts/release/prepare-canary-commands/parse-params.js
-25
@@ -3,7 +3,6 @@
3
'use strict';
4
5
const commandLineArgs = require('command-line-args');
6
-const commandLineUsage = require('command-line-usage');
6
7
const paramDefinitions = [
8
{
@@ -17,29 +16,5 @@ const paramDefinitions = [
16
module.exports = () => {
17
const params = commandLineArgs(paramDefinitions);
18
20
- if (!params.build) {
21
- const usage = commandLineUsage([
22
- {
23
- content:
24
- 'Prepare a Circle CI build to be published to NPM as a canary.',
25
- },
26
- {
27
- header: 'Options',
28
- optionList: paramDefinitions,
29
- },
30
- {
31
- header: 'Examples',
32
- content: [
33
- {
34
- desc: 'Example:',
35
- example: '$ ./prepare-canary.js [bold]{--build=}[underline]{12639}',
36
- },
37
- ],
38
- },
39
- ]);
40
- console.log(usage);
41
- process.exit(1);
42
- }
43
-
19
return params;
20
};
scripts/release/prepare-canary.js
+5
@@ -7,6 +7,7 @@ const {getPublicPackages, handleError} = require('./utils');
7
8
const checkEnvironmentVariables = require('./prepare-canary-commands/check-environment-variables');
9
const downloadBuildArtifacts = require('./prepare-canary-commands/download-build-artifacts');
10
+const getLatestMasterBuildNumber = require('./prepare-canary-commands/get-latest-master-build-number');
11
const parseParams = require('./prepare-canary-commands/parse-params');
12
const printPrereleaseSummary = require('./shared-commands/print-prerelease-summary');
13
@@ -16,6 +17,10 @@ const run = async () => {
17
params.cwd = join(__dirname, '..', '..');
18
params.packages = await getPublicPackages();
19
20
+ if (!params.build) {
21
+ params.build = await getLatestMasterBuildNumber();
22
+ }
23
+
24
await checkEnvironmentVariables(params);
25
await downloadBuildArtifacts(params);
26
await printPrereleaseSummary(params);