Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI/CD workflows and first test #5

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/build_and_release.yml
Original file line number Diff line number Diff line change
@@ -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/*
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 constants.ts
Original file line number Diff line number Diff line change
@@ -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`;
Expand Down
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.

Loading