Skip to content

Commit

Permalink
feat(ports): jq (#47)
Browse files Browse the repository at this point in the history
* feat(ports): `jq`

* fix: deno dir issue

* fix(ci): minor troubles

* fix(ci): typo

* fix(tests): DENO_DIR trouble

* fix(tests): missing cc

* fix(tests): disable alpine hacks
  • Loading branch information
Yohe-Am authored Apr 9, 2024
1 parent 423d38e commit f7e823e
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 71 deletions.
6 changes: 3 additions & 3 deletions .ghjk/lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"dependsOn": [],
"env": {
"installs": [
"ea4ab1dc054cb2dba8fc5c830c995c8db385cc79"
"f48ddfcfec810fcfcfc155fef7281a8c139c26fa"
],
"env": {
"STUFF": "stuffier"
Expand Down Expand Up @@ -201,7 +201,7 @@
],
"globalEnv": {
"installs": {
"ea4ab1dc054cb2dba8fc5c830c995c8db385cc79": {
"f48ddfcfec810fcfcfc155fef7281a8c139c26fa": {
"port": {
"ty": "denoWorker@v1",
"name": "protoc_ghrel",
Expand All @@ -212,7 +212,7 @@
"x86_64-darwin"
],
"version": "0.1.0",
"moduleSpecifier": "file:///ports/protoc.ts"
"moduleSpecifier": "file:///data/home/ghjk/ports/protoc.ts"
}
},
"c4cf06e095dadfbdd5e26070bc2b7baffc5ff45f": {
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ on:
workflow_dispatch:

env:
DENO_VERSION: "1.40.2"
DENO_VERSION: "1.42.1"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GHJK_LOG_PANIC_LEVEL: error
DENO_DIR: .deno-dir

jobs:
test-e2e:
runs-on: "${{ matrix.os }}"
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
Expand All @@ -37,7 +39,7 @@ jobs:
if: "${{ matrix.os == 'macos-latest' || matrix.os == 'macos-14' }}"
uses: actions/cache@v4
with:
path: ${{ env.GHJK_DENO_DIR }}
path: ${{ env.DENO_DIR }}
key: deno-mac-${{ hashFiles('**/deno.lock') }}

- if: "${{ matrix.e2eType == 'docker' }}"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ on:
- ready_for_review

env:
DENO_VERSION: "1.40.2"
DENO_VERSION: "1.42.1"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GHJK_LOG: debug
GHJK_LOG_PANIC_LEVEL: error
DENO_DIR: .deno-dir

jobs:
changes:
Expand Down Expand Up @@ -59,9 +60,8 @@ jobs:
if: "${{ matrix.os == 'macos-latest' || matrix.os == 'macos-14' }}"
uses: actions/cache@v4
with:
path: ${{ env.GHJK_DENO_DIR }}
path: ${{ env.DENO_DIR }}
key: deno-mac-${{ hashFiles('**/deno.lock') }}

- if: "${{ matrix.e2eType == 'docker' }}"
uses: docker/setup-buildx-action@v3
- if: "${{ matrix.e2eType == 'docker' }}"
Expand Down
5 changes: 4 additions & 1 deletion check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { $ } from "./utils/mod.ts";

const files = (await Array.fromAsync(
$.path(import.meta.url).parentOrThrow().expandGlob("**/*.ts", {
exclude: [],
exclude: [
".ghjk/**",
".deno-dir/**",
],
}),
)).map((ref) => ref.path.toString());

Expand Down
5 changes: 4 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
},
"fmt": {
"exclude": [
"**/*.md"
"**/*.md",
".ghjk/**",
".deno-dir/**"
]
},
"lint": {
"exclude": [
".deno-dir/**",
"ghjk.ts",
"play.ts"
],
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e -u
GHJK_VERSION="${GHJK_VERSION:-v0.1.0-alpha}"
GHJK_INSTALLER_URL="${GHJK_INSTALLER_URL:-https://raw.github.com/metatypedev/ghjk/$GHJK_VERSION/install.ts}"
GHJK_SHARE_DIR="${GHJK_SHARE_DIR:-$HOME/.local/share/ghjk}"
DENO_VERSION="${DENO_VERSION:-v1.40.2}"
DENO_VERSION="${DENO_VERSION:-v1.42.1}"

# make sure the version is prepended with v
if [ "${DENO_VERSION#"v"}" = "$DENO_VERSION" ]; then
Expand Down
1 change: 1 addition & 0 deletions port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export { GithubReleasePort } from "./modules/ports/ghrel.ts";
export { PortBase } from "./modules/ports/base.ts";
export * from "./utils/unarchive.ts";
export { default as portsValidators } from "./modules/ports/types.ts";
export { serializePlatform } from "./modules/ports/types/platform.ts";

import { std_url } from "./deps/common.ts";
import { PortBase } from "./modules/ports/base.ts";
Expand Down
83 changes: 83 additions & 0 deletions ports/jq_ghrel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import {
$,
DownloadArgs,
dwnUrlOut,
GithubReleasePort,
InstallArgs,
type InstallConfigSimple,
osXarch,
serializePlatform,
} from "../port.ts";
import { GithubReleasesInstConf, readGhVars } from "../modules/ports/ghrel.ts";

const manifest = {
ty: "denoWorker@v1" as const,
name: "jq_ghrel",
version: "0.1.0",
moduleSpecifier: import.meta.url,
platforms: [
...osXarch(
["linux", "darwin"],
["aarch64", "x86_64"],
),
serializePlatform({ os: "windows", arch: "x86_64" }),
],
};

export default function conf(
config: InstallConfigSimple & GithubReleasesInstConf = {},
) {
return {
...readGhVars(),
...config,
port: manifest,
};
}

export class Port extends GithubReleasePort {
repoOwner = "jqlang";
repoName = "jq";

downloadUrls(args: DownloadArgs) {
const { installVersion, platform } = args;

let arch;
switch (platform.arch) {
case "x86_64":
arch = "amd64";
break;
case "aarch64":
arch = "arm64";
break;
default:
throw new Error(`unsupported platform: ${serializePlatform(platform)}`);
}
const os = platform.os == "darwin" ? "macos" : platform.os;

return [
this.releaseArtifactUrl(
installVersion,
`jq-${os}-${arch}${os == "windows" ? "exe" : ""}`,
),
]
.map(dwnUrlOut)
.map((out) => ({ ...out, mode: 0o700 }));
}

async install(args: InstallArgs) {
const installPath = $.path(args.installPath);
await $.removeIfExists(installPath);

const [{ name: fileName }] = this.downloadUrls(args);
const fileDwnPath = $.path(args.downloadPath).resolve(fileName);

await fileDwnPath.copyFile(
(await installPath
.join("bin")
.ensureDir())
.join(
args.platform.os == "windows" ? "jq.exe" : "jq",
),
);
}
}
1 change: 1 addition & 0 deletions ports/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { default as curl } from "./curl.ts";
export { default as earthly } from "./earthly.ts";
export { default as git } from "./git.ts";
export { default as infisical } from "./infisical.ts";
export { default as jq_ghrel } from "./jq_ghrel.ts";
export { default as meta_cli_ghrel } from "./meta_cli_ghrel.ts";
export { default as mold } from "./mold.ts";
export { default as node } from "./node.ts";
Expand Down
39 changes: 6 additions & 33 deletions tests/ports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ type CustomE2eTestCase = Omit<E2eTestCase, "ePoints" | "tsGhjkfileStr"> & {
};
// order tests by download size to make failed runs less expensive
const cases: CustomE2eTestCase[] = [
// 2 megs
{
name: "jq",
installConf: ports.jq_ghrel(),
ePoint: `jq --version`,
},
// 3 megs
{
name: "protoc",
Expand Down Expand Up @@ -165,17 +171,6 @@ const cases: CustomE2eTestCase[] = [
components: ["rust-analyzer"],
targets: ["wasm32-unknown-unknown"],
profile: "minimal",
...(
Deno.build.os == "linux" &&
Deno.env.get("GHJK_TEST_E2E_TYPE") == "docker"
? {
// tests are run on alpine docker
host: Deno.build.arch == "x86_64"
? "x86_64-unknown-linux-musl"
: "aarch64-unknown-linux-musl",
}
: {}
),
}),
ePoint: `rustc --version`,
},
Expand All @@ -186,17 +181,6 @@ const cases: CustomE2eTestCase[] = [
crateName: "sd",
rustConfOverride: {
profile: "minimal",
...(
Deno.build.os == "linux" &&
Deno.env.get("GHJK_TEST_E2E_TYPE") == "docker"
? {
// tests are run on alpine docker
host: Deno.build.arch == "x86_64"
? "x86_64-unknown-linux-musl"
: "aarch64-unknown-linux-musl",
}
: {}
),
},
}),
ePoint: `sd --version`,
Expand All @@ -209,17 +193,6 @@ const cases: CustomE2eTestCase[] = [
profile: "dev", // force to use cargo-install
rustConfOverride: {
profile: "minimal",
...(
Deno.build.os == "linux" &&
Deno.env.get("GHJK_TEST_E2E_TYPE") == "docker"
? {
// tests are run on alpine docker
host: Deno.build.arch == "x86_64"
? "x86_64-unknown-linux-musl"
: "aarch64-unknown-linux-musl",
}
: {}
),
},
}),
ePoint: `sd --version`,
Expand Down
80 changes: 80 additions & 0 deletions tests/test-alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
ARG DENO_V=1.42.1

FROM docker.io/denoland/deno:alpine-${DENO_V}

ARG BASH_V=5.2.21-r0
ARG FISH_V=3.6.3-r0
ARG ZSH_V=5.9-r2
ARG GIT_V=2.43.0-r0
ARG CURL_V=8.5.0-r0
ARG XZ_V=5.4.5-r0
ARG GTAR_V=1.35-r2
ARG UNZIP_V=6.0-r14
ARG ZSTD_V=1.5.5-r8
ARG GCOMPAT_V=1.1.0-r4
ARG BUILD_BASE_V=0.5-r3

RUN set -eux; \
apk update; \
apk add \
# ambient deps \
zstd=$ZSTD_V \
tar=$GTAR_V \
# test deps \
bash=$BASH_V \
fish=$FISH_V \
zsh=$ZSH_V \
# asdf deps \
git=$GIT_V \
curl=$CURL_V \
xz=$XZ_V \
unzip=$UNZIP_V \
build-base=$BUILD_BASE_V \
# gcompat=$GCOMPAT_V \
ca-certificates \
;

WORKDIR /ghjk

COPY deno.lock deno.jsonc ./
COPY deps/* ./deps/
RUN deno task cache

COPY . ./

RUN ln -s ./main.ts /bin/ghjk

WORKDIR /app

ENV GHJK_LOG=debug
ENV GHJK_INSTALL_EXE_DIR=/usr/bin
ENV GHJK_INSTALL_HOOK_SHELLS=fish,bash,zsh
# share the module cache of the image
ENV GHJK_INSTALL_DENO_DIR=$DENO_DIR
RUN deno run -A /ghjk/install.ts

ARG GITHUB_TOKEN
ENV GITHUB_TOKEN=$GITHUB_TOKEN

# avoid variable expansion in the contents of the
# here-document by quoting the tag
COPY <<"EOT" /app/ghjk.ts
#{{CMD_ADD_CONFIG}}
EOT

RUN <<EOT
set -eux
cat $(which ghjk)
export CLICOLOR_FORCE=1
ghjk print config
ghjk ports sync
EOT

# activate ghjk non-interactive shells execs
ENV BASH_ENV=/root/.local/share/ghjk/env.bash
ENV ZDOTDIR=/root/.local/share/ghjk/

# BASH_ENV behavior is only avail in bash, not sh
SHELL [ "/bin/bash", "-c"]

CMD ['false']
Loading

0 comments on commit f7e823e

Please sign in to comment.