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

Feature/deno upgrade #199

Merged
merged 7 commits into from
Jul 3, 2023
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: 0 additions & 10 deletions .github/.kodiak.toml

This file was deleted.

34 changes: 8 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,36 @@ jobs:
fmt-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: deno-fmt
id: fmt
uses: denoland/setup-deno@main
with:
deno-version: "~1.25"
deno-version: "~1.34"
- run: |
deno fmt --check

- name: comment-pr
if: ${{ failure() }}
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { issue: { number: issue_number }, repo: { owner, repo } } = context;
github.issues.createComment({ issue_number, owner, repo, body: 'Error in `deno fmt`. Please check the Action logs.' });

linting-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: check-linting
id: lint
uses: denoland/setup-deno@main
with:
deno-version: "~1.25"
deno-version: "~1.34"
- run: |
deno lint

- name: comment-pr
if: ${{ failure() }}
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { issue: { number: issue_number }, repo: { owner, repo } } = context;
github.issues.createComment({ issue_number, owner, repo, body: 'Error in `deno lint`. Please check the Action logs.' });

build:
if: ${{ success() }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: denoland/setup-deno@main
with:
deno-version: "~1.25"
- uses: actions/cache@v2
deno-version: "~1.34"
- uses: actions/cache@v3
with:
path: ~/.cache/deno # see https://deno.land/manual/linking_to_external_code
key: ${{ runner.os }}-deno # it seems there's no particular cache keying required
Expand All @@ -70,7 +52,7 @@ jobs:

- name: Archive production artifacts
if: ${{ github.event_name != 'pull_request' }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: collie
path: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
pr-labeler:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: TimonVS/pr-labeler-action@v3
with:
configuration-path: .github/pr-labeler-config.yml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: new-version
id: version
Expand Down
8 changes: 2 additions & 6 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
"strict": true
},
"lint": {
"files": {
"include": ["src/"]
}
"include": ["src/"]
},
"fmt": {
"files": {
"include": ["src/"]
}
"include": ["src/"]
},
"tasks": {
"run": "deno run $(deno run --quiet --no-check ./flags.ts) ./src/main.ts",
Expand Down
430 changes: 430 additions & 0 deletions deno.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ done
# Download artifacts based on CPU architecture and OS type
case "$(uname -s)" in
Darwin)
url=$(curl -s https://api.github.com/repos/meshcloud/collie-cli/releases/latest | grep "browser_download_url.*$arch*apple" | cut -d : -f 2,3 | tr -d \" | tr -d \ )
name="collie-$arch-apple-darwin"
url=$(curl -s https://api.github.com/repos/meshcloud/collie-cli/releases/latest | grep "browser_download_url.*$arch.*apple" | cut -d : -f 2,3 | tr -d \" | tr -d \ )
name="collie-$arch-apple-darwin"
;;
Linux)
echo "detected Linux"
url=$(curl -s https://api.github.com/repos/meshcloud/collie-cli/releases/latest | grep "browser_download_url.*linux" | cut -d : -f 2,3 | tr -d \" | tr -d \ )
name="collie-x86_64-unknown-linux-gnu"
;;
Expand All @@ -40,6 +41,7 @@ case "$(uname -s)" in
exit 1
;;
esac

echo "Downloading the artifact... (${url})"
curl "${url}" -L -o collie.tar.gz --silent
# untar and movin the artifact
Expand Down
11 changes: 6 additions & 5 deletions src/model/schemas/ModelValidator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import schema from "./schema.json" assert { type: "json" };

import Ajv, { ErrorObject } from "https://esm.sh/ajv@8.11.0";
import addFormats from "https://esm.sh/[email protected]";
import Ajv, { ErrorObject } from "npm:ajv@8.12.0";
import addFormats from "npm:[email protected]";
import {
FoundationConfig,
FoundationFrontmatter,
Expand All @@ -13,13 +13,14 @@ import { KitModule } from "../../kit/KitModule.ts";
import { ComplianceControl } from "../../compliance/ComplianceControl.ts";

export class ModelValidator {
private readonly ajv: Ajv;
private readonly ajv: Ajv.default;
constructor(private readonly logger: Logger) {
this.ajv = new Ajv({ allErrors: true });
// sorry about the .default stuff here, there's probably a better way to do this
this.ajv = new Ajv.default({ allErrors: true });

// something's wrong about the typings here
// deno-lint-ignore no-explicit-any
addFormats(this.ajv as any);
addFormats.default(this.ajv as any);

this.ajv.addSchema(schema);
}
Expand Down
2 changes: 1 addition & 1 deletion src/process/ProcessRunnerResult.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface ProcessResult {
status: Deno.ProcessStatus;
status: Deno.CommandStatus;
}

export interface ProcessResultWithOutput extends ProcessResult {
Expand Down
28 changes: 18 additions & 10 deletions src/process/QuietProcessRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,32 @@ export class QuietProcessRunner
commands: string[],
options?: ProcessRunnerOptions,
): Promise<ProcessResultWithOutput> {
const p = Deno.run({
const args = ShellRunnerPolicy.shellCommands(commands);
const exec = args.shift();

if (!exec) {
throw new Error("Invalid argument: commands is empty");
}

const cmd = new Deno.Command(exec, {
...options,
cmd: ShellRunnerPolicy.shellCommands(commands),
args,
stdout: "piped",
stderr: "piped",
});

const decoder = new TextDecoder();
const rawOutput = await p.output();
const rawError = await p.stderrOutput();
const status = await p.status();
const output = await cmd.output();

p.close();
const decoder = new TextDecoder();

const result = {
status,
stderr: decoder.decode(rawError),
stdout: decoder.decode(rawOutput),
status: {
signal: output.signal,
code: output.code,
success: output.success,
},
stdout: decoder.decode(output.stdout),
stderr: decoder.decode(output.stderr),
};

return result;
Expand Down
16 changes: 11 additions & 5 deletions src/process/TransparentProcessRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ export class TransparentProcessRunner implements IProcessRunner<ProcessResult> {
commands: string[],
options?: ProcessRunnerOptions,
): Promise<ProcessResult> {
const p = Deno.run({
const args = ShellRunnerPolicy.shellCommands(commands);
const exec = args.shift();

if (!exec) {
throw new Error("Invalid argument: commands is empty");
}

const cmd = new Deno.Command(exec, {
...options,
cmd: ShellRunnerPolicy.shellCommands(commands),
args,
stdout: "inherit",
stderr: "inherit",
});

const status = await p.status();

p.close();
const p = cmd.spawn();
const status = await p.status;

const result: ProcessResult = {
status,
Expand Down