Skip to content

Commit

Permalink
test: check if installed command is really executable
Browse files Browse the repository at this point in the history
  • Loading branch information
suin committed Jun 20, 2024
1 parent 3deb83c commit 2cc1c25
Show file tree
Hide file tree
Showing 34 changed files with 3,269 additions and 60 deletions.
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "Ubuntu",
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"runArgs": ["--platform=linux/amd64"],
"workspaceFolder": "/workspace",
"remoteEnv": {
"PATH": "/root/.proto/shims:/root/.proto/bin:${containerEnv:PATH}"
Expand Down
2 changes: 2 additions & 0 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

curl -fsSL https://moonrepo.dev/install/proto.sh | PROTO_HOME=/usr/local bash -s -- --yes
cd /workspace
proto use
15 changes: 9 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@ jobs:
config:
- os: macos-12
target: x86_64-apple-darwin
- os: macos-14
- os: macos-latest
target: aarch64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: ubuntu-20.04
- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu

steps:
- uses: actions/checkout@v4
- name: Install
uses: moonrepo/setup-toolchain@v0
with:
fetch-depth: 0
- uses: moonrepo/setup-toolchain@v0
env:
PROTO_LOG: debug
with:
auto-install: true
cache: false
- run: bun install --frozen-lockfile
- run: bun test
- run: yarn install --immutable
- run: moon ci --color -c 1
- uses: appthrust/moon-ci-retrospect@v0
if: success() || failure()
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,7 @@ dist

# Finder (MacOS) folder config
.DS_Store

# moon
.moon/cache
.moon/docker
8 changes: 8 additions & 0 deletions .moon/tasks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$schema: https://moonrepo.dev/schemas/tasks.json

tasks:
test:
command: vitest --run --pool=forks --passWithNoTests
inputs:
- "**/*.ts"
platform: node
40 changes: 40 additions & 0 deletions .moon/toolchain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# https://moonrepo.dev/docs/config/toolchain
$schema: https://moonrepo.dev/schemas/toolchain.json

node:
# The version to use. Must be a semantic version that includes major, minor, and patch.
# We suggest using the latest active LTS version: https://nodejs.org/en/about/releases
# version: '20.0.0'

# The package manager to use when managing dependencies.
# Accepts "npm" (default), "pnpm", "yarn", or "bun".
packageManager: yarn

# The version of the package manager (above) to use.
yarn:
version: 4.2.2
installArgs:
- --immutable

# Add `node.version` as a constraint in the root `package.json` `engines`.
addEnginesConstraint: true

# Dedupe dependencies after the lockfile has changed.
dedupeOnLockfileChange: true

# Version format to use when syncing dependencies within the project's `package.json`.
# dependencyVersionFormat: 'workspace'

# Infer and automatically create moon tasks from `package.json` scripts, per project.
# BEWARE: Tasks and scripts are not 1:1 in functionality, so please refer to the documentation.
inferTasksFromScripts: false

# Support the "one version policy" by only declaring dependencies in the root `package.json`.
# rootPackageOnly: true

# Sync a project's relationships as `dependencies` within the project's `package.json`.
syncProjectWorkspaceDependencies: true

# Sync `node.version` to a 3rd-party version manager's config file.
# Accepts "nodenv" (.node-version), "nvm" (.nvmrc), or none.
# syncVersionManagerConfig: 'nvm'
9 changes: 9 additions & 0 deletions .moon/workspace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$schema: https://moonrepo.dev/schemas/workspace.json

projects:
- "*"
- "!.*"

vcs:
manager: git
defaultBranch: main
6 changes: 5 additions & 1 deletion .prototools
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
bun = "1.1.15"
moon = "1.25.6"
node = "22.3.0"

[plugins]
moon = "https://raw.githubusercontent.com/moonrepo/moon/master/proto-plugin.toml"
894 changes: 894 additions & 0 deletions .yarn/releases/yarn-4.2.2.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
yarnPath: .yarn/releases/yarn-4.2.2.cjs

nodeLinker: node-modules
8 changes: 8 additions & 0 deletions argo/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "argo",
afterInstall: async ($) => {
await $`argo version`;
},
});
8 changes: 8 additions & 0 deletions argocd/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "argocd",
afterInstall: async ($) => {
await $`argocd version --client`;
},
});
8 changes: 8 additions & 0 deletions black/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "black",
afterInstall: async ($) => {
await $`black --version`;
},
});
Binary file removed bun.lockb
Binary file not shown.
8 changes: 8 additions & 0 deletions cue/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "cue",
afterInstall: async ($) => {
await $`cue version`;
},
});
8 changes: 8 additions & 0 deletions fzf/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "fzf",
afterInstall: async ($) => {
await $`fzf --version`;
},
});
8 changes: 8 additions & 0 deletions gh/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "gh",
afterInstall: async ($) => {
await $`gh --version`;
},
});
21 changes: 0 additions & 21 deletions install.test.ts

