Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
[ghstack-poisoned]
  • Loading branch information
poteto committed Jun 24, 2024
1 parent 25a6144 commit 3b3a5c8
Showing 1 changed file with 54 additions and 50 deletions.
104 changes: 54 additions & 50 deletions scripts/rollup/build-all-release-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,61 +80,63 @@ const argv = yargs.wrap(yargs.terminalWidth()).options({
},
}).argv;

if (argv.ci === 'github') {
// ./scripts/rollup/build was being used by spawning a new process and passing via ENV variables
// so let's just preserve this for now and rewrite it later to just take a function arg
process.env.RELEASE_CHANNEL = argv.releaseChannel;
buildEverything(argv.bundleType);
switch (argv.releaseChannel) {
case 'stable': {
processStable('./build');
break;
async function main() {
if (argv.ci === 'github') {
// ./scripts/rollup/build was being used by spawning a new process and passing via ENV variables
// so let's just preserve this for now and rewrite it later to just take a function arg
process.env.RELEASE_CHANNEL = argv.releaseChannel;
await buildEverything(argv.bundleType);
switch (argv.releaseChannel) {
case 'stable': {
processStable('./build');
break;
}
case 'experimental': {
processExperimental('./build');
break;
}
default:
throw new Error(`Unknown release channel ${argv.releaseChannel}`);
}
case 'experimental': {
} else if (argv.ci === 'circleci') {
// 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');
break;
}
default:
throw new Error(`Unknown release channel ${argv.releaseChannel}`);
}
} else if (argv.ci === 'circleci') {
// 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');
// 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;
crossDeviceRenameSync('./build', stableDir);
processStable(stableDir);
buildForChannel('experimental', '', '');
const experimentalDir = tmp.dirSync().name;
crossDeviceRenameSync('./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.
mergeDirsSync(experimentalDir + '/', stableDir + '/');

// Now restore the combined directory back to its original name
crossDeviceRenameSync(stableDir, './build');
}
} 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;
crossDeviceRenameSync('./build', stableDir);
processStable(stableDir);
buildForChannel('experimental', '', '');
const experimentalDir = tmp.dirSync().name;
crossDeviceRenameSync('./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.
mergeDirsSync(experimentalDir + '/', stableDir + '/');

// Now restore the combined directory back to its original name
crossDeviceRenameSync(stableDir, './build');
}

function buildForChannel(channel, nodeTotal, nodeIndex) {
Expand Down Expand Up @@ -501,3 +503,5 @@ function mergeDirsSync(source, destination) {
}
}
}

main();

0 comments on commit 3b3a5c8

Please sign in to comment.