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

feat: mvp #1

Merged
merged 45 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6a7c25a
wip: docker based suite
Yohe-Am Nov 8, 2023
b2459ac
Merge branch 'main' into feat/mvp
Yohe-Am Nov 9, 2023
058a964
wip: worker based plugins
Yohe-Am Nov 9, 2023
40da885
wip: installation
Yohe-Am Nov 12, 2023
98fea71
wip: shimmy shim shim
Yohe-Am Nov 16, 2023
084d519
feat: ambient access plugs
Yohe-Am Nov 17, 2023
40c106a
feat: plugin deps
Yohe-Am Nov 19, 2023
5bf620f
feat: wasmedge, lib/include shims support and globs
Yohe-Am Nov 22, 2023
7cf84cb
feat(plug): pnpm
Yohe-Am Nov 22, 2023
88f1993
feat(plug): cargo-instal and wasm-tools
Yohe-Am Nov 23, 2023
4dd100b
feat(plug): wasm-opt & cargo-insta
Yohe-Am Nov 23, 2023
56657b7
feat(ci): e2e tests and some new plugs
Yohe-Am Nov 24, 2023
f9573b1
Merge branch 'main' into feat/mvp
Yohe-Am Nov 24, 2023
10b1108
wip: asdf plug support
Yohe-Am Nov 24, 2023
612731c
fix: missing changes
Yohe-Am Nov 24, 2023
97d1c6f
feat(core): asdf support
Yohe-Am Nov 24, 2023
411ee78
fix: formatting
Yohe-Am Nov 24, 2023
1b8bcfb
fix(tests): disable asdf-python
Yohe-Am Nov 24, 2023
e52fbcf
feat(plug): protoc
Yohe-Am Nov 26, 2023
4ee2592
feat(tests): `protoc`
Yohe-Am Nov 26, 2023
627e3d4
refactor(hooks): move to bash-preexec
Yohe-Am Nov 27, 2023
b3fd19f
fix(hooks): `init_ghjk` directly in hooks.sh
Yohe-Am Nov 27, 2023
eee3a6d
feat(plug): earthly
Yohe-Am Nov 27, 2023
915abbc
fix: change installId format to something less problematic
Yohe-Am Nov 28, 2023
6fe347e
feat(plug): ruff
Yohe-Am Nov 28, 2023
0a90307
feat(plug): whiz
Yohe-Am Nov 30, 2023
08b4c36
refactor: native js `unarchive`
Yohe-Am Nov 30, 2023
f21dafb
fix: use zipjs
Yohe-Am Nov 30, 2023
0b0fb49
fix: better `unarchive`
Yohe-Am Nov 30, 2023
74d44a6
fix: get tests working
Yohe-Am Nov 30, 2023
237c057
fix: address feedback
Yohe-Am Nov 30, 2023
5e19714
fix: remove dead code
Yohe-Am Nov 30, 2023
f95a1bc
refactor: `install.ts` -> `setup.ts`
Yohe-Am Dec 1, 2023
d7511a6
refactor: `setup.ts` -> `init.ts`
Yohe-Am Dec 1, 2023
f06ec82
wip: `modules`
Yohe-Am Dec 1, 2023
da08af2
wip: `plugs` -> `ports`
Yohe-Am Dec 1, 2023
324906d
refactor: big un
Yohe-Am Dec 2, 2023
fb7d8e0
fix: apply feedback
Yohe-Am Dec 4, 2023
cbb0f39
fix: pin debian pkg versions for test dockerfile
Yohe-Am Dec 4, 2023
1c818e0
fix: back to aliases and zsh support
Yohe-Am Dec 4, 2023
9dc062c
refactor(hooks): explicit bash command
Yohe-Am Dec 4, 2023
fe0e00b
feat(ci): ghjk action
Yohe-Am Dec 5, 2023
56de32f
fix(ci): missing shell prop
Yohe-Am Dec 5, 2023
fa8e79a
fix(action): improve outputs
Yohe-Am Dec 5, 2023
278beb1
refactor: make hooks more efficient
Yohe-Am Dec 5, 2023
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
.vscode
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ repos:
- ts
- tsx
files: ^website/
- id: version
name: "Lock versions"
always_run: true
Yohe-Am marked this conversation as resolved.
Show resolved Hide resolved
language: system
entry: bash -c 'deno run -A dev/lock.ts --check'
pass_filenames: false
# - id: version
Yohe-Am marked this conversation as resolved.
Show resolved Hide resolved
# name: "Lock versions"
# always_run: true
# language: system
# entry: bash -c 'deno run -A dev/lock.ts --check'
# pass_filenames: false
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
hooks:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
}
71 changes: 64 additions & 7 deletions cli/core/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,56 @@ const log = console.log;
console.log = (...args) => {
log("[ghjk.ts]", ...args);
};
const module = await import(Deno.args[0]);
console.log = log;
module.ghjk.runCli(Deno.args.slice(1));
const mod = await import(Deno.args[0]);
mod.ghjk.runCli(Deno.args.slice(1));
`,
"hooks/hook.sh": `
ghjk_already_run=false