This file was deleted.

8 changes: 8 additions & 0 deletions jnv/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "jnv",
afterInstall: async ($) => {
await $`jnv --version`;
},
});
8 changes: 8 additions & 0 deletions jq/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "jq",
afterInstall: async ($) => {
await $`jq --version`;
},
});
8 changes: 8 additions & 0 deletions k3d/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "k3d",
afterInstall: async ($) => {
await $`k3d --version`;
},
});
8 changes: 8 additions & 0 deletions k6/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "k6",
afterInstall: async ($) => {
await $`k6 --version`;
},
});
8 changes: 8 additions & 0 deletions k9s/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "k9s",
afterInstall: async ($) => {
await $`k9s version`;
},
});
8 changes: 8 additions & 0 deletions mise/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "mise",
afterInstall: async ($) => {
await $`mise --version`;
},
});
30 changes: 21 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
{
"name": "proto-toml-plugin",
"type": "module",
"devDependencies": {
"@biomejs/biome": "^1.8.1",
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
"name": "proto-toml-plugin",
"type": "module",
"devDependencies": {
"@biomejs/biome": "^1.8.1",
"@tsconfig/node22": "^22.0.0",
"@tsconfig/strictest": "^2.0.5",
"@types/node": "^20.14.6",
"typescript": "^5.4.5",
"vitest": "^1.6.0"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"packageManager": "[email protected]",
"engines": {
"node": "22.3.0"
},
"dependencies": {
"toml": "^3.0.0",
"zx": "^8.1.3"
}
}
8 changes: 8 additions & 0 deletions rye/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "rye",
afterInstall: async ($) => {
await $`rye --version`;
},
});
8 changes: 8 additions & 0 deletions sccache/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "sccache",
afterInstall: async ($) => {
await $`sccache --version`;
},
});
8 changes: 8 additions & 0 deletions stern/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "stern",
afterInstall: async ($) => {
await $`stern --version`;
},
});
51 changes: 51 additions & 0 deletions testkit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// biome-ignore lint/nursery/noRestrictedImports: <explanation>
import { readFileSync } from "node:fs";
import { mkdtemp } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join as pathJoin } from "node:path";
import toml from "toml";
import { test } from "vitest";
import { $ as $$, type Shell, cd } from "zx/core";

export function run({
name,
afterInstall,
}: {
name: string;
afterInstall?: ($: Shell) => Promise<void>;
}) {
const tomlPath = pathJoin(import.meta.dirname, name, "plugin.toml");
const content = readFileSync(tomlPath, { encoding: "utf-8" });
const data = toml.parse(content) as Plugin;
const platform = getPlatform();
const supportPlatforms = Object.keys(data.platform);
const skip = !supportPlatforms.includes(platform);
console.log(`[${name}] supports: [${supportPlatforms}], current: ${platform}, skip: ${skip}`);
const $ = $$({ verbose: true });

test.skipIf(skip)(`proto install ${name}`, { timeout: Number.POSITIVE_INFINITY }, async () => {
const dir = await mkdtemp(`${tmpdir()}/proto-plugin-test-${name}`);
cd(dir);
await $`pwd`;
await $`proto plugin add ${name} source:${tomlPath}`;
await $`proto install ${name} latest`;
if (afterInstall) {
await afterInstall($);
}
});
}

type Plugin = {
name: string;
platform: Partial<Record<"linux" | "macos" | "windows", object>>;
};

function getPlatform(): "linux" | "macos" | "windows" | "unknown" {
return process.platform === "linux"
? "linux"
: process.platform === "darwin"
? "macos"
: process.platform === "win32"
? "windows"
: "unknown";
}
8 changes: 8 additions & 0 deletions tilt/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { run } from "../testkit.js";

run({
name: "tilt",
afterInstall: async ($) => {
await $`tilt version`;
},
});
Loading

0 comments on commit 2cc1c25

Please sign in to comment.