Skip to content

Commit

Permalink
Merge pull request #1555 from embroider-build/fix-release
Browse files Browse the repository at this point in the history
Fix release script
  • Loading branch information
mansona authored Jul 21, 2023
2 parents 65cfb16 + 3ad772d commit b8ac17b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
4 changes: 4 additions & 0 deletions test-packages/release/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ yargs(process.argv.slice(2))
description:
'Allows you to run "publish" even if there are uncommitted changes in your repo. Useful only for developing "publish" itself.',
})
.option('otp', {
type: 'string',
description: 'This is an OTP that will be passed to npm publish',
})
.option('dryRun', {
type: 'boolean',
description: 'Run through the release, but log to stdout instead of tagging/pushing/publishing',
Expand Down
37 changes: 26 additions & 11 deletions test-packages/release/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function makeTags(solution: Solution, reporter: IssueReporter, dryRun: boo

if (dryRun) {
info(`--dryRun active. Skipping \`git tag ${tag}\``);
return;
continue;
}

await execa('git', ['tag', tag], {
Expand Down Expand Up @@ -101,7 +101,10 @@ async function doesReleaseExist(octokit: Octokit, tagName: string, reporter: Iss

return response.status === 200;
} catch (err) {
console.error(err);
if (err.status === 404) {
return false;
}
console.error(err.message);
reporter.reportFailure(`Problem while checking for existing GitHub release`);
}
}
Expand Down Expand Up @@ -138,23 +141,27 @@ async function createGithubRelease(
}
}

async function doesVersionExist(pkgName: string, version: string) {
async function doesVersionExist(pkgName: string, version: string, reporter: IssueReporter) {
try {
let latest = await latestVersion(pkgName, { version });
return Boolean(latest);
} catch (err) {
console.info(err);
return false;
if (err.name === 'VersionNotFoundError') {
return false;
}

console.error(err.message);
reporter.reportFailure(`Problem while checking for existing npm release`);
}
}

async function pnpmPublish(solution: Solution, reporter: IssueReporter, dryRun: boolean): Promise<void> {
async function pnpmPublish(solution: Solution, reporter: IssueReporter, dryRun: boolean, otp?: string): Promise<void> {
for (let [pkgName, entry] of solution) {
if (!entry.impact) {
continue;
}

let preExisting = await doesVersionExist(pkgName, entry.newVersion);
let preExisting = await doesVersionExist(pkgName, entry.newVersion, reporter);

if (preExisting) {
info(`${pkgName} has already been publish @ version ${entry.newVersion}`);
Expand All @@ -163,12 +170,20 @@ async function pnpmPublish(solution: Solution, reporter: IssueReporter, dryRun:

if (dryRun) {
info(
`--dryRun active. Skipping \`pnpm publish --access=public\` for ${pkgName}, which would publish version ${entry.newVersion}`
`--dryRun active. Skipping \`pnpm publish --access=public${
otp ? ' --otp=*redacted*' : ''
}\` for ${pkgName}, which would publish version ${entry.newVersion}`
);
return;
continue;
}

try {
const args = ['publish', '--access=public'];

if (otp) {
args.push(`--otp=${otp}`);
}

await execa('pnpm', ['publish', '--access=public'], {
cwd: absoluteDirname(entry.pkgJSONPath),
stderr: 'inherit',
Expand All @@ -180,7 +195,7 @@ async function pnpmPublish(solution: Solution, reporter: IssueReporter, dryRun:
}
}

export async function publish(opts: { skipRepoSafetyCheck?: boolean; dryRun?: boolean }) {
export async function publish(opts: { skipRepoSafetyCheck?: boolean; dryRun?: boolean; otp?: string }) {
let dryRun = opts.dryRun ?? false;

if (!opts.skipRepoSafetyCheck) {
Expand Down Expand Up @@ -209,7 +224,7 @@ To publish a release you should start from a clean repo. Run "embroider-release
let reporter = new IssueReporter();

await makeTags(solution, reporter, dryRun);
await pnpmPublish(solution, reporter, dryRun);
await pnpmPublish(solution, reporter, dryRun, opts.otp);
await pushTags(reporter, dryRun);
await createGithubRelease(octokit, description, representativeTag, reporter, dryRun);

Expand Down

0 comments on commit b8ac17b

Please sign in to comment.