ghjk_hook() {
zifeo marked this conversation as resolved.
Show resolved Hide resolved
# Check if the trap has already executed
if [[ "$ghjk_already_run" = true ]]; then
return
fi
ghjk_already_run=true
if [[ -v GHJK_CLEANUP ]]; then
eval $GHJK_CLEANUP
unset GHJK_CLEANUP
fi
current_dir=$PWD
while [ "$current_dir" != "/" ]; do
if [ -e "$current_dir/ghjk.ts" ]; then
shim="$HOME/.local/share/ghjk/shims/$(echo "$current_dir" | tr '/' '.')"
if [ -d "$shim" ]; then
PATH="$shim:$(echo "$PATH" | grep -v "^$HOME\/\.local\/share\/ghjk\/shim")"
source "$shim/loader.fish"
if [ "$shim/loader.fish" -ot "$current_dir/ghjk.ts" ]; then
echo -e "\e[38;2;255;69;0m[ghjk] Detected changes, please sync...\e[0m"
fi
else
echo -e "\e[38;2;255;69;0m[ghjk] Uninstalled runtime found, please sync...\e[0m"
echo "$shim"
fi
alias ghjk="deno run -A $HOME/.local/share/ghjk/hooks/entrypoint.ts $current_dir/ghjk.ts"
return
fi
cur_dir="$(dirname "$current_dir")"
done
alias ghjk "echo 'No ghjk.ts config found.'"
}

trap 'ghjk_hook' DEBUG

set_again() {
ghjk_already_run=false
}

if [[ -n "$PROMPT_COMMAND" ]]; then
PROMPT_COMMAND+=";"
fi

PROMPT_COMMAND+="set_again;"
`,
"hooks/hook.fish": `
function ghjk_hook --on-variable PWD
if set --query GHJK_CLEANUP
Expand Down Expand Up @@ -55,10 +101,15 @@ async function detectShell(): Promise<string> {
"-o",
"comm=",
]);
const path = parent.unwrapOrElse((e) => {
throw new Error(`cannot get parent process name: ${e}`);
}).trimEnd();

const path = parent
.unwrapOrElse((e) => {
const envShell = Deno.env.get("SHELL");
if (!envShell) {
throw new Error(`cannot get parent process name: ${e}`);
}
return envShell;
})
.trimEnd();
return basename(path, ".exe").toLowerCase();
}

Expand Down Expand Up @@ -117,6 +168,12 @@ export async function install() {
/\.local\/share\/ghjk\/hooks\/hook.fish/,
"source $HOME/.local/share/ghjk/hooks/hook.fish",
);
} else if (shell === "bash") {
await filterAddFile(
resolve(homeDir, ".bashrc"),
/\.local\/share\/ghjk\/hooks\/hook.sh/,
"source $HOME/.local/share/ghjk/hooks/hook.sh",
);
} else {
throw new Error(`unsupported shell: ${shell}`);
}
Expand Down
1 change: 1 addition & 0 deletions cli/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class SyncCommand extends Command {
// (beware of multiple versions of tools libs)
// here, only showing what should happen after as an example

return;
const nodeTool = node({ version: "v21.1.0" });

// build dag
Expand Down
48 changes: 36 additions & 12 deletions cli/utils.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,68 @@
import { Err, Ok, Result } from "./deps.ts";

export function dbg<T>(val: T) {
console.log("[dbg] ", val);
return val;
}

export async function runAndReturn(
cmd: string[],
cwd?: string,
env: Record<string, string> = Deno.env.toObject(),
): Promise<Result<string, string>> {
const output = await new Deno.Command(cmd[0], {
args: cmd.slice(1),
cwd,
stdout: "piped",
stderr: "piped",
env,
}).output();
try {
const output = await new Deno.Command(cmd[0], {
args: cmd.slice(1),
cwd,
stdout: "piped",
stderr: "piped",
env,
}).output();

return output.success
? Ok(new TextDecoder().decode(output.stdout))
: Err(new TextDecoder().decode(output.stderr));
return output.success
? Ok(new TextDecoder().decode(output.stdout))
: Err(new TextDecoder().decode(output.stderr));
} catch (err) {
return Err(err.toString());
}
}

export async function runOrExit(
cmd: string[],
cwd?: string,
env: Record<string, string> = Deno.env.toObject(),
options: {
cwd?: string;
env?: Record<string, string>;
pipeInput?: string;
} = {},
) {
const { cwd, env, pipeInput } = {
...options,
env: options.env ?? Deno.env.toObject(),
};
console.log(cmd);
const p = new Deno.Command(cmd[0], {
args: cmd.slice(1),
cwd,
stdout: "piped",
stderr: "piped",
stdin: "piped",
env,
}).spawn();

// keep pipe asynchronous till the command exists
void p.stdout.pipeTo(Deno.stdout.writable, { preventClose: true });
void p.stderr.pipeTo(Deno.stderr.writable, { preventClose: true });

if (pipeInput) {
const writer = p.stdin.getWriter();
await writer.write(new TextEncoder().encode(pipeInput));
await writer.close();
}
const { code, success } = await p.status;
if (!success) {
Deno.exit(code);
}
//await p.stdin.close();
}

function home_dir(): string | null {
Expand Down
6 changes: 6 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tasks": {
// "test": "DOCKER_SOCK=/var/run/docker.sock deno test --unstable --allow-env=DOCKER_SOCK --allow-read=/var/run/docker.sock --allow-write=/var/run/docker.sock tests/*"
"test": "deno test --unstable --allow-run=docker --allow-read --allow-env tests/*"
}
}
Loading