Skip to content

Commit

Permalink
feat(ci): ghjk action
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohe-Am committed Dec 5, 2023
1 parent 9dc062c commit fe0e00b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 12 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,20 @@ jobs:
env:
SKIP_LOGIN: true
- run: deno task test

test-action:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
with:
deno-version: ${{ env.DENO_VERSION }}
- uses: ./
id: ghjk-action
env:
GHJK_CONFIG: ./examples/protoc/ghjk.ts
- shell: bash
run: |
cd examples/protoc
. ${{ steps.ghjk-action.outputs.hooks-dir }}/hook.sh
protoc --version
34 changes: 34 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Setup Ghjk'
description: 'Installs ghjk and optionally syncs according to the config'
inputs:
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
default: true
outputs:
# FIXME: convert to js based action to access env var exports
# for BASH_ENV
hooks-dir:
description: "Directory where the hooks are placed"
value: ${{ steps.ghjk-dirs.outputs.share-dir }}/hooks
runs:
using: "composite"
steps:
- id: install-ghjk
shell: bash
env:
GHJK_EXE_INSTALL_DIR: /usr/bin
run: deno run -A ${{ inputs.installer-uri }}
- id: sync-ghjk
if: ${{ inputs.sync }}
run: |
ghjk ports sync
- id: ghjk-dirs
shell: bash
run: echo "share-dir=$HOME/.local/share/ghjk" >> $GITHUB_OUTPUT
4 changes: 4 additions & 0 deletions examples/protoc/ghjk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { ghjk } from "../../mod.ts";
import protoc from "../../ports/protoc.ts";

protoc({});
10 changes: 5 additions & 5 deletions ghjk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import whiz from "./ports/whiz.ts";
// cargo_insta({});
// jco({});
// mold({});
// act({});
asdf({
pluginRepo: "https://github.com/asdf-community/asdf-cmake",
installType: "version",
});
act({});
// asdf({
// pluginRepo: "https://github.com/asdf-community/asdf-cmake",
// installType: "version",
// });
// protoc({ });
// earthly({});
// ruff({});
Expand Down
5 changes: 3 additions & 2 deletions host/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import * as std_modules from "../modules/std.ts";
import * as deno from "./deno.ts";

export async function main() {
const configPath = Deno.env.get("GHJK_CONFIG") ??
const configPathIn = Deno.env.get("GHJK_CONFIG") ??
await findConfig(Deno.cwd());
if (!configPath) {
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);

logger().debug({ configPath });
Expand Down
14 changes: 10 additions & 4 deletions install/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

// TODO: support for different environments to use different versions of ghjk

import "../setup_logger.ts";
import logger from "../utils/logger.ts";
import { std_fs, std_path } from "../deps/cli.ts";
import { dirs, importRaw } from "../utils/mod.ts";
import { spawnOutput } from "../utils/mod.ts";
Expand Down Expand Up @@ -93,6 +95,7 @@ export async function install() {
throw new Error("windows is not yet supported :/");
}
const { homeDir, shareDir } = dirs();
logger().debug("installing hooks", { shareDir });
await unpackVFS(shareDir);
const shell = await detectShell();
if (shell === "fish") {
Expand All @@ -116,7 +119,7 @@ export async function install() {
} else {
throw new Error(`unsupported shell: ${shell}`);
}
const skipBinInstall = Deno.env.get("GHJK_SKIP_BIN_INSTALL");
const skipBinInstall = Deno.env.get("GHJK_SKIP_EXE_INSTALL");
if (!skipBinInstall && skipBinInstall != "0" && skipBinInstall != "false") {
switch (Deno.build.os) {
case "linux":
Expand All @@ -125,11 +128,13 @@ export async function install() {
case "illumos":
case "darwin": {
// TODO: respect xdg dirs
const binDir = Deno.env.get("GHJK_BIN_INSTALL_PATH") ??
const exeDir = Deno.env.get("GHJK_EXE_INSTALL_DIR") ??
std_path.resolve(homeDir, ".local", "bin");
await std_fs.ensureDir(binDir);
await std_fs.ensureDir(exeDir);
const exePath = std_path.resolve(exeDir, `ghjk`);
logger().debug("installing executable", { exePath });
await Deno.writeTextFile(
std_path.resolve(binDir, `ghjk`),
exePath,
`#!/bin/sh
deno run --unstable-worker-options -A ${import.meta.resolve("../main.ts")} $*`,
{ mode: 0o700 },
Expand All @@ -140,4 +145,5 @@ deno run --unstable-worker-options -A ${import.meta.resolve("../main.ts")} $*`,
throw new Error(`${Deno.build.os} is not yet supported`);
}
}
logger().info("install success");
}
2 changes: 1 addition & 1 deletion tests/test.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RUN ln -s ./main.ts /bin/ghjk

WORKDIR /app

ENV GHJK_BIN_INSTALL_PATH=/usr/bin
ENV GHJK_EXE_INSTALL_DIR=/usr/bin
# explicitly set the shell var as detection fails otherwise
# because ps program is not present in this image
RUN SHELL=/bin/bash deno run -A /ghjk/install.ts
Expand Down

0 comments on commit fe0e00b

Please sign in to comment.