From f7e823ec3009f832ed72bfa940513cec599548d5 Mon Sep 17 00:00:00 2001 From: Yohe-Am <56622350+Yohe-Am@users.noreply.github.com> Date: Tue, 9 Apr 2024 22:11:16 +0300 Subject: [PATCH] feat(ports): `jq` (#47) * 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 --- .ghjk/lock.json | 6 +-- .github/workflows/nightly.yml | 6 ++- .github/workflows/tests.yml | 6 +-- check.ts | 5 ++- deno.jsonc | 5 ++- install.sh | 2 +- port.ts | 1 + ports/jq_ghrel.ts | 83 +++++++++++++++++++++++++++++++++++ ports/mod.ts | 1 + tests/ports.ts | 39 +++------------- tests/test-alpine.Dockerfile | 80 +++++++++++++++++++++++++++++++++ tests/test.Dockerfile | 49 ++++++++++----------- 12 files changed, 212 insertions(+), 71 deletions(-) create mode 100644 ports/jq_ghrel.ts create mode 100644 tests/test-alpine.Dockerfile diff --git a/.ghjk/lock.json b/.ghjk/lock.json index 0696b3ee..09ac08a0 100644 --- a/.ghjk/lock.json +++ b/.ghjk/lock.json @@ -131,7 +131,7 @@ "dependsOn": [], "env": { "installs": [ - "ea4ab1dc054cb2dba8fc5c830c995c8db385cc79" + "f48ddfcfec810fcfcfc155fef7281a8c139c26fa" ], "env": { "STUFF": "stuffier" @@ -201,7 +201,7 @@ ], "globalEnv": { "installs": { - "ea4ab1dc054cb2dba8fc5c830c995c8db385cc79": { + "f48ddfcfec810fcfcfc155fef7281a8c139c26fa": { "port": { "ty": "denoWorker@v1", "name": "protoc_ghrel", @@ -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": { diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 6e7f10df..f26d0499 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -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 @@ -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' }}" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6c4ad343..ceab6301 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: @@ -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' }}" diff --git a/check.ts b/check.ts index 73e91f7b..e2341541 100755 --- a/check.ts +++ b/check.ts @@ -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()); diff --git a/deno.jsonc b/deno.jsonc index b6014943..801f17cc 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -6,11 +6,14 @@ }, "fmt": { "exclude": [ - "**/*.md" + "**/*.md", + ".ghjk/**", + ".deno-dir/**" ] }, "lint": { "exclude": [ + ".deno-dir/**", "ghjk.ts", "play.ts" ], diff --git a/install.sh b/install.sh index a94be871..d10d6aca 100755 --- a/install.sh +++ b/install.sh @@ -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 diff --git a/port.ts b/port.ts index f24196f3..34214ea7 100644 --- a/port.ts +++ b/port.ts @@ -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"; diff --git a/ports/jq_ghrel.ts b/ports/jq_ghrel.ts new file mode 100644 index 00000000..c608dfb1 --- /dev/null +++ b/ports/jq_ghrel.ts @@ -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", + ), + ); + } +} diff --git a/ports/mod.ts b/ports/mod.ts index 280aeff7..25be49d5 100644 --- a/ports/mod.ts +++ b/ports/mod.ts @@ -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"; diff --git a/tests/ports.ts b/tests/ports.ts index 95004621..34489a9c 100644 --- a/tests/ports.ts +++ b/tests/ports.ts @@ -21,6 +21,12 @@ type CustomE2eTestCase = Omit & { }; // 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", @@ -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`, }, @@ -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`, @@ -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`, diff --git a/tests/test-alpine.Dockerfile b/tests/test-alpine.Dockerfile new file mode 100644 index 00000000..b1626ce8 --- /dev/null +++ b/tests/test-alpine.Dockerfile @@ -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 <