pantry/scripts/build.ts

55 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-08-01 22:43:40 +03:00
#!/usr/bin/env -S tea -E
/*---
args:
- deno
- run
- --allow-net
- --allow-run
2022-09-08 23:40:35 +03:00
- --allow-read
2022-09-09 16:37:26 +03:00
- --allow-write={{tea.prefix}}
2022-08-01 22:43:40 +03:00
- --allow-env
- --import-map={{ srcroot }}/import-map.json
---*/
2022-09-20 14:53:40 +03:00
import { usePantry } from "hooks"
2022-09-28 18:14:46 +03:00
import { Installation, Package } from "types"
2022-09-21 10:46:24 +03:00
import { pkg as pkgutils } from "utils"
2022-09-20 18:29:21 +03:00
import { useFlags, usePrefix } from "hooks"
2022-09-28 18:14:46 +03:00
import { set_output } from "./utils/gha.ts"
import build from "./build/build.ts"
2022-08-10 21:58:22 +03:00
2022-08-17 15:22:22 +03:00
useFlags()
2022-08-01 22:43:40 +03:00
const pantry = usePantry()
2022-09-21 10:46:24 +03:00
const dry = Deno.args.map(pkgutils.parse)
2022-09-08 23:40:35 +03:00
const gha = !!Deno.env.get("GITHUB_ACTIONS")
2022-09-13 18:05:04 +03:00
const group_it = gha && dry.length > 1
2022-09-28 18:14:46 +03:00
const rv: Installation[] = []
2022-09-20 18:29:21 +03:00
if (usePrefix().string != "/opt") {
console.error({ TEA_PREFIX: usePrefix().string })
throw new Error("builds must be performed in /opt (try TEA_PREFIX=/opt)")
}
2022-09-21 10:46:24 +03:00
for (const rq of dry) {
const pkg = await pantry.resolve(rq)
2022-08-01 22:43:40 +03:00
2022-09-13 18:05:04 +03:00
if (group_it) {
2022-09-21 10:46:24 +03:00
console.log("::group::", pkgutils.str(pkg))
2022-09-08 23:40:35 +03:00
} else {
2022-09-21 10:46:24 +03:00
console.log({ building: pkg.project })
2022-09-08 23:40:35 +03:00
}
2022-08-01 22:43:40 +03:00
2022-09-28 18:14:46 +03:00
const install = await build(pkg)
rv.push(install)
2022-09-08 23:40:35 +03:00
2022-09-13 18:05:04 +03:00
if (group_it) {
2022-09-08 23:40:35 +03:00
console.log("::endgroup::")
}
2022-08-01 22:43:40 +03:00
}
2022-09-01 20:49:14 +03:00
2022-09-28 18:14:46 +03:00
await set_output("pkgs", rv.map(x => pkgutils.str(x.pkg)))
await set_output("paths", rv.map(x => x.path), '%0A')
2022-09-29 19:07:07 +03:00
await set_output("relative-paths", rv.map(x => x.path.relative({ to: usePrefix() })))