-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Download Circle CI artifact and prepare canary release #14225
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
60 changes: 60 additions & 0 deletions
60
scripts/release/prepare-canary-commands/download-build-artifacts.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,60 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const chalk = require('chalk'); | ||
const http = require('request-promise-json'); | ||
const {exec} = require('child-process-promise'); | ||
const {readdirSync} = require('fs'); | ||
const {readJsonSync} = require('fs-extra'); | ||
const {logPromise} = require('../utils'); | ||
|
||
const run = async ({build, cwd}) => { | ||
// https://circleci.com/docs/2.0/artifacts/#downloading-all-artifacts-for-a-build-on-circleci | ||
const metadataURL = `https://circleci.com/api/v1.1/project/github/facebook/react/${build}/artifacts?circle-token=${ | ||
process.env.CIRCLE_CI_API_TOKEN | ||
}`; | ||
const metadata = await http.get(metadataURL, true); | ||
const nodeModulesURL = metadata.find( | ||
entry => entry.path === 'home/circleci/project/node_modules.tgz' | ||
).url; | ||
|
||
// Download and extract artifact | ||
await exec(`rm -rf ${cwd}/build/node_modules*`); | ||
await exec(`curl ${nodeModulesURL} --output ${cwd}/build/node_modules.tgz`); | ||
await exec(`mkdir ${cwd}/build/node_modules`); | ||
await exec( | ||
`tar zxvf ${cwd}/build/node_modules.tgz -C ${cwd}/build/node_modules/` | ||
); | ||
|
||
// Unpack packages and parepare to publish | ||
const compressedPackages = readdirSync('build/node_modules/'); | ||
for (let i = 0; i < compressedPackages.length; i++) { | ||
await exec( | ||
`tar zxvf ${cwd}/build/node_modules/${ | ||
compressedPackages[i] | ||
} -C ${cwd}/build/node_modules/` | ||
); | ||
const packageJSON = readJsonSync( | ||
`${cwd}/build/node_modules/package/package.json` | ||
); | ||
await exec( | ||
`mv ${cwd}/build/node_modules/package ${cwd}/build/node_modules/${ | ||
packageJSON.name | ||
}` | ||
); | ||
} | ||
|
||
// Cleanup | ||
await exec(`rm ${cwd}/build/node_modules.tgz`); | ||
await exec(`rm ${cwd}/build/node_modules/*.tgz`); | ||
}; | ||
|
||
module.exports = async ({build, cwd}) => { | ||
return logPromise( | ||
run({build, cwd}), | ||
`Downloading artifacts from Circle CI for build ${chalk.yellow.bold( | ||
`${build}` | ||
)}` | ||
); | ||
}; |
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,65 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const chalk = require('chalk'); | ||
const commandLineArgs = require('command-line-args'); | ||
const commandLineUsage = require('command-line-usage'); | ||
const figlet = require('figlet'); | ||
|
||
const paramDefinitions = [ | ||
{ | ||
name: 'build', | ||
type: Number, | ||
description: | ||
'Circle CI build identifier (e.g. https://circleci.com/gh/facebook/react/<build>)', | ||
defaultValue: false, | ||
}, | ||
{ | ||
name: 'path', | ||
type: String, | ||
alias: 'p', | ||
description: | ||
'Location of React repository to release; defaults to [bold]{cwd}', | ||
defaultValue: '.', | ||
}, | ||
]; | ||
|
||
module.exports = () => { | ||
const params = commandLineArgs(paramDefinitions); | ||
|
||
if (!params.build) { | ||
const usage = commandLineUsage([ | ||
{ | ||
content: chalk | ||
.hex('#61dafb') | ||
.bold(figlet.textSync('react', {font: 'Graffiti'})), | ||
raw: true, | ||
}, | ||
{ | ||
content: | ||
'Prepare a Circle CI build to be published to NPM as a canary.', | ||
}, | ||
{ | ||
header: 'Options', | ||
optionList: paramDefinitions, | ||
}, | ||
{ | ||
header: 'Examples', | ||
content: [ | ||
{ | ||
desc: 'Example:', | ||
example: '$ ./prepare-canary.js [bold]{--build=}[underline]{12639}', | ||
}, | ||
], | ||
}, | ||
]); | ||
console.log(usage); | ||
process.exit(1); | ||
} | ||
|
||
return { | ||
...params, | ||
cwd: params.path, // For script convenience | ||
}; | ||
}; |
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,40 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const chalk = require('chalk'); | ||
const {join, relative} = require('path'); | ||
|
||
module.exports = ({cwd, build, path}) => { | ||
const publishPath = relative( | ||
process.env.PWD, | ||
join(__dirname, '../publish.js') | ||
); | ||
const command = `${publishPath}` + (path ? ` -p ${path}` : ''); | ||
|
||
const packagingFixturesPath = join(cwd, 'fixtures/packaging'); | ||
const standaloneFixturePath = join( | ||
cwd, | ||
'fixtures/packaging/babel-standalone/dev.html' | ||
); | ||
|
||
console.log( | ||
chalk` | ||
{green.bold A potential canary has been prepared!} | ||
Next there are a couple of manual steps: | ||
|
||
{bold.underline Smoke test the packages} | ||
|
||
1. Open {yellow.bold ${standaloneFixturePath}} in the browser. | ||
2. It should say {italic "Hello world!"} | ||
3. Next go to {yellow.bold ${packagingFixturesPath}} and run {bold node build-all.js} | ||
4. Install the "pushstate-server" module ({bold npm install -g pushstate-server}) | ||
5. Go to the repo root and {bold pushstate-server -s .} | ||
6. Open {blue.bold http://localhost:9000/fixtures/packaging} | ||
7. Verify every iframe shows {italic "Hello world!"} | ||
|
||
After completing the above steps, you can publish this canary by running: | ||
{yellow.bold ${command}} | ||
`.replace(/\n +/g, '\n') | ||
); | ||
}; |
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,24 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const {handleError} = require('./utils'); | ||
|
||
const checkEnvironmentVariables = require('./shared-commands/check-environment-variables'); | ||
const downloadBuildArtifacts = require('./prepare-canary-commands/download-build-artifacts'); | ||
const parseParams = require('./prepare-canary-commands/parse-params'); | ||
const printSummary = require('./prepare-canary-commands/print-summary'); | ||
|
||
const run = async () => { | ||
try { | ||
const params = parseParams(); | ||
|
||
await checkEnvironmentVariables(params); | ||
await downloadBuildArtifacts(params); | ||
await printSummary(params); | ||
} catch (error) { | ||
handleError(error); | ||
} | ||
}; | ||
|
||
run(); |
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
File renamed without changes.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushstate-server
works better