From 79b7605082d2c892df10015efc5c1af4a04860c9 Mon Sep 17 00:00:00 2001 From: Daniel Dye Date: Fri, 18 Oct 2024 14:20:47 +0100 Subject: [PATCH] Add CI/CD workflows and first test --- .github/workflows/build_and_release.yml | 54 +++++++++++++++++++++++++ commands/global.test.ts | 54 +++++++++++++++++++++++++ deno.json | 2 +- deno.lock | 15 +++++++ 4 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build_and_release.yml create mode 100644 commands/global.test.ts diff --git a/.github/workflows/build_and_release.yml b/.github/workflows/build_and_release.yml new file mode 100644 index 0000000..2aefe4f --- /dev/null +++ b/.github/workflows/build_and_release.yml @@ -0,0 +1,54 @@ +name: Build and Release + +on: + push: + +jobs: + test: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-13, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Deno + uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + - name: Run Tests + run: deno test -A + + build: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-13, macos-latest] + runs-on: ${{ matrix.os }} + needs: + - test + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Deno + uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + - name: Build + run: deno task compile + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.os }}.drenv + path: builds/* + + release: + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + needs: + - build + steps: + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + files: build/* + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/commands/global.test.ts b/commands/global.test.ts new file mode 100644 index 0000000..8731b1c --- /dev/null +++ b/commands/global.test.ts @@ -0,0 +1,54 @@ +import { describe, it, beforeAll } from "jsr:@std/testing/bdd"; +import { assertEquals, assertRejects } from "jsr:@std/assert"; +import { ensureDir } from "jsr:@std/fs"; + +import global, { NotInstalled, NoGlobalVersion } from "./global.ts"; + +describe("global", () => { + describe("when an argument is passed", () => { + describe("when DR version has been registered", () => { + beforeAll(async () => { + await ensureDir(`${Deno.env.get("HOME")}/.drenv/versions/1.0.0`); + await Deno.writeTextFile(`${Deno.env.get("HOME")}/.drenv/versions/1.0.0/CHANGELOG-CURR.txt`, "* 1.0.0"); + }) + + it("writes to the ~/.drenv/.dragonruby-version file", async () => { + await global("1.0.0"); + + const result = await Deno.readTextFile(`${Deno.env.get("HOME")}/.drenv/.dragonruby-version`); + + assertEquals(result, "1.0.0"); + }) + }) + }) + + describe("when an argument is not passed", () => { + describe("when version has been set", () => { + beforeAll(async () => { + await Deno.writeTextFile(`${Deno.env.get("HOME")}/.drenv/.dragonruby-version`, "1.0.0"); + }) + + it("returns the version from the ~/.drenv/.dragonruby-version file", async () => { + const result = await global(); + + assertEquals(result, "1.0.0"); + }) + }) + + describe("when version has not been set", () => { + beforeAll(async () => { + await Deno.remove(`${Deno.env.get("HOME")}/.drenv/.dragonruby-version`); + }) + + it("raises an error", async () => { + assertRejects( + async () => { + await global(); + }, + NoGlobalVersion, + "drenv: no global version configured" + ) + }) + }) + }) +}) diff --git a/deno.json b/deno.json index a78aab9..b2b1fef 100644 --- a/deno.json +++ b/deno.json @@ -1,7 +1,7 @@ { "tasks": { "dev": "deno run --watch main.ts", - "compile": "deno compile -A --output=builds/drenv main.ts", + "compile": "deno compile -A --output=builds/ main.ts", "compile:windows-x86": "deno compile -A --output=builds/x86_64-pc-windows-msvc.drenv --target=x86_64-pc-windows-msvc main.ts", "compile:macos-x86": "deno compile -A --output=builds/x86_64-apple-darwin.drenv --target=x86_64-apple-darwin main.ts", "compile:macos-arm64": "deno compile -A --output=builds/aarch64-apple-darwin.drenv --target=aarch64-apple-darwin main.ts", diff --git a/deno.lock b/deno.lock index 7692c2a..6e1ab7e 100644 --- a/deno.lock +++ b/deno.lock @@ -1,12 +1,15 @@ { "version": "4", "specifiers": { + "jsr:@std/assert@*": "1.0.6", "jsr:@std/assert@1": "1.0.6", + "jsr:@std/assert@^1.0.6": "1.0.6", "jsr:@std/fs@*": "1.0.4", "jsr:@std/fs@^1.0.4": "1.0.4", "jsr:@std/internal@^1.0.4": "1.0.4", "jsr:@std/path@^1.0.6": "1.0.6", "jsr:@std/semver@*": "1.0.3", + "jsr:@std/testing@*": "1.0.3", "npm:commander@*": "12.1.0", "npm:commander@^12.1.0": "12.1.0" }, @@ -31,6 +34,13 @@ }, "@std/semver@1.0.3": { "integrity": "7c139c6076a080eeaa4252c78b95ca5302818d7eafab0470d34cafd9930c13c8" + }, + "@std/testing@1.0.3": { + "integrity": "f98c2bee53860a5916727d7e7d3abe920dd6f9edace022e2d059f00d05c2cf42", + "dependencies": [ + "jsr:@std/assert@^1.0.6", + "jsr:@std/internal" + ] } }, "npm": { @@ -38,6 +48,11 @@ "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==" } }, + "remote": { + "https://deno.land/std@0.114.0/fmt/colors.ts": "8368ddf2d48dfe413ffd04cdbb7ae6a1009cf0dccc9c7ff1d76259d9c61a0621", + "https://deno.land/std@0.114.0/testing/_diff.ts": "95578951cd3c9977fd3822c64e9831c739ae8d2a5faece71d3f21bfb553f6275", + "https://deno.land/std@0.114.0/testing/asserts.ts": "550c71c634c608cffabf9e50520435cf03ff4bbd1db1253b0ade4debb444b131" + }, "workspace": { "dependencies": [ "jsr:@std/assert@1",