pantry/scripts/build.ts

58 lines
1.5 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"
import build from "./build/build.ts"
2022-09-20 14:53:40 +03:00
import { Package } from "types"
import { parse_pkg_requirement } from "utils"
2022-09-20 18:29:21 +03:00
import { useFlags, usePrefix } from "hooks"
2022-09-20 14:53:40 +03:00
import * as semver from "semver"
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-20 14:53:40 +03:00
const dry = Deno.args.map(parse_pkg_requirement)
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-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-01 20:49:14 +03:00
for (const pkgrq of dry) {
const versions = await pantry.getVersions(pkgrq)
const version = semver.maxSatisfying(versions, pkgrq.constraint)
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-20 14:53:40 +03:00
console.log("::group::", `${pkg.project}=${pkg.version}`)
2022-09-08 23:40:35 +03:00
} else {
console.log({ building: pkgrq.project })
}
2022-08-01 22:43:40 +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))