Skip to content

Commit

Permalink
fix(plugin-release): make --dry-run actually have an effect for relea…
Browse files Browse the repository at this point in the history
…se-commit
  • Loading branch information
kherock committed Aug 23, 2021
1 parent 82c5385 commit ea0555d
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions packages/plugin-release/sources/commands/releaseCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import {promisify}

import {changelogStream} from "../releaseUtils";

const cliEscape = (str: string): string => {
const specialChars = ` \t\n$|&><\`"'`;
return specialChars.split(``).some(char => str.includes(char))
? `'${str.replace(/'/g, `\\'`)}'`
: str;
};

// eslint-disable-next-line arca/no-default-export
export default class ReleaseCommitCommand extends BaseCommand {
static usage = Command.Usage({
Expand Down Expand Up @@ -65,21 +72,38 @@ export default class ReleaseCommitCommand extends BaseCommand {
.map(({locator, manifest}) => `${structUtils.stringifyIdent(locator)}: v${manifest.version}`)
.join(`\n`);

const commitArgs = [`commit`, `-m`, `chore: release ${projectTagName}\n\n${newWorkspaceVersions}`];
const commitMessage = `chore: release ${projectTagName}\n\n${newWorkspaceVersions}`;
const commitArgs = [`commit`, `-m`, commitMessage];
if (this.amend)
commitArgs.push(`--amend`);
await execUtils.execvp(`git`, commitArgs, {
cwd: project.cwd,
strict: true,
report.reportJson({
gitOpt: `commit`,
commitMessage,
});
if (this.dryRun) {
report.reportInfo(MessageName.UNNAMED, `git ${commitArgs.map(cliEscape).join(` `)}`);
} else {
await execUtils.execvp(`git`, commitArgs, {
cwd: project.cwd,
strict: true,
});
}

for (const {locator} of taggableWorkspaces) {
const tagName = structUtils.stringifyLocator(locator);
await execUtils.execvp(`git`, [`tag`, tagName, this.tagHead], {
cwd: project.cwd,
strict: true,
const tagArgs = [`tag`, tagName, this.tagHead];
report.reportJson({
gitOp: `tag`,
tagName,
});
report.reportJson({ident: structUtils.stringifyIdent(locator), tagName});
if (this.dryRun) {
report.reportInfo(MessageName.UNNAMED, `git ${tagArgs.map(cliEscape).join(` `)}`);
} else {
await execUtils.execvp(`git`, tagArgs, {
cwd: project.cwd,
strict: true,
});
}
}

let text = ``;
Expand All @@ -97,11 +121,19 @@ export default class ReleaseCommitCommand extends BaseCommand {
}),
getText,
]);
report.reportJson({ident: structUtils.stringifyIdent(project.topLevelWorkspace.locator), tagName: projectTagName});
await execUtils.execvp(`git`, [`tag`, `-a`, projectTagName, `-m`, `${projectTagName}\n${text}`, `--cleanup=verbatim`, this.tagHead], {
cwd: project.cwd,
strict: true,
const tagArgs = [`tag`, `-a`, `-m`, `${projectTagName}\n${text}`, `--cleanup=verbatim`, projectTagName, this.tagHead];
report.reportJson({
tagName: projectTagName,
tagMessage: text,
});
if (this.dryRun) {
report.reportInfo(MessageName.UNNAMED, `git ${tagArgs.map(cliEscape).join(` `)}`);
} else {
await execUtils.execvp(`git`, tagArgs, {
cwd: project.cwd,
strict: true,
});
}
});
return report.exitCode();
}
Expand Down

0 comments on commit ea0555d

Please sign in to comment.