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

Import deno / dnit utils #1

Merged
merged 9 commits into from
Sep 3, 2020
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
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# top-most EditorConfig file
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = space
indent_size = 2
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deno test

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
deno: ["v1.x", "nightly"]
os: [ubuntu-latest]

steps:
- name: Setup repo
uses: actions/checkout@v2

- name: Setup Deno
uses: denolib/setup-deno@c7d7968ad4a59c159a777f79adddad6872ee8d96
with:
deno-version: ${{ matrix.deno }} # tests across multiple Deno versions

- name: Run Tests
run: deno test -A --unstable
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.test
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Utils for Typescript / deno / dnit

Typescript utils for deno https://deno.land/ & dnit https://deno.land/x/dnit

## Importing in projects

Deno imports via HTTP(s). There are several URL rewriting tools to help import:
- https://deno.land/x - Adds packages to their list of third party modules
- https://denopkg.com/user/repo@tag/path/to/file - A simple redirect to github raw

21 changes: 21 additions & 0 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// std & general deno dependencies

import * as flags from "https://deno.land/std@0.67.0/flags/mod.ts";
import * as fs from "https://deno.land/std@0.67.0/fs/mod.ts";
import * as hash from "https://deno.land/std@0.67.0/hash/mod.ts";
import * as io from "https://deno.land/std@0.67.0/io/mod.ts";
import * as log from "https://deno.land/std@0.67.0/log/mod.ts";
import * as path from "https://deno.land/std@0.67.0/path/mod.ts";
import * as semver from "https://deno.land/x/semver@v1.0.0/mod.ts";
import * as uuid from "https://deno.land/std@0.67.0/uuid/mod.ts";

export {
flags,
fs,
hash,
io,
log,
path,
semver,
uuid,
};
19 changes: 19 additions & 0 deletions dnit-deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Dependencies from dnit:

export {
TaskContext,
Action,
IsUpToDate,
TaskParams,
Task,
TrackedFile,
FileParams,

runAlways,
file,
task,
setupLogging,
getLogger,
exec,
execBasic,
} from "https://deno.land/x/dnit@dnit-v1.5.2/mod.ts";
1 change: 1 addition & 0 deletions dnit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.manifest.json
28 changes: 28 additions & 0 deletions dnit/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
task,
exec,
runAlways,
} from "https://deno.land/x/dnit@dnit-v1.5.2/dnit.ts";
import { runConsole } from "../process.ts";

const test = task({
name: "test",
description: "Run local tests",
action: async () => {
await runConsole(
[
"deno",
"test",
"--unstable",
"--allow-read",
"--allow-write",
"--allow-run",
],
);
},
uptodate: runAlways,
});

exec(Deno.args, [
test,
]);
91 changes: 91 additions & 0 deletions docker/docker.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { DockerImage } from "./image.ts";
import { fs, path, uuid } from "../deps.ts";
import { file } from "../dnit-deps.ts";
import { assertEquals } from "../test-deps.ts";
import { run } from "../process.ts";

Deno.test("DockerImage setup test", async () => {
const testDir = path.join(".test", uuid.v4.generate());
const ctxDir = path.join(testDir, "docker_ctxdir");
const markerDir = path.join(testDir, "built");
const dockerImage = new DockerImage("test", "test", ctxDir, markerDir);

const foo = file({ path: path.join(testDir, "foo.txt") });
await Deno.mkdir(path.dirname(foo.path), { recursive: true });
await Deno.writeTextFile(foo.path, "foo contents");

const tree = path.join(testDir, "tree");
{
await Deno.mkdir(tree, { recursive: true });
await Deno.writeTextFile(path.join(tree, "foo.txt"), "foo tree contents");
await Deno.mkdir(path.join(tree, "subdir"), { recursive: true });
await Deno.writeTextFile(
path.join(tree, "subdir", "foo.txt"),
"foo tree contents",
);
}

dockerImage.addFile(foo, "foo.txt");
dockerImage.addFileContent("bar contents", "bar.txt");
dockerImage.addFileTree(tree, "tree/treedir");

await dockerImage.copyToCtx();

console.log("checking exists " + path.join(ctxDir, "bar.txt"));

assertEquals(fs.existsSync(path.join(ctxDir, "foo.txt")), true);
assertEquals(fs.existsSync(path.join(ctxDir, "bar.txt")), true);
assertEquals(
fs.existsSync(path.join(ctxDir, "tree/treedir", "foo.txt")),
true,
);
assertEquals(
fs.existsSync(path.join(ctxDir, "tree/treedir", "subdir", "foo.txt")),
true,
);

assertEquals(
Deno.readTextFileSync(path.join(ctxDir, "foo.txt")),
"foo contents",
);
assertEquals(
Deno.readTextFileSync(path.join(ctxDir, "bar.txt")),
"bar contents",
);
assertEquals(
Deno.readTextFileSync(path.join(ctxDir, "tree/treedir", "foo.txt")),
"foo tree contents",
);
assertEquals(
Deno.readTextFileSync(
path.join(ctxDir, "tree/treedir", "subdir", "foo.txt"),
),
"foo tree contents",
);

await Deno.remove(testDir, { recursive: true });
});

Deno.test("DockerImage test", async () => {
const testDir = path.join(".test", uuid.v4.generate());
const ctxDir = path.join(testDir, "docker_ctxdir");
const markerDir = path.join(testDir, "built");
const dockerImage = new DockerImage(
"testdnitdocker",
"test",
ctxDir,
markerDir,
);
const testmsg = "testmsg" + uuid.v4.generate();
dockerImage.addFileContent(testmsg, "test/helloworld.txt");
dockerImage.fromImage("ubuntu", "18.04");
dockerImage.addCmd("COPY test/helloworld.txt /tmp");

await dockerImage.action();

const chk = await run(
["docker", "run", "testdnitdocker_test", "cat", "/tmp/helloworld.txt"],
);
assertEquals(chk, testmsg);
await Deno.remove(testDir, { recursive: true });
});
Loading