Skip to content

Commit

Permalink
feat(tests): local e2e suite runer
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Dec 11, 2023
1 parent 46fa189 commit d738a72
Show file tree
Hide file tree
Showing 18 changed files with 364 additions and 136 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,25 @@ jobs:
- uses: pre-commit/[email protected]

test-e2e:
runs-on: ubuntu-latest
runs-on: "${{ matrix.os }}"
strategy:
matrix:
include:
- runs-on: ubuntu-latest
e2eType: "docker"
- os: macos-latest
e2eType: "local"
# - os: windows-latest
# e2eType: "local"
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
with:
deno-version: ${{ env.DENO_VERSION }}
- uses: docker/setup-buildx-action@v3
- uses: actions-hub/docker/cli@master
- if: "${{ matrix.e2eType == 'docker' }}"
uses: docker/setup-buildx-action@v3
- if: "${{ matrix.e2eType == 'docker' }}"
uses: actions-hub/docker/cli@master
env:
SKIP_LOGIN: true
- run: deno task test
Expand Down
14 changes: 9 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
name: 'Setup Ghjk'
description: 'Installs ghjk and optionally syncs according to the config'
inputs:
installer-uri:
description: 'Alternative installer script to use'
version:
description: 'Github version/branch to install from'
required: true
# FIXME: find a way to get commit sha of current executing action version
# default: $GITHUB_SERVER_URL/$GITHUB_ACTION_REPOSITORY/raw/feat/
default: './install.ts'
default: 'v0.1.0-alpha'
# installer-uri:
# description: 'Alternative installer script to use'
# required: true
# # FIXME: find a way to get commit sha of current executing action version
# # default: $GITHUB_SERVER_URL/$GITHUB_ACTION_REPOSITORY/raw/feat/
# default: './install.ts'
sync:
description: 'Disable to skip syncing ports'
required: true
Expand Down
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"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 --fail-fast --parallel --unstable --allow-run=docker,sudo,which,ls,tar,git,curl,unzip --allow-read --allow-env tests/*",
"test": "deno test --fail-fast --parallel --unstable -A tests/*",
"cache": "deno cache deps/*",
"check": "deno check *.ts **/*.ts",
"lint": "deno lint --ignore=ghjk.ts,play.ts --rules-exclude=no-explicit-any"
Expand Down
54 changes: 52 additions & 2 deletions deno.lock

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

2 changes: 1 addition & 1 deletion ghjk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import whiz from "./ports/whiz.ts";
// cargo_insta({});
// jco({});
// mold({});
// act({});
act({});
// asdf({
// pluginRepo: "https://github.com/asdf-community/asdf-cmake",
// installType: "version",
Expand Down
22 changes: 9 additions & 13 deletions host/mod.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import "../setup_logger.ts";

import { std_path } from "../deps/common.ts";
import { cliffy_cmd } from "../deps/cli.ts";
import logger from "../utils/logger.ts";
import logger, { isColorfulTty } from "../utils/logger.ts";
// import { $ } from "../utils/mod.ts";

import { envDirFromConfig, findConfig, isColorfulTty } from "../utils/mod.ts";
import { envDirFromConfig } from "../utils/mod.ts";
import validators from "./types.ts";
import * as std_modules from "../modules/std.ts";
import * as deno from "./deno.ts";

