Skip to content

Commit

Permalink
Merge branch 'main' into center
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
zifeo committed Oct 27, 2024
2 parents 341c29d + 4c1295f commit 1db649e
Show file tree
Hide file tree
Showing 26 changed files with 344 additions and 53 deletions.
24 changes: 15 additions & 9 deletions .ghjk/lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
"ports": {
"version": "0",
"configResolutions": {
"bciqay4m4kmzfduj5t2clgejxgpe5zwper6lyyaxt7rhbjalaqd32nhq": {
"version": "2.34.1",
"buildDepConfigs": {},
"portRef": "[email protected]",
"specifiedVersion": false
},
"bciqjlw6cxddajjmznoemlmnu7mgbbm7a3hfmnd2x5oivwajmiqui5ey": {
"version": "v0.2.63",
"version": "v0.2.64",
"buildDepConfigs": {},
"portRef": "[email protected]",
"specifiedVersion": false
Expand All @@ -15,16 +21,16 @@
"version": "3.7.1",
"buildDepConfigs": {
"cpy_bs_ghrel": {
"version": "3.12.3",
"version": "3.12.4",
"buildDepConfigs": {
"tar_aa": {
"version": "1.35",
"version": "1.34",
"buildDepConfigs": {},
"portRef": "[email protected]",
"specifiedVersion": false
},
"zstd_aa": {
"version": "v1.5.6,",
"version": "v1.4.8,",
"buildDepConfigs": {},
"portRef": "[email protected]",
"specifiedVersion": false
Expand All @@ -39,16 +45,16 @@
"specifiedVersion": false
},
"bciqij3g6mmbjn4a6ps4eipcy2fmw2zumgv5a3gbxycthroffihwquoi": {
"version": "3.12.3",
"version": "3.12.4",
"buildDepConfigs": {
"tar_aa": {
"version": "1.35",
"version": "1.34",
"buildDepConfigs": {},
"portRef": "[email protected]",
"specifiedVersion": false
},
"zstd_aa": {
"version": "v1.5.6,",
"version": "v1.4.8,",
"buildDepConfigs": {},
"portRef": "[email protected]",
"specifiedVersion": false
Expand All @@ -58,13 +64,13 @@
"specifiedVersion": false
},
"bciqj4p5hoqweghbuvz52rupja7sqze34z63dd62nz632c5zxikv6ezy": {
"version": "1.35",
"version": "1.34",
"buildDepConfigs": {},
"portRef": "[email protected]",
"specifiedVersion": false
},
"bciqe6fwheayositrdk7rkr2ngdr4wizldakex23tgivss7w6z7g3q3y": {
"version": "v1.5.6,",
"version": "v1.4.8,",
"buildDepConfigs": {},
"portRef": "[email protected]",
"specifiedVersion": false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/autoupdate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: browniebroke/pre-commit-autoupdate-action@main
- uses: peter-evans/create-pull-request@v6
- uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update/pre-commit-hooks
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ jobs:
env:
GHJKFILE: ./examples/protoc/ghjk.ts
- run: |
cd examples/protoc
cd examples/tasks
. $(ghjk print share-dir-path)/env.sh
protoc --version
ghjk x hey
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@
play.*
examples/**/.ghjk
.dev

deps/https
node_analysis_*
v8_code_cache_*
dep_analysis_*
gen
npm
deno.land
jsr.io
esm.sh
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ ghjk was designed to be an intermediate alternative between [Earthly](https://gi

```bash
# stable
curl -fsSL https://raw.githubusercontent.com/metatypedev/ghjk/0.2.0/install.sh | bash
curl -fsSL https://raw.githubusercontent.com/metatypedev/ghjk/v0.2.1/install.sh | bash
# latest (main)
curl -fsSL https://raw.githubusercontent.com/metatypedev/ghjk/0.2.0/install.sh | GHJK_VERSION=main bash/fish/zsh
curl -fsSL https://raw.githubusercontent.com/metatypedev/ghjk/v0.2.1/install.sh | GHJK_VERSION=main bash/fish/zsh
```

In your project, create a configuration file called `ghjk.ts` that look something like:
Expand All @@ -41,7 +41,7 @@ In your project, create a configuration file called `ghjk.ts` that look somethin
// NOTE: All the calls in your `ghjk.ts` file are ultimately modifying the 'sophon' proxy
// object exported here.
// WARN: always import `hack.ts` file first
export { sophon } from "https://raw.githubusercontent.com/metatypedev/ghjk/0.2.0/hack.ts";
export { sophon } from "https://raw.githubusercontent.com/metatypedev/ghjk/v0.2.1/hack.ts";
import {
install,
task,
Expand Down Expand Up @@ -70,9 +70,9 @@ Ghjk is primarily configured through constructs called "environments" or "envs"
They serve as recipes for making (mostly) reproducable posix shells.

```ts
export { sophon } from "https://raw.githubusercontent.com/metatypedev/ghjk/0.2.0/hack.ts";
import * as ghjk from "https://raw.githubusercontent.com/metatypedev/ghjk/0.2.0/hack.ts";
import * as ports from "https://raw.githubusercontent.com/metatypedev/ghjk/0.2.0/ports/mod.ts";
export { sophon } from "https://raw.githubusercontent.com/metatypedev/ghjk/v0.2.1/hack.ts";
import * as ghjk from "https://raw.githubusercontent.com/metatypedev/ghjk/v0.2.1/hack.ts";
import * as ports from "https://raw.githubusercontent.com/metatypedev/ghjk/v0.2.1/ports/mod.ts";

// top level `install`s go to the `main` env
ghjk.install(ports.protoc());
Expand Down
1 change: 1 addition & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"tasks": {
"test": "deno test --parallel --unstable-worker-options --unstable-kv -A tests/*",
"self": "deno run -A --unstable-kv --unstable-worker-options main.ts ",
"cache": "deno cache deps/*",
"check": "deno run -A ./scripts/check.ts",
"dev": "deno run -A ./scripts/dev.ts"
Expand Down
2 changes: 2 additions & 0 deletions deno.lock

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

21 changes: 21 additions & 0 deletions examples/env_vars/ghjk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { file } from "../../hack.ts";

const ghjk = file({
defaultEnv: "empty",
envs: [{ name: "empty", inherit: false }],
defaultBaseEnv: "empty",
allowedBuildDeps: [],
installs: [],
stdDeps: true,
enableRuntimes: true,
tasks: {},
});

export const sophon = ghjk.sophon;
const { env, task } = ghjk;

env("main")
.var("A", "A#STATIC")
.var("C", ($) => $`echo C [$A, $B]`.text())
.var("B", () => "B#DYNAMIC")
.onEnter(task(($) => $`echo enter $A, $B, $C`));
66 changes: 56 additions & 10 deletions files/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ import * as std_modules from "../modules/std.ts";
import type { ExecTaskArgs } from "../modules/tasks/deno.ts";
import { TaskDefHashed, TasksModuleConfig } from "../modules/tasks/types.ts";
// envs
import type {
EnvRecipe,
EnvsModuleConfig,
Provision,
WellKnownProvision,
import {
type EnvRecipe,
type EnvsModuleConfig,
type Provision,
type WellKnownProvision,
} from "../modules/envs/types.ts";
import envsValidators from "../modules/envs/types.ts";
import modulesValidators from "../modules/types.ts";

const validators = {
Expand Down Expand Up @@ -100,7 +101,7 @@ export type TaskDefArgs = {
desc?: string;
dependsOn?: string | string[];
workingDir?: string | Path;
vars?: Record<string, string | number>;
vars?: Record<string, string | number>; // TODO: add DynEnvValue?
allowedBuildDeps?: (InstallConfigFat | AllowedPortDep)[];
installs?: InstallConfigFat | InstallConfigFat[];
inherit?: EnvParent;
Expand Down Expand Up @@ -305,7 +306,7 @@ export class Ghjkfile {
workingDir,
`<task:${task.name ?? key}>`,
);
await task.fn(custom$, {
return await task.fn(custom$, {
argv,
env: Object.freeze(envVars),
$: custom$,
Expand Down Expand Up @@ -653,6 +654,15 @@ export class Ghjkfile {
const prov: WellKnownProvision = { ty: "posix.envVar", key, val };
return prov;
}),
...Object.entries(final.dynVars).map((
[key, val],
) => {
const prov = { ty: "posix.envVarDyn", key, taskKey: val };
return unwrapZodRes(
envsValidators.envVarDynProvision.safeParse(prov),
prov,
);
}),
// env hooks
...hooks,
],
Expand Down Expand Up @@ -886,6 +896,7 @@ type EnvFinalizer = () => {
installSetId: string;
inherit: string | string[] | boolean;
vars: Record<string, string>;
dynVars: Record<string, string>;
desc?: string;
onEnterHookTasks: string[];
onExitHookTasks: string[];
Expand All @@ -894,6 +905,12 @@ type EnvFinalizer = () => {
export type EnvDefArgsPartial =
& { name?: string }
& Omit<EnvDefArgs, "name">;

export type DynEnvValue =
| (() => string | number)
| (($_: typeof $) => string | number)
| (($_: typeof $) => Promise<string | number>);

//
// /**
// * A version of {@link EnvDefArgs} that has all container
Expand Down Expand Up @@ -938,6 +955,7 @@ export class EnvBuilder {
#file: Ghjkfile;
#inherit: string | string[] | boolean = true;
#vars: Record<string, string | number> = {};
#dynVars: Record<string, string> = {};
#desc?: string;
#onEnterHookTasks: string[] = [];
#onExitHookTasks: string[] = [];
Expand All @@ -958,6 +976,7 @@ export class EnvBuilder {
vars: Object.fromEntries(
Object.entries(this.#vars).map(([key, val]) => [key, val.toString()]),
),
dynVars: this.#dynVars,
desc: this.#desc,
onExitHookTasks: this.#onExitHookTasks,
onEnterHookTasks: this.#onEnterHookTasks,
Expand Down Expand Up @@ -991,18 +1010,45 @@ export class EnvBuilder {
/**
* Add an environment variable.
*/
var(key: string, val: string) {
var(key: string, val: string | DynEnvValue) {
this.vars({ [key]: val });
return this;
}

/**
* Add multiple environment variable.
*/
vars(envVars: Record<string, string | number>) {
vars(envVars: Record<string, string | number | DynEnvValue>) {
const vars = {}, dynVars = {};
for (const [k, v] of Object.entries(envVars)) {
switch (typeof v) {
case "string":
case "number":
Object.assign(vars, { [k]: v });
break;
case "function": {
const taskKey = this.#file.addTask({
ty: "denoFile@v1",
fn: v,
nonce: k,
});
Object.assign(dynVars, { [k]: taskKey });
break;
}
default:
throw new Error(
`environment value of type "${typeof v}" is not supported`,
);
}
}

Object.assign(
this.#vars,
unwrapZodRes(validators.envVars.safeParse(envVars), { envVars }),
unwrapZodRes(validators.envVars.safeParse(vars), { envVars: vars }),
);
Object.assign(
this.#dynVars,
dynVars,
);
return this;
}
Expand Down
4 changes: 2 additions & 2 deletions ghjk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ install(
task(
"lock-sed",
async ($) => {
const GHJK_VERSION = "0.2.0";
const GHJK_VERSION = "0.2.1";
await sedLock(
$.path(import.meta.dirname!),
{
Expand All @@ -41,7 +41,7 @@ task(
],
"./README.md": [
[
/(.*\/metatypedev\/ghjk\/)[^/]*(\/.*)/,
/(.*\/metatypedev\/ghjk\/v)[^/]*(\/.*)/,
GHJK_VERSION,
],
],
Expand Down
2 changes: 1 addition & 1 deletion host/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type HostCtx = {
lockedFlagSet: boolean;
};

const GHJK_VERSION = "0.2.0";
const GHJK_VERSION = "0.2.1";

export async function cli(args: CliArgs) {
logger().debug(`ghjk CLI`, GHJK_VERSION);
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e -u

GHJK_VERSION="${GHJK_VERSION:-v0.2.0}"
GHJK_VERSION="${GHJK_VERSION:-v0.2.1}"
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.44.2}"
Expand Down
3 changes: 2 additions & 1 deletion modules/envs/posix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export async function cookPosixEnv(
case "posix.headerFile":
includePaths.push(wellKnownProv.absolutePath);
break;
// case "posix.envVarDyn":
case "posix.envVar":
if (vars[wellKnownProv.key]) {
throw new Error(
Expand All @@ -84,7 +85,7 @@ export async function cookPosixEnv(
break;
default:
throw Error(
`unsupported provision type: ${(wellKnownProv as any).provision}`,
`unsupported provision type: ${(wellKnownProv as any).ty}`,
);
}
}));
Expand Down
Loading

0 comments on commit 1db649e

Please sign in to comment.