Skip to content

Commit

Permalink
feat!: Migrate to JSR.io (#26)
Browse files Browse the repository at this point in the history
* use jsr form most

* fmt

* x

* fix order

* clean

* x
  • Loading branch information
sylc authored Jun 2, 2024
1 parent 8db55e8 commit bf06cf7
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 224 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![deno module](https://shield.deno.dev/x/release_up)](https://deno.land/x/release_up)
[![JSR](https://jsr.io/badges/@sylc/release_up)](https://jsr.io/@sylc/release_up)

<h1 align="center">
🌱 release_up
Expand All @@ -24,7 +24,7 @@ Most changes are optionals and configurable.
# Installation

```
$ deno install -A -f -n release_up https://deno.land/x/[email protected]/cli.ts
$ deno install --global --force --allow-run --allow-net -n release_up jsr:@sylc/release-up
```

# Usage
Expand Down
39 changes: 31 additions & 8 deletions cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
import { assertEquals } from "https://deno.land/std@0.177.0/testing/asserts.ts";
import { assertEquals } from "jsr:@std/assert@0.225.3";
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"),
semver.format(
semver.increment(semver.parse("1.0.0"), "patch", undefined, undefined),
),
"1.0.1",
);
assertEquals(
semver.format(
semver.increment(semver.parse("1.0.0"), "minor", undefined, undefined),
),
"1.1.0",
);
assertEquals(
semver.format(
semver.increment(semver.parse("1.0.0"), "major", undefined, undefined),
),
"2.0.0",
);
assertEquals(
semver.format(
semver.increment(semver.parse("1.0.0"), "prepatch", "canary"),
),
"1.0.1-canary.0",
);
assertEquals(
semver.inc("1.0.0-canary.1", "patch", undefined, "canary"),
semver.format(
semver.increment(semver.parse("1.0.0-canary.1"), "patch", "canary"),
),
"1.0.0",
);
assertEquals(
semver.inc("1.0.0", "prerelease", undefined, "canary"),
semver.format(
semver.increment(semver.parse("1.0.0"), "prerelease", "canary"),
),
"1.0.1-canary.0",
);
assertEquals(
semver.inc("1.0.1-canary.0", "prerelease", undefined, "canary"),
semver.format(
semver.increment(semver.parse("1.0.1-canary.0"), "prerelease", "canary"),
),
"1.0.1-canary.1",
);
});
56 changes: 37 additions & 19 deletions cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { colors, delay, log, semver, wait } from "./deps.ts";
import { colors, delay, log, semver, step } from "./deps.ts";
import { Command, EnumType } from "./deps.ts";

import type { ReleaseConfig } from "./config.ts";
import { fetchRepo, Repo } from "./src/repo.ts";
import { fetchRepo, type Repo } from "./src/repo.ts";
import { ezgit } from "./src/git.ts";

// Plugins
Expand All @@ -12,7 +12,7 @@ import regex from "./plugins/regex/mod.ts";
import versionFile from "./plugins/versionFile/mod.ts";

import config from "./deno.json" with { type: "json" };
import { ReleasePlugin } from "./plugin.ts";
import type { ReleasePlugin } from "./plugin.ts";
import { initLogger } from "./src/log.ts";

const version = config.version;
Expand Down Expand Up @@ -53,7 +53,8 @@ await new Command()
* 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")}
* prerelease <name> ${colors.dim("eg: 1.2.3-name.0 -> 1.2.3-name.1")}`)
* prerelease <name> ${colors.dim("eg: 1.2.3-name.0 -> 1.2.3-name.1")}
name default to 'canary'`)
.type("semver", new EnumType(release_type))
.arguments("<release_type:semver> [name:string]")
.option("--config <config_path>", "Define the path of the config.", {
Expand All @@ -71,7 +72,7 @@ await new Command()
.option("--allowUncommitted", "Allow uncommited change in the repo.")
.option("--debug", "Enable debug logging.")
.action(async (opts, release_type, name) => {
await initLogger(opts.debug);
initLogger(opts.debug);
log.debug(opts, release_type, name);

let suffix: string | undefined = undefined;
Expand Down Expand Up @@ -164,33 +165,35 @@ await new Command()
}

// Load Repo
const fetch = wait("Loading project info").start();
const fetch = step("Loading project info").start();
let repo: Repo;
try {
repo = await fetchRepo(Deno.cwd());
} catch (err) {
fetch.fail(Deno.inspect(err));
console.log(err);
fetch.fail();
log.critical(err.message);
Deno.exit(1);
}
fetch.succeed("Project loaded correctly");

const [latest] = repo.tags;
const from = latest ? latest.version : "0.0.0";
const to = semver.inc(from, release_type, undefined, suffix)!;
const to = semver.increment(semver.parse(from), release_type, suffix);

const integrity = wait("Checking the project").start();
const integrity = step("Checking the project").start();
await delay(1000);
if (repo.status.raw.length !== 0) {
if (opts.allowUncommitted) {
integrity.fail(
console.log(
"Uncommitted changes on your repository - allowUncommitted is true passing... ",
);
} else {
integrity.fail("Uncommitted changes on your repository!");
Deno.exit(1);
}
} else if (!repo.commits.some((_) => _.belongs === null)) {
integrity.fail(`No changes since the last release!`);
integrity.fail("No changes since the last release!");
Deno.exit(1);
}
integrity.succeed("Project check successful");
Expand All @@ -200,7 +203,14 @@ await new Command()
if (!plugin.preCommit) continue;
try {
log.debug(`Executing preCommit ${plugin.name}`);
await plugin.preCommit(repo, release_type, from, to, config, log);
await plugin.preCommit(
repo,
release_type,
from,
semver.format(to),
config,
log,
);
} catch (err) {
log.critical(err.message);
Deno.exit(1);
Expand All @@ -214,10 +224,11 @@ await new Command()
Deno.exit(1);
}

const bump = wait(
`Releasing ${colors.bold(to)} ${colors.dim(`(latest was ${from})`)}`,
const bump = step(
`Releasing ${colors.bold(semver.format(to))} ${
colors.dim(`(latest was ${from})`)
}`,
).start();

if (!opts.dry) {
try {
await ezgit(repo.path, "add -A");
Expand All @@ -231,14 +242,14 @@ await new Command()
await ezgit(repo.path, "push");
await ezgit(repo.path, "push --tags");
} catch (err) {
bump.fail(`Unable to release ${colors.bold(to)}\n`);
bump.fail(`Unable to release ${colors.bold(semver.format(to))}\n`);
log.critical(err.message);
Deno.exit(1);
}
bump.succeed(`Released ${colors.bold(to)}!`);
bump.succeed(`Released ${colors.bold(semver.format(to))}!`);
} else {
bump.warn(
`Skipping release ${colors.bold(to)} ${
`Skipping release ${colors.bold(semver.format(to))} ${
colors.dim(
`(latest was ${from})`,
)
Expand All @@ -250,7 +261,14 @@ await new Command()
if (!plugin.postCommit) continue;
try {
log.debug(`Executing postCommit ${plugin.name}`);
await plugin.postCommit(repo, release_type, from, to, config, log);
await plugin.postCommit(
repo,
release_type,
from,
semver.format(to),
config,
log,
);
} catch (err) {
log.critical(err.message);
Deno.exit(1);
Expand Down
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@sylc/release_up",
"name": "@sylc/release-up",
"version": "0.8.0",
"exports": "./cli.ts",
"tasks": {
"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 --config ./tools/.release_up.json",
"test": "deno test -A",
"check": "deno fmt && deno lint"
"check": "deno fmt && deno lint && deno check ./cli.ts"
},
"fmt": {
"exclude": ["CHANGELOG.md"]
Expand Down
Loading

0 comments on commit bf06cf7

Please sign in to comment.