-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Add CI workflow that builds both release channels simultaneously #20573
Merged
Merged
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
'use strict'; | ||
|
||
/* eslint-disable no-for-of-loops/no-for-of-loops */ | ||
|
||
const fs = require('fs'); | ||
const {spawnSync} = require('child_process'); | ||
const tmp = require('tmp'); | ||
|
||
// Runs the build script for both stable and experimental release channels, | ||
// by configuring an environment variable. | ||
|
||
if (process.env.CIRCLE_NODE_TOTAL) { | ||
// In CI, we use multiple concurrent processes. Allocate half the processes to | ||
// build the stable channel, and the other half for experimental. Override | ||
// the environment variables to "trick" the underlying build script. | ||
const total = parseInt(process.env.CIRCLE_NODE_TOTAL, 10); | ||
const halfTotal = Math.floor(total / 2); | ||
const index = parseInt(process.env.CIRCLE_NODE_INDEX, 10); | ||
if (index < halfTotal) { | ||
const nodeTotal = halfTotal; | ||
const nodeIndex = index; | ||
buildForChannel('stable', nodeTotal, nodeIndex); | ||
processStable('./build'); | ||
} else { | ||
const nodeTotal = total - halfTotal; | ||
const nodeIndex = index - halfTotal; | ||
buildForChannel('experimental', nodeTotal, nodeIndex); | ||
processExperimental('./build'); | ||
} | ||
|
||
// TODO: Currently storing artifacts as `./build2` so that it doesn't conflict | ||
// with old build job. Remove once we migrate rest of build/test pipeline. | ||
fs.renameSync('./build', './build2'); | ||
} else { | ||
// Running locally, no concurrency. Move each channel's build artifacts into | ||
// a temporary directory so that they don't conflict. | ||
buildForChannel('stable', '', ''); | ||
const stableDir = tmp.dirSync().name; | ||
fs.renameSync('./build', stableDir); | ||
processStable(stableDir); | ||
|
||
buildForChannel('experimental', '', ''); | ||
const experimentalDir = tmp.dirSync().name; | ||
fs.renameSync('./build', experimentalDir); | ||
processExperimental(experimentalDir); | ||
|
||
// Then merge the experimental folder into the stable one. processExperimental | ||
// will have already removed conflicting files. | ||
// | ||
// In CI, merging is handled automatically by CircleCI's workspace feature. | ||
spawnSync('rsync', ['-ar', experimentalDir + '/', stableDir + '/']); | ||
|
||
// Now restore the combined directory back to its original name | ||
// TODO: Currently storing artifacts as `./build2` so that it doesn't conflict | ||
// with old build job. Remove once we migrate rest of build/test pipeline. | ||
fs.renameSync(stableDir, './build2'); | ||
} | ||
|
||
function buildForChannel(channel, nodeTotal, nodeIndex) { | ||
spawnSync('node', ['./scripts/rollup/build.js', ...process.argv.slice(2)], { | ||
stdio: ['pipe', process.stdout, process.stderr], | ||
env: { | ||
...process.env, | ||
RELEASE_CHANNEL: channel, | ||
CIRCLE_NODE_TOTAL: nodeTotal, | ||
CIRCLE_NODE_INDEX: nodeIndex, | ||
}, | ||
}); | ||
} | ||
|
||
function processStable(buildDir) { | ||
if (fs.existsSync(buildDir + '/node_modules')) { | ||
fs.renameSync(buildDir + '/node_modules', buildDir + '/oss-stable'); | ||
} | ||
|
||
if (fs.existsSync(buildDir + '/facebook-www')) { | ||
for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) { | ||
const filePath = buildDir + '/facebook-www/' + fileName; | ||
const stats = fs.statSync(filePath); | ||
if (!stats.isDirectory()) { | ||
fs.renameSync(filePath, filePath.replace('.js', '.classic.js')); | ||
} | ||
} | ||
} | ||
|
||
if (fs.existsSync(buildDir + '/sizes')) { | ||
fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-stable'); | ||
} | ||
} | ||
|
||
function processExperimental(buildDir) { | ||
if (fs.existsSync(buildDir + '/node_modules')) { | ||
fs.renameSync(buildDir + '/node_modules', buildDir + '/oss-experimental'); | ||
} | ||
|
||
if (fs.existsSync(buildDir + '/facebook-www')) { | ||
for (const fileName of fs.readdirSync(buildDir + '/facebook-www')) { | ||
const filePath = buildDir + '/facebook-www/' + fileName; | ||
const stats = fs.statSync(filePath); | ||
if (!stats.isDirectory()) { | ||
fs.renameSync(filePath, filePath.replace('.js', '.modern.js')); | ||
} | ||
} | ||
} | ||
|
||
if (fs.existsSync(buildDir + '/sizes')) { | ||
fs.renameSync(buildDir + '/sizes', buildDir + '/sizes-experimental'); | ||
} | ||
|
||
// Delete all other artifacts that weren't handled above. We assume they are | ||
// duplicates of the corresponding artifacts in the stable channel. Ideally, | ||
// the underlying build script should not have produced these files in the | ||
// first place. | ||
for (const pathName of fs.readdirSync(buildDir)) { | ||
if ( | ||
pathName !== 'oss-experimental' && | ||
pathName !== 'facebook-www' && | ||
pathName !== 'sizes-experimental' | ||
) { | ||
spawnSync('rm', ['-rm', buildDir + '/' + pathName]); | ||
} | ||
} | ||
} |
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.
@acdlite Was this supposed to be
-rf
? Neither GNU (most linux distributions) nor BSD (macOS) versions ofrm
have a-m
flag.