export async function main() {
const configPathIn = Deno.env.get("GHJK_CONFIG") ??
await findConfig(Deno.cwd());
if (!configPathIn) {
logger().error("ghjk did not find any `ghjk.ts` config.");
Deno.exit(2);
}
const configPath = std_path.resolve(Deno.cwd(), configPathIn);
const envDir = envDirFromConfig(configPath);
export interface MainArgs {
ghjkDir: string;
configPath: string;
}
export async function main(args: MainArgs) {
const { configPath, ghjkDir } = args;
const envDir = envDirFromConfig(ghjkDir, configPath);

logger().debug({ configPath });
logger().debug({ envDir });
Expand Down
23 changes: 20 additions & 3 deletions install.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
//! Setup ghjk for the CWD
//! Install ghjk for the current user

import { install } from "./install/mod.ts";
import "./setup_logger.ts";
import { defaultInstallArgs, detectShell, install } from "./install/mod.ts";

if (import.meta.main) {
await install();
const skipBinInstall = Deno.env.get("GHJK_INSTALL_SKIP_EXE");
await install({
...defaultInstallArgs,
ghjkDir: Deno.env.get("GHJK_DIR") ?? defaultInstallArgs.ghjkDir,
skipExecInstall: skipBinInstall == "0" || skipBinInstall == "false",
shellsToHook: Deno.env.get("GHJK_INSTALL_HOOK_SHELLS")
?.split(",")
?.map((str) => str.trim())
?.filter((str) => str.length > 0) ??
[
await detectShell(),
],
ghjkExecInstallDir: Deno.env.get("GHJK_INSTALL_EXE_DIR") ??
defaultInstallArgs.ghjkExecInstallDir,
shellHookMarker: Deno.env.get("GHJK_INSTALL_HOOK_MARKER") ??
defaultInstallArgs.shellHookMarker,
});
} else {
throw new Error(
"unexpected ctx: if you want to access the ghjk installer, import `install` from ./install/mod.ts",
Expand Down
11 changes: 5 additions & 6 deletions install/hooks/bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ ansi_yel='\033[0;33m'
ansi_nc='\033[0m' # No Color

init_ghjk() {
if [ -n "${GHJK_CLEANUP+x}" ]; then
eval "$GHJK_CLEANUP"
if [ -n "${GHJK_CLEANUP_POSIX+x}" ]; then
eval "$GHJK_CLEANUP_POSIX"
fi
unset GHJK_CLEANUP
unset GHJK_CLEANUP_POSIX
unset GHJK_LAST_LOADER_PATH
unset GHJK_LAST_LOADER_TS
cur_dir=$PWD
while [ "$cur_dir" != "/" ]; do
if [ -e "$cur_dir/ghjk.ts" ]; then
envDir="$HOME/.local/share/ghjk/envs/$(printf "$cur_dir" | tr '/' '.')"
envDir="__GHJK_DIR__/envs/$(printf "$cur_dir" | tr '/' '.')"
if [ -d "$envDir" ]; then
export GHJK_LAST_LOADER_PATH="$envDir/loader.sh"
export GHJK_LAST_LOADER_TS=$(stat -c "%Y" "$GHJK_LAST_LOADER_PATH" | tr -d '\n')
Expand Down Expand Up @@ -54,9 +54,8 @@ export LAST_PWD="$PWD"
precmd() {
if [ "$LAST_PWD" != "$PWD" ] || (
# if the last detected loader has been touched
[ -n "${GHJK_LAST_LOADER_PATH+x}" ] && [ $(stat -c "%Y" "$GHJK_LAST_LOADER_PATH" | tr -d '\n') != $(("$GHJK_LAST_LOADER_TS")) ]
[ -n "${GHJK_LAST_LOADER_PATH+x}" ] && [ $(stat -c "%Y" "$GHJK_LAST_LOADER_PATH" | tr -d '\n') != "$GHJK_LAST_LOADER_TS" ]
); then
echo "got here"
init_ghjk
export LAST_PWD="$PWD"
fi
Expand Down
14 changes: 9 additions & 5 deletions install/hooks/fish.fish
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function init_ghjk
if set --query GHJK_CLEANUP
eval $GHJK_CLEANUP
if set --query GHJK_CLEANUP_FISH
eval $GHJK_CLEANUP_FISH
end
set --erase GHJK_CLEANUP
set --erase GHJK_CLEANUP_FISH
set --erase GHJK_LAST_LOADER_PATH
set --erase GHJK_LAST_LOADER_TS
set --local cur_dir $PWD
while test $cur_dir != "/"
if test -e $cur_dir/ghjk.ts
set --local envDir $HOME/.local/share/ghjk/envs/(string replace --all / . $cur_dir)
set --local envDir __GHJK_DIR__/envs/(string replace --all / . $cur_dir)
if test -d $envDir
set -g -x GHJK_LAST_LOADER_PATH $envDir/loader.fish
set -g -x GHJK_LAST_LOADER_TS (stat -c "%Y" $envDir/loader.fish | tr -d '\n')
Expand All @@ -32,14 +32,18 @@ end

function ghjk_prompt_hook --on-event fish_prompt
# only init if the loader has been modified
if set --query GHJK_LAST_LOADER_PATH; and test (stat -c "%Y" $GHJK_LAST_LOADER_PATH | tr -d '\n') != $GHJK_LAST_LOADER_TS
if test ! $ghjk_prompt_init_flag; and set --query GHJK_LAST_LOADER_PATH; and test (stat -c "%Y" $GHJK_LAST_LOADER_PATH | tr -d '\n') != $GHJK_LAST_LOADER_TS
init_ghjk
set -g ghjk_prompt_init_flag true
end
set -g ghjk_prompt_init_flag false
end

# try to detect ghjk.ts on each change of PWD
function ghjk_pwd_hook --on-variable PWD
init_ghjk
# set the flag so that the prompt hook doesn't load it again
set -g ghjk_prompt_init_flag true
end

# try loading any relevant ghjk.ts right away
Expand Down
Loading

0 comments on commit d738a72

Please sign in to comment.