Skip to content

Commit

Permalink
feat: add support for prerelease (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylc committed Jun 23, 2022
1 parent f06a575 commit 08c062b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- prepatch
- preminor
- premajor
- prerelease
required: true

jobs:
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# release_up
[![deno module](https://shield.deno.dev/x/release_up)](https://deno.land/x/release_up)

<h1 align="center">
🌱 release_up
</h1>

<p align="center">
<b>Automate semver releases in Deno 🦕</b>
</p>

A fork of [release](https://github.com/denosaurs/release), by
[denosaurs](https://github.com/denosaurs), with more config options
Expand Down Expand Up @@ -27,6 +35,7 @@ $ deno install -A -f --no-check -n release_up https://deno.land/x/release_up@0.4
* prepatch <name> eg: 1.2.3 -> 1.2.4-name.0
* preminor <name> eg: 1.2.3 -> 1.3.0-name.0
* premajor <name> eg: 1.2.3 -> 2.0.0-name.0
* prerelease <name> eg: 1.2.3-name.0 -> 1.2.3-name.1
Options:
Expand Down
24 changes: 24 additions & 0 deletions cli.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { assertEquals } from "https://deno.land/std@0.141.0/testing/asserts.ts";
import { semver } from "./deps.ts";

Deno.test("semver", () => {
assertEquals(semver.inc("1.0.0", "patch", undefined, undefined), "1.0.1");
assertEquals(semver.inc("1.0.0", "minor", undefined, undefined), "1.1.0");
assertEquals(semver.inc("1.0.0", "major", undefined, undefined), "2.0.0");
assertEquals(
semver.inc("1.0.0", "prepatch", undefined, "canary"),
"1.0.1-canary.0",
);
assertEquals(
semver.inc("1.0.0-canary.1", "patch", undefined, "canary"),
"1.0.0",
);
assertEquals(
semver.inc("1.0.0", "prerelease", undefined, "canary"),
"1.0.1-canary.0",
);
assertEquals(
semver.inc("1.0.1-canary.0", "prerelease", undefined, "canary"),
"1.0.1-canary.1",
);
});
21 changes: 14 additions & 7 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ export type ReleaseType =
| "major"
| "prepatch"
| "preminor"
| "premajor";
| "premajor"
| "prerelease";

const actions: ReleaseType[] = [
const release_type: ReleaseType[] = [
"patch",
"minor",
"major",
"prepatch",
"preminor",
"premajor",
"premajor",
"prerelease",
];

const DEFAULT_CONFIG_PATH = ".release_up.json";
Expand All @@ -47,8 +50,9 @@ await new Command()
* major ${colors.dim("eg: 1.2.3 -> 2.0.0")}
* prepatch <name> ${colors.dim("eg: 1.2.3 -> 1.2.4-name.0")}
* preminor <name> ${colors.dim("eg: 1.2.3 -> 1.3.0-name.0")}
* premajor <name> ${colors.dim("eg: 1.2.3 -> 2.0.0-name.0")}`)
.type("semver", new EnumType(actions))
* premajor <name> ${colors.dim("eg: 1.2.3 -> 2.0.0-name.0")}
* prerelease <name> ${colors.dim("eg: 1.2.3-name.0 -> 1.2.3-name.1")}`)
.type("semver", new EnumType(release_type))
.arguments("<release_type:semver> [name:string]")
.option("--config <confi_path>", "Define the path of the config.", {
default: `${DEFAULT_CONFIG_PATH}`,
Expand All @@ -58,7 +62,8 @@ await new Command()
.option("--versionFile", "Enable VersionFile plugin.")
.option(
"--regex <pattern:string>",
"Enable Regex plugin. The regex need to be provided as string.",
"Enable Regex plugin. The regex need to be provided as string. --regex can be specified multiple times",
{ collect: true },
)
.option("--dry", "Dry run, Does not commit any changes.")
.option("--allowUncommitted", "Allow uncommited change in the repo.")
Expand All @@ -68,7 +73,9 @@ await new Command()
log.debug(opts, release_type, name);

let suffix: string | undefined = undefined;
if (["prepatch", "preminor", "premajor"].includes(release_type)) {
if (
["prepatch", "preminor", "premajor", "prerelease"].includes(release_type)
) {
suffix = (name as string | undefined) ?? "canary";
}

Expand Down Expand Up @@ -102,7 +109,7 @@ await new Command()
if (opts.regex) {
pluginsList.regex = regex;
// deno-lint-ignore no-explicit-any
(config as any).regex = { patterns: [opts.regex] };
(config as any).regex = { patterns: opts.regex };
}
if (opts.versionFile) pluginsList.versionFile = versionFile;

Expand Down
6 changes: 4 additions & 2 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"tasks": {
"test": "deno run -A ./cli.ts --dry --allowUncommitted --regex \"(?<=@)(.*)(?=\/cli)\" --changelog --github",
"release": "deno fmt --check && deno lint && deno run -A ./cli.ts --regex \"(?<=@)(.*)(?=\/cli)\" --github --versionFile --changelog"
"dev": "deno run -A ./cli.ts --dry --allowUncommitted --regex \"(?<=@)(.*)(?=\/cli)\" --regex \"(?<=Version: )(.*)\n\" --changelog --github",
"release": "deno fmt --check && deno lint && deno run -A ./cli.ts --regex \"(?<=@)(.*)(?=\/cli)\" --regex \"(?<=Version: )(.*)$\" --github --versionFile --changelog",
"test": "deno test -A",
"check": "deno fmt && deno lint"
},
"fmt": {
"files": {
Expand Down

0 comments on commit 08c062b

Please sign in to comment.