From 7d96f7c3522e49033dd72a32a876acd192740ebf Mon Sep 17 00:00:00 2001 From: Jacob Heider Date: Thu, 27 Oct 2022 18:23:32 -0400 Subject: [PATCH] de-duplicate pantry scripts (#11) --- .github/workflows/build.yml | 64 +++++++++++++++++++++---------------- scripts/build.ts | 17 ++-------- scripts/test.ts | 9 ++++-- scripts/utils/misc.ts | 17 ++++++++++ 4 files changed, 62 insertions(+), 45 deletions(-) create mode 100644 scripts/utils/misc.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 41bd1d3d..bd34108d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,6 +43,12 @@ jobs: repository: teaxyz/cli token: ${{ secrets.TEMP_JACOBS_GITHUB_PAT }} + - uses: teaxyz/setup@v0 + id: tea + with: + srcroot: /opt/tea.xyz/var/pantry + prefix: /opt + - name: HACKS run: | case ${{ matrix.os }} in @@ -58,32 +64,23 @@ jobs: ;; esac - - uses: teaxyz/setup@v0 - id: tea - with: - srcroot: pantry - prefix: /opt - - - name: prepare pantries - run: | - # Ensures the pantry paths within our tea environment exist, and are as synchronized - # as might be needed in the future; we then copy the contents of our checkout into - # them (excluding symlinks -- `cp`s all handle them differently and they aren't needed - # here) to allow access to any new code being merged into PR/CI. - tea --sync + - run: | find $GITHUB_WORKSPACE/pantry \ -not -type l \ -mindepth 1 \ -maxdepth 1 \ -print0 | \ xargs -0 -I{} cp -Rv {} /opt/tea.xyz/var/pantry + cp -a cli /opt/tea.xyz/var/ - - run: pantry/scripts/sort.ts ${{ inputs.projects }} + - run: /opt/tea.xyz/var/pantry/scripts/sort.ts ${{ inputs.projects }} id: sorted - run: cli/scripts/install.ts ${{ steps.sorted.outputs.pre-install }} - - run: pantry/scripts/build.ts ${{ steps.sorted.outputs.pkgs }} + - run: cat /opt/tea.xyz/var/pantry/projects/zlib.net/package.yml + + - run: /opt/tea.xyz/var/pantry/scripts/build.ts ${{ steps.sorted.outputs.pkgs }} id: build env: # GITHUB_TOKEN doesn't have private access to teaxyz/cli. @@ -130,7 +127,7 @@ jobs: - uses: actions/checkout@v3 with: - path: cli + path: tea.xyz/var/cli repository: teaxyz/cli token: ${{ secrets.TEMP_JACOBS_GITHUB_PAT }} @@ -142,31 +139,33 @@ jobs: - uses: teaxyz/setup@v0 id: tea with: - srcroot: pantry + srcroot: tea.xyz/var/pantry prefix: ${{ github.workspace }} - - name: overlay this pantry + - name: overlay our pantry run: | - tea --sync - find $GITHUB_WORKSPACE/pantry \ + find pantry \ -not -type l \ -mindepth 1 \ -maxdepth 1 \ -print0 | \ - xargs -0 -I{} cp -Rv {} $GITHUB_WORKSPACE/tea.xyz/var/pantry + xargs -0 -I{} cp -Rv {} tea.xyz/var/pantry - uses: actions/download-artifact@v3 with: name: ${{ matrix.tag || matrix.os }} - run: tar xzf artifacts.tgz - working-directory: ${{ steps.tea.outputs.prefix }} - - run: pantry/scripts/test.ts ${{ inputs.projects }} + # script comes from pantry.core, which _might_not_be_this_pantry_ + - run: tea.xyz/var/pantry/scripts/test.ts ${{ inputs.projects }} bottle: needs: [test, build] runs-on: ${{ matrix.platform.os }} + defaults: + run: + working-directory: tea.xyz/var/pantry strategy: matrix: platform: @@ -183,16 +182,25 @@ jobs: - uses: actions/checkout@v3 with: - path: cli + path: tea.xyz/var/cli repository: teaxyz/cli token: ${{ secrets.TEMP_JACOBS_GITHUB_PAT }} - uses: teaxyz/setup@v0 id: tea with: - srcroot: pantry + srcroot: tea.xyz/var/pantry prefix: ${{ github.workspace }} + - name: overlay our pantry + run: | + find $GITHUB_WORKSPACE/pantry \ + -not -type l \ + -mindepth 1 \ + -maxdepth 1 \ + -print0 | \ + xargs -0 -I{} cp -Rv {} . + - uses: actions/download-artifact@v3 with: name: ${{ matrix.platform.tag || matrix.platform.os }} @@ -201,12 +209,12 @@ jobs: - run: tar xzf artifacts.tgz working-directory: ${{ steps.tea.outputs.prefix }} - - run: pantry/scripts/bottle.ts ${{ needs.build.outputs.built }} + - run: scripts/bottle.ts ${{ needs.build.outputs.built }} id: bottle-xz env: COMPRESSION: xz - - run: pantry/scripts/bottle.ts ${{ needs.build.outputs.built }} + - run: scripts/bottle.ts ${{ needs.build.outputs.built }} id: bottle-gz env: COMPRESSION: gz @@ -214,7 +222,7 @@ jobs: - name: upload bottles id: upload if: ${{ inputs.upload }} - run: pantry/scripts/upload.ts + run: scripts/upload.ts --pkgs ${{ needs.build.outputs.built }} ${{ needs.build.outputs.built }} --srcs ${{ needs.build.outputs.srcs }} ${{ needs.build.outputs.srcs }} --bottles ${{ steps.bottle-gz.outputs.bottles }} ${{ steps.bottle-xz.outputs.bottles }} diff --git a/scripts/build.ts b/scripts/build.ts index f6e53baf..1798cc25 100755 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -21,6 +21,7 @@ import { Installation } from "types" import { pkg as pkgutils } from "utils" import { useFlags, usePrefix } from "hooks" import { set_output } from "./utils/gha.ts" +import { overlay_this_pantry } from "./utils/misc.ts" import build, { BuildResult } from "./build/build.ts" import * as ARGV from "./utils/args.ts" import Path from "path" @@ -38,7 +39,7 @@ if (usePrefix().string != "/opt") { throw new Error("builds must be performed in /opt (try TEA_PREFIX=/opt)") } -await overlay() +await overlay_this_pantry() for (const rq of dry) { const pkg = await pantry.resolve(rq) @@ -66,17 +67,3 @@ await set_output("srcs-relative-paths", rv.compact(x => x.src?.relative({ to })) interface InstallationPlus extends Installation { src: Path } - -///------------------------------------------------------------ -/// overlay ourselves onto the /opt pantry -async function overlay() { - const pantry_prefix = usePrefix().join("tea.xyz/var/pantry") - const self = new URL(import.meta.url).path().parent().parent().join("projects") - const to = pantry_prefix.join("projects") - for await (const [path, {isFile}] of self.walk()) { - if (isFile) { - const dst = to.join(path.relative({ to: self })) - path.cp({ into: dst.parent().mkpath() }) - } - } -} diff --git a/scripts/test.ts b/scripts/test.ts index 17030aad..872896a0 100755 --- a/scripts/test.ts +++ b/scripts/test.ts @@ -18,8 +18,9 @@ import { usePantry, useFlags, usePrefix } from "hooks" import useShellEnv, { expand } from "hooks/useShellEnv.ts" import { run, undent, pkg as pkgutils } from "utils" import { resolve, install, hydrate, link } from "prefab" -import Path from "path" +import { overlay_this_pantry } from "./utils/misc.ts" import * as ARGV from "./utils/args.ts" +import Path from "path" useFlags() @@ -30,6 +31,8 @@ for await (const pkg of ARGV.installs()) { } async function test(self: Installation) { + await overlay_this_pantry() + const yml = await pantry.getYAML(self.pkg).parse() const deps = await deps4(self.pkg) const installations = await prepare(deps) @@ -69,7 +72,9 @@ async function test(self: Installation) { text += "\n" for await (const [path, {name, isFile}] of pantry.getYAML(self.pkg).path.parent().ls()) { - if (isFile && name != 'package.yml') path.cp({ into: cwd }) + if (isFile && name != 'package.yml') { + path.cp({ into: cwd }) + } } const cmd = tmp diff --git a/scripts/utils/misc.ts b/scripts/utils/misc.ts new file mode 100644 index 00000000..7a724799 --- /dev/null +++ b/scripts/utils/misc.ts @@ -0,0 +1,17 @@ +import { usePrefix } from "hooks" + +export async function overlay_this_pantry() { + const pantry_prefix = usePrefix().join("tea.xyz/var/pantry") + const self = new URL(import.meta.url).path().parent().parent().parent().join("projects") + + // noop, but also THIS FUCKS SHIT UP + if (self.parent().eq(pantry_prefix)) return + + const to = pantry_prefix.join("projects") + for await (const [path, {isFile}] of self.walk()) { + if (isFile) { + const dst = to.join(path.relative({ to: self })) + path.cp({ into: dst.parent().mkpath() }) + } + } +}