diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index 20cf941..f96a0be 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -24,8 +24,12 @@ jobs: steps: - uses: actions/checkout@v4 - uses: denoland/setup-deno@v2 - - run: deno test --allow-read --parallel --junit-path=./junit.xml - - uses: EnricoMi/publish-unit-test-result-action@v2 - if: always() + - run: deno test --allow-read --parallel --coverage=cov/ --junit-path=./junit.xml + - run: deno coverage --lcov cov/ > cov.lcov + - uses: codecov/codecov-action@v5 with: - files: junit.xml + token: ${{ secrets.CODECOV_TOKEN }} + - uses: codecov/test-results-action@v1 + if: ${{ !cancelled() }} + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/cli.ts b/cli.ts index e25e6b3..d794ce4 100644 --- a/cli.ts +++ b/cli.ts @@ -1,6 +1,7 @@ import { colors } from "@cliffy/ansi/colors"; import { Command } from "@cliffy/command"; import { Input, Select } from "@cliffy/prompt"; +import { greaterThan, parse } from "@std/semver"; import { readLinesFromFile } from "utils"; import { days } from "./days/mod.ts"; import denoJson from "./deno.json" with { type: "json" }; @@ -18,6 +19,33 @@ const list = new Command() } }); +const update = new Command() + .description("Update to the latest version") + .action(async () => { + const { latest } = await fetch(`https://jsr.io/${denoJson.name}/meta.json`) + .then( + (res) => res.json(), + ); + const isUpdateAvailable = greaterThan( + parse(latest), + parse(denoJson.version), + ); + if (isUpdateAvailable) { + console.log( + colors.bold.yellow( + `Update available: ${denoJson.version} -> ${latest}`, + ), + ); + console.log("Updating..."); + await new Deno.Command(Deno.execPath(), { + args: ["run", "-r", `jsr:@aoc/2024`, "--help"], + }).output(); + console.log(colors.bold.green("Updated successfully")); + } else { + console.log(colors.bold.green("Already up to date")); + } + }); + const main = new Command() .name("Advent of Code - 2024") .version(denoJson.version) @@ -83,5 +111,6 @@ function isWebUrl(path: string): boolean { if (import.meta.main) { await main .command("list", list) + .command("update", update) .parse(Deno.args); } diff --git a/deno.json b/deno.json index c397bd7..d7a6fe5 100644 --- a/deno.json +++ b/deno.json @@ -4,7 +4,7 @@ "license": "MIT", "exports": "./cli.ts", "tasks": { - "cli": "deno run --allow-read ./cli.ts", + "cli": "deno run -RN ./cli.ts", "update:version": "deno run -A ./scripts/update_version.ts" }, "imports": { diff --git a/deno.lock b/deno.lock index 7faaf0f..3b942ae 100644 --- a/deno.lock +++ b/deno.lock @@ -1,6 +1,7 @@ { "version": "4", "specifiers": { + "jsr:@aoc/2024@1.3.0": "1.3.0", "jsr:@cliffy/ansi@1.0.0-rc.5": "1.0.0-rc.5", "jsr:@cliffy/command@1.0.0-rc.5": "1.0.0-rc.5", "jsr:@cliffy/flags@1.0.0-rc.5": "1.0.0-rc.5", @@ -31,6 +32,17 @@ "npm:@types/node@*": "22.5.4" }, "jsr": { + "@aoc/2024@1.3.0": { + "integrity": "ed1fada613b52b8330826e90cd1ad1591a020c3a7599d70b189c487357b6579f", + "dependencies": [ + "jsr:@cliffy/ansi", + "jsr:@cliffy/command", + "jsr:@cliffy/prompt", + "jsr:@std/collections", + "jsr:@std/path@1", + "jsr:@std/streams" + ] + }, "@cliffy/ansi@1.0.0-rc.5": { "integrity": "85a4dba4da5d8278dcdfeea98672cd15706c244833f82edc60c61f410d9fc1a9", "dependencies": [