diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5305b044..8f9970b5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,12 @@ name: Release +run-name: github.event.head_commit.message on: + push: + branches: + - main + paths: + - '**/deno.json' workflow_dispatch: defaults: @@ -11,6 +17,7 @@ jobs: publish: name: Publish runs-on: ubuntu-latest + if: "contains(github.event.head_commit.message, 'chore: release')" permissions: contents: read diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index ce0dcb96..8028706f 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -1,4 +1,5 @@ -name: update +name: Update +run-name: github.event.head_commit.message on: schedule: @@ -11,6 +12,7 @@ permissions: jobs: update: + name: Update runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/_tools/bump.ts b/_tools/bump.ts new file mode 100644 index 00000000..09749f2c --- /dev/null +++ b/_tools/bump.ts @@ -0,0 +1,38 @@ +import { associateWith, maxWith } from "@std/collections"; +import { compare, format, increment, parse, ReleaseType } from "@std/semver"; + +type PackageName = "core" | "cli" | "integration" | "lib"; + +type Config = { + version: string; +}; + +const [type, ...pkgs] = Deno.args as [ReleaseType, ...PackageName[]]; + +const jsons = associateWith( + pkgs, + (pkg) => JSON.parse(Deno.readTextFileSync(`./${pkg}/deno.json`)) as Config, +); + +const vers = Object.values(jsons).map((json) => json.version).map(parse); +const max = maxWith(vers, compare)!; +const bumped = format(increment(max, type)); + +for (const [pkg, json] of Object.entries(jsons)) { + json.version = bumped; + await Deno.writeTextFile( + `./${pkg}/deno.json`, + JSON.stringify(json, null, 2) + "\n", + ); +} + +await new Deno.Command("git", { + args: [ + "commit", + "-m", + `chore: release ${bumped}`, + ...pkgs.map((it) => `${it}/deno.json`), + ], + stdout: "inherit", + stderr: "inherit", +}).output(); diff --git a/deno.json b/deno.json index 8b819017..2361ceab 100644 --- a/deno.json +++ b/deno.json @@ -1,5 +1,6 @@ { "tasks": { + "bump": "deno run -A ./_tools/bump.ts", "cache": "deno task -q ls | xargs deno cache", "check": "deno task -q ls | xargs deno check", "ls": "ls ./lib/*.ts ./core/*.ts ./integration/*.ts ./cli/*.ts ./cli/src/*.ts",