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
Migrate prepare-release-from-ci to new workflow #20581
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,65 +3,56 @@ | |
'use strict'; | ||
|
||
const {exec} = require('child-process-promise'); | ||
const {existsSync, readdirSync} = require('fs'); | ||
const {readJsonSync} = require('fs-extra'); | ||
const {existsSync} = require('fs'); | ||
const {join} = require('path'); | ||
const {getArtifactsList, logPromise} = require('../utils'); | ||
const theme = require('../theme'); | ||
|
||
const run = async ({build, cwd}) => { | ||
const run = async ({build, cwd, releaseChannel}) => { | ||
const artifacts = await getArtifactsList(build); | ||
const nodeModulesArtifact = artifacts.find(entry => | ||
entry.path.endsWith('node_modules.tgz') | ||
const buildArtifacts = artifacts.find(entry => | ||
entry.path.endsWith('build2.tgz') | ||
); | ||
|
||
if (!nodeModulesArtifact) { | ||
if (!buildArtifacts) { | ||
console.log( | ||
theme`{error The specified build (${build}) does not contain any build artifacts.}` | ||
); | ||
process.exit(1); | ||
} | ||
|
||
const nodeModulesURL = nodeModulesArtifact.url; | ||
// Download and extract artifact | ||
await exec(`rm -rf ./build2`, {cwd}); | ||
await exec( | ||
`curl -L $(fwdproxy-config curl) ${buildArtifacts.url} | tar -xvz`, | ||
{ | ||
cwd, | ||
} | ||
); | ||
|
||
// Copy to staging directory | ||
// TODO: Consider staging the release in a different directory from the CI | ||
// build artifacts: `./build/node_modules` -> `./staged-releases` | ||
if (!existsSync(join(cwd, 'build'))) { | ||
await exec(`mkdir ./build`, {cwd}); | ||
} else { | ||
await exec(`rm -rf ./build/node_modules`, {cwd}); | ||
} | ||
|
||
// Download and extract artifact | ||
await exec(`rm -rf ./build/node_modules*`, {cwd}); | ||
await exec(`curl -L ${nodeModulesURL} --output ./build/node_modules.tgz`, { | ||
cwd, | ||
}); | ||
await exec(`mkdir ./build/node_modules`, {cwd}); | ||
await exec(`tar zxvf ./build/node_modules.tgz -C ./build/node_modules/`, { | ||
cwd, | ||
}); | ||
|
||
// Unpack packages and prepare to publish | ||
const compressedPackages = readdirSync(join(cwd, 'build/node_modules/')); | ||
for (let i = 0; i < compressedPackages.length; i++) { | ||
await exec( | ||
`tar zxvf ./build/node_modules/${compressedPackages[i]} -C ./build/node_modules/`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When this was originally added, we didn't store the entire build directory as a CI artifact. Just the npm packages. The reason we stored each module as an individual tarball was because we ran |
||
{cwd} | ||
); | ||
const packageJSON = readJsonSync( | ||
join(cwd, `/build/node_modules/package/package.json`) | ||
); | ||
await exec( | ||
`mv ./build/node_modules/package ./build/node_modules/${packageJSON.name}`, | ||
{cwd} | ||
); | ||
let sourceDir; | ||
if (releaseChannel === 'stable') { | ||
sourceDir = 'oss-stable'; | ||
} else if (releaseChannel === 'experimental') { | ||
sourceDir = 'oss-experimental'; | ||
} else { | ||
console.error('Internal error: Invalid release channel: ' + releaseChannel); | ||
process.exit(releaseChannel); | ||
} | ||
|
||
// Cleanup | ||
await exec(`rm ./build/node_modules.tgz`, {cwd}); | ||
await exec(`rm ./build/node_modules/*.tgz`, {cwd}); | ||
await exec(`cp -r ./build2/${sourceDir} ./build/node_modules`, {cwd}); | ||
}; | ||
|
||
module.exports = async ({build, cwd}) => { | ||
module.exports = async ({build, cwd, releaseChannel}) => { | ||
return logPromise( | ||
run({build, cwd}), | ||
run({build, cwd, releaseChannel}), | ||
theme`Downloading artifacts from Circle CI for build {build ${build}}` | ||
); | ||
}; |
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.
Hey @acdlite I'm trying to execute this script on a Windows machine and it looks like it assumes Unix heavily. I'm trying to rewrite this in a more xplat fashion, but I can't figure out what
fwdproxy-config curl
is or returns. If you could point me to the package that enables this command or something, that'd be great. Thanks!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 friendly ping