-
Notifications
You must be signed in to change notification settings - Fork 47.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Download error-codes from Circle CI after publishing
- Loading branch information
Brian Vaughn
committed
Nov 19, 2018
1 parent
e624d14
commit 3585929
Showing
4 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
scripts/release/publish-commands/download-error-codes-from-ci.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const http = require('request-promise-json'); | ||
const {exec} = require('child-process-promise'); | ||
const {readJsonSync} = require('fs-extra'); | ||
const {logPromise} = require('../utils'); | ||
const theme = require('../theme'); | ||
|
||
const run = async ({cwd, tags}) => { | ||
if (!tags.includes('latest')) { | ||
// Don't update error-codes for alphas. | ||
return; | ||
} | ||
|
||
// All packages are built from a single source revision, | ||
// so it is safe to read build info from any one of them. | ||
const {buildNumber, environment} = readJsonSync( | ||
`${cwd}/build/node_modules/react/build-info.json` | ||
); | ||
|
||
// If this release was created on Circle CI, grab the updated error codes from there. | ||
// Else the user will have to manually regenerate them. | ||
if (environment === 'ci') { | ||
// https://circleci.com/docs/2.0/artifacts/#downloading-all-artifacts-for-a-build-on-circleci | ||
// eslint-disable-next-line max-len | ||
const metadataURL = `https://circleci.com/api/v1.1/project/github/facebook/react/${buildNumber}/artifacts?circle-token=${ | ||
process.env.CIRCLE_CI_API_TOKEN | ||
}`; | ||
const metadata = await http.get(metadataURL, true); | ||
|
||
// Each container stores an "error-codes" artifact, unfortunately. | ||
// We want to use the one that also ran `yarn build` since it may have modifications. | ||
const {node_index} = metadata.find( | ||
entry => entry.path === 'home/circleci/project/node_modules.tgz' | ||
); | ||
const {url} = metadata.find( | ||
entry => | ||
entry.node_index === node_index && | ||
entry.path === 'home/circleci/project/scripts/error-codes/codes.json' | ||
); | ||
|
||
// Download and stage changers | ||
await exec(`curl ${url} --output ${cwd}/scripts/error-codes/codes.json`); | ||
} | ||
}; | ||
|
||
module.exports = async params => { | ||
return logPromise(run(params), theme`Retrieving error codes`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters