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
|
|
|
|
---*/
|
|
|
|
|
|
|
|
import usePantry from "hooks/usePantry.ts"
|
2022-09-19 16:32:27 +03:00
|
|
|
import build from "./build/build.ts"
|
2022-09-01 20:49:14 +03:00
|
|
|
import { Package, parsePackageRequirement, semver } from "types"
|
2022-08-17 15:22:22 +03:00
|
|
|
import useFlags from "hooks/useFlags.ts"
|
2022-09-19 16:32:27 +03:00
|
|
|
import useCellar from "hooks/useCellar.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()
|
|
|
|
const cellar = useCellar()
|
2022-09-02 17:51:31 +03:00
|
|
|
const dry = Deno.args.map(parsePackageRequirement)
|
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-08-01 22:43:40 +03:00
|
|
|
const rv: Package[] = []
|
2022-09-19 16:32:27 +03:00
|
|
|
|
|
|
|
if (cellar.prefix.string != "/opt") {
|
|
|
|
console.error({ TEA_PREFIX: cellar.prefix.string })
|
|
|
|
throw new Error("builds must be performed in /opt (try TEA_PREFIX=/opt)")
|
|
|
|
}
|
|
|
|
|
2022-09-01 20:49:14 +03:00
|
|
|
for (const pkgrq of dry) {
|
|
|
|
const versions = await pantry.getVersions(pkgrq)
|
|
|
|
const version = semver.maxSatisfying(versions, pkgrq.constraint)
|
2022-09-19 16:32:27 +03:00
|
|
|
if (!version) throw new Error(`no-version-found: ${pkgrq.project}`)
|
2022-09-01 20:49:14 +03:00
|
|
|
const pkg = { project: pkgrq.project, version }
|
2022-08-01 22:43:40 +03:00
|
|
|
|
2022-09-13 18:05:04 +03:00
|
|
|
if (group_it) {
|
2022-09-08 23:40:35 +03:00
|
|
|
console.log("::group::", `${pkg.project}@${pkg.version}`)
|
|
|
|
} else {
|
|
|
|
console.log({ building: pkgrq.project })
|
|
|
|
}
|
2022-08-01 22:43:40 +03:00
|
|
|
|
2022-09-19 16:32:27 +03:00
|
|
|
await build(pkg)
|
2022-09-01 20:49:14 +03:00
|
|
|
rv.push(pkg)
|
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
|
|
|
|
|
|
|
const built_pkgs = rv.map(({ project, version }) => `${project}@${version}`).join(" ")
|
|
|
|
const txt = `::set-output name=pkgs::${built_pkgs}\n`
|
|
|
|
await Deno.stdout.write(new TextEncoder().encode(txt))
|