diff --git a/.github/workflows/build_and_release.yml b/.github/workflows/build_and_release.yml new file mode 100644 index 0000000..5d80139 --- /dev/null +++ b/.github/workflows/build_and_release.yml @@ -0,0 +1,73 @@ +name: Build and Release + +on: + push: + +jobs: + test: + strategy: + matrix: + os: + - name: x86_64-pc-windows-msvc + runner: windows-latest + - name: x86_64-apple-darwin + runner: macos-13 + - name: aarch64-apple-darwin + runner: macos-latest + - name: x86_64-unknown-linux-gnu + runner: ubuntu-latest + - name: aarch64-unknown-linux-gnu + runner: ubuntu-latest + runs-on: ${{ matrix.os.runner }} + 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: + - name: x86_64-pc-windows-msvc + runner: windows-latest + - name: x86_64-apple-darwin + runner: macos-13 + - name: aarch64-apple-darwin + runner: macos-latest + - name: x86_64-unknown-linux-gnu + runner: ubuntu-latest + - name: aarch64-unknown-linux-gnu + runner: ubuntu-latest + runs-on: ${{ matrix.os.runner }} + 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 compile -A --output=builds/ --target=${{ matrix.os.name }} main.ts + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.os.name }}.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/* 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/constants.ts b/constants.ts index aa3f020..b7fcd22 100644 --- a/constants.ts +++ b/constants.ts @@ -1,4 +1,4 @@ -export const version = "0.3.0"; +export const version = "0.3.1"; export const homePath = `${Deno.env.get("HOME")}/.drenv`; export const versionsPath = `${homePath}/versions`; export const binPath = `${homePath}/bin`; 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",