Skip to content

Commit

Permalink
feat: add --tag-version-format flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Cid53 authored and antongolub committed Sep 10, 2021
1 parent aece660 commit 259864c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CLI flag options:
--ignore-packages Packages list to be ignored on bumping process (append to the ones that already exist at package.json workspaces)
--deps.bump Define deps version updating rule. Allowed: override, satisfy, inherit.
--deps.release Define release type for dependent package if any of its deps changes. Supported values: patch, minor, major, inherit.
--tag-version-format Format to use for the version number applied to tag names. Default: "@${version}" generates "package-name@1.0.0"
--help Help info.

Examples
Expand Down Expand Up @@ -92,4 +93,4 @@ You can also combine the CLI ignore options with the `!` operator at each packag
We use this tool to release our JS platform code inhouse (GitHub Enterprise + JB TeamCity) and for our OSS (GitHub + Travis CI). Guaranteed working configurations available in projects.
* [qiwi/substrate](https://github.com/qiwi/substrate)
* [qiwi/json-rpc](https://github.com/qiwi/json-rpc)
* [qiwi/lint-config-qiwi](https://github.com/qiwi/lint-config-qiwi)
* [qiwi/lint-config-qiwi](https://github.com/qiwi/lint-config-qiwi)
5 changes: 5 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const cli = meow(
--deps.bump Define deps version updating rule. Allowed: override, satisfy, inherit.
--deps.release Define release type for dependent package if any of its deps changes. Supported values: patch, minor, major, inherit.
--ignore-packages Packages' list to be ignored on bumping process
--tag-version-format Format to use for the version number applied to tag names. Default: "@\${version}" generates "package-name@1.0.0"
--help Help info.
Examples
Expand Down Expand Up @@ -49,6 +50,10 @@ const cli = meow(
ignorePackages: {
type: "string",
},
tagVersionFormat: {
type: "string",
default: "@${version}",
},
dryRun: {
type: "boolean",
},
Expand Down
2 changes: 1 addition & 1 deletion lib/multiSemanticRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async function releasePackage(pkg, createInlinePlugin, multiContext, flags) {
// Add the package name into tagFormat.
// Thought about doing a single release for the tag (merging several packages), but it's impossible to prevent Github releasing while allowing NPM to continue.
// It'd also be difficult to merge all the assets into one release without full editing/overriding the plugins.
options.tagFormat = name + "@${version}";
options.tagFormat = name + (flags.tagVersionFormat || "@${version}");

// This options are needed for plugins that do not rely on `pluginOptions` and extract them independently.
options._pkgOptions = pkgOptions;
Expand Down
27 changes: 27 additions & 0 deletions test/lib/multiSemanticRelease.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1283,4 +1283,31 @@ describe("multiSemanticRelease()", () => {
message: expect.stringMatching("can't have cyclic with sequentialPrepare option"),
});
});

test("Generated tag with custom version format", async () => {
// Create Git repo with copy of Yarn workspaces fixture.
const cwd = await gitInit();
copyDirectory(`test/fixtures/yarnWorkspaces/`, cwd);
await gitCommitAll(cwd, "feat: Initial release");
await gitInitOrigin(cwd);
await gitPush(cwd);

// Capture output.
const stdout = new WritableStreamBuffer();
const stderr = new WritableStreamBuffer();

const multiSemanticRelease = require("../../");
await multiSemanticRelease(
[`packages/a/package.json`],
{},
{ cwd, stdout, stderr },
{ tagVersionFormat: "/${version}", deps: {} }
);

// Get stdout and stderr output.
const err = stderr.getContentsAsString("utf8");
expect(err).toBe(false);
const out = stdout.getContentsAsString("utf8");
expect(out).toMatch("Created tag msr-test-a/1.0.0");
});
});

0 comments on commit 259864c

Please sign in to comment.