From e4509ef4093daa006723ba0610e2e15123bea33f Mon Sep 17 00:00:00 2001 From: Max Howell Date: Wed, 17 Aug 2022 08:22:22 -0400 Subject: [PATCH] various fixes (#80) --- README.md | 6 +++++ scripts/bottle.ts | 4 +++ scripts/build.ts | 6 ++--- scripts/ls.ts | 64 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/sort.ts | 14 +++++++---- scripts/test.ts | 12 ++++++--- scripts/upload.ts | 5 +++- 7 files changed, 97 insertions(+), 14 deletions(-) create mode 100755 scripts/ls.ts diff --git a/README.md b/README.md index fcb461e3..5934b77e 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,9 @@ knowledge. Please keep it tidy. |-------------|---------| | deno.land | ^1.18 | | tea.xyz | ^0 | + +## Build All + +```sh +scripts/ls.ts | xargs scripts/sort.ts | xargs scripts/build.ts +``` diff --git a/scripts/bottle.ts b/scripts/bottle.ts index 384e3d62..a038c137 100755 --- a/scripts/bottle.ts +++ b/scripts/bottle.ts @@ -6,6 +6,7 @@ args: - run - --allow-net - --allow-run + - --allow-env - --allow-read=/opt/ - --allow-write=/opt/ - --import-map={{ srcroot }}/import-map.json @@ -16,6 +17,9 @@ import { Path } from "types" import useCellar from "hooks/useCellar.ts" import { run } from "utils" import useCache from "hooks/useCache.ts" +import useFlags from "hooks/useFlags.ts" + +useFlags() const cellar = useCellar() const filesListName = 'files.txt' diff --git a/scripts/build.ts b/scripts/build.ts index ae723cdb..10bedecd 100755 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -24,11 +24,9 @@ import { parsePackageRequirement } from "types" import hydrate from "prefab/hydrate.ts" import resolve from "prefab/resolve.ts" import { get_build_deps } from "./_lib.ts" +import useFlags from "hooks/useFlags.ts" -// -import { print } from "utils" -print("this because otherwise console.verbose is not defined lol") -// +useFlags() const pantry = usePantry() const cellar = useCellar() diff --git a/scripts/ls.ts b/scripts/ls.ts new file mode 100755 index 00000000..acb14def --- /dev/null +++ b/scripts/ls.ts @@ -0,0 +1,64 @@ +#!/usr/bin/env -S tea -E + +// returns all pantry entries as `[{ name, path }]` + +/*--- +args: + - deno + - run + - --allow-env + - --allow-read=/opt/tea.xyz/var/pantry + - --import-map={{ srcroot }}/import-map.json +---*/ + +import { Path } from "types" +import useFlags from "hooks/useFlags.ts" + +const flags = useFlags() + + +const prefix = new Path('/opt/tea.xyz/var/pantry/projects') + +//FIXME unfortunately importing executes the script below +export async function* ls(): AsyncGenerator { + for await (const path of _ls_pantry(prefix)) { + yield { + name: path.parent().relative({ to: prefix }), + path: path.string + } + } +} + +async function* _ls_pantry(dir: Path): AsyncGenerator { + if (!dir.isDirectory()) throw new Error() + + for await (const [path, { name, isDirectory }] of dir.ls()) { + if (isDirectory) { + for await (const x of _ls_pantry(path)) { + yield x + } + } else if (name === "package.yml") { + yield path + } + } +} + +interface Entry { + name: string + path: string +} + +const rv: Entry[] = [] +for await (const item of ls()) { + rv.push(item) +} + +if (Deno.env.get("GITHUB_ACTIONS")) { + const projects = rv.map(x => x.name).join(":") + console.log(`::set-output name=projects::${projects}`) +} else if (flags.json) { + const output = JSON.stringify(rv, null, 2) + console.log(output) +} else { + console.log(rv.map(x => x.name).join("\n")) +} diff --git a/scripts/sort.ts b/scripts/sort.ts index 4e381c5b..5dbdaa9b 100755 --- a/scripts/sort.ts +++ b/scripts/sort.ts @@ -15,11 +15,9 @@ args: import { parsePackageRequirement } from "types" import hydrate from "prefab/hydrate.ts" import { get_build_deps } from "./_lib.ts" +import useFlags from "hooks/useFlags.ts" -// -import { print } from "utils" -print("this because otherwise console.verbose is not defined lol") -// +const flags = useFlags() const dry = Deno.args.map(project => { const match = project.match(/projects\/(.*)\/package.yml/) @@ -31,4 +29,10 @@ const wet = await hydrate(dry, get_build_deps(set)) const gas = wet.map(x => x.project) .filter(x => set.has(x)) // we're only sorting `dry` so reject the rest -console.log(`::set-output name=pkgs::${gas.join(" ")}`) +if (Deno.env.get("GITHUB_ACTIONS")) { + console.log(`::set-output name=pkgs::${gas.join(" ")}`) +} else if (flags.json) { + console.log(gas) +} else { + console.log(gas.join("\n")) +} diff --git a/scripts/test.ts b/scripts/test.ts index 0c5bb475..38e43230 100755 --- a/scripts/test.ts +++ b/scripts/test.ts @@ -17,6 +17,9 @@ import usePantry from "hooks/usePantry.ts" import useShellEnv, { expand } from "hooks/useShellEnv.ts" import { run, undent, isPlainObject } from "utils" import { validatePackageRequirement } from "utils/lvl2.ts" +import useFlags from "hooks/useFlags.ts" + +useFlags() //TODO install any other deps @@ -69,10 +72,11 @@ function get_deps() { return rv function attempt(obj: PlainObject) { - if (isPlainObject(obj)) - for (const [project, constraint] of Object.entries(obj)) { - const pkg = validatePackageRequirement({ project, constraint }) - if (pkg) rv.push(pkg) + if (isPlainObject(obj)) { + for (const [project, constraint] of Object.entries(obj)) { + const pkg = validatePackageRequirement({ project, constraint }) + if (pkg) rv.push(pkg) + } } } } diff --git a/scripts/upload.ts b/scripts/upload.ts index 6a63c705..be7bd902 100755 --- a/scripts/upload.ts +++ b/scripts/upload.ts @@ -6,7 +6,7 @@ args: - run - --allow-net - --allow-read=/opt - - --allow-env=AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_S3 + - --allow-env - --import-map={{ srcroot }}/import-map.json ---*/ @@ -16,6 +16,9 @@ import useCache from "hooks/useCache.ts" import useCellar from "hooks/useCellar.ts" import { encodeToString } from "encodeToString" import { Package, parsePackageRequirement, SemVer, semver } from "types" +import useFlags from "hooks/useFlags.ts" + +useFlags() if (Deno.args.length === 0) throw new Error("no args supplied")