Skip to content

Commit

Permalink
Add CI/CD workflows and first test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitemaeric committed Oct 18, 2024
1 parent b0773c6 commit a822139
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 1 deletion.
53 changes: 53 additions & 0 deletions .github/workflows/build_and_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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@v2
- name: Set up Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Run Tests
run: deno -A test

build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-13, macos-latest]
runs-on: ${{ matrix.os }}
needs:
- test
steps:
- name: Checkout
uses: actions/checkout@v2
- 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:
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 }}
54 changes: 54 additions & 0 deletions commands/global.test.ts
Original file line number Diff line number Diff line change
@@ -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"
)
})
})
})
})
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 15 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a822139

Please sign in to comment.