de-duplicate pantry scripts (#11)

This commit is contained in:
Jacob Heider 2022-10-27 18:23:32 -04:00 committed by GitHub
parent 8d594e2114
commit 7d96f7c352
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 45 deletions

View file

@ -43,6 +43,12 @@ jobs:
repository: teaxyz/cli repository: teaxyz/cli
token: ${{ secrets.TEMP_JACOBS_GITHUB_PAT }} token: ${{ secrets.TEMP_JACOBS_GITHUB_PAT }}
- uses: teaxyz/setup@v0
id: tea
with:
srcroot: /opt/tea.xyz/var/pantry
prefix: /opt
- name: HACKS - name: HACKS
run: | run: |
case ${{ matrix.os }} in case ${{ matrix.os }} in
@ -58,32 +64,23 @@ jobs:
;; ;;
esac esac
- uses: teaxyz/setup@v0 - run: |
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
find $GITHUB_WORKSPACE/pantry \ find $GITHUB_WORKSPACE/pantry \
-not -type l \ -not -type l \
-mindepth 1 \ -mindepth 1 \
-maxdepth 1 \ -maxdepth 1 \
-print0 | \ -print0 | \
xargs -0 -I{} cp -Rv {} /opt/tea.xyz/var/pantry 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 id: sorted
- run: cli/scripts/install.ts ${{ steps.sorted.outputs.pre-install }} - 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 id: build
env: env:
# GITHUB_TOKEN doesn't have private access to teaxyz/cli. # GITHUB_TOKEN doesn't have private access to teaxyz/cli.
@ -130,7 +127,7 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
path: cli path: tea.xyz/var/cli
repository: teaxyz/cli repository: teaxyz/cli
token: ${{ secrets.TEMP_JACOBS_GITHUB_PAT }} token: ${{ secrets.TEMP_JACOBS_GITHUB_PAT }}
@ -142,31 +139,33 @@ jobs:
- uses: teaxyz/setup@v0 - uses: teaxyz/setup@v0
id: tea id: tea
with: with:
srcroot: pantry srcroot: tea.xyz/var/pantry
prefix: ${{ github.workspace }} prefix: ${{ github.workspace }}
- name: overlay this pantry - name: overlay our pantry
run: | run: |
tea --sync find pantry \
find $GITHUB_WORKSPACE/pantry \
-not -type l \ -not -type l \
-mindepth 1 \ -mindepth 1 \
-maxdepth 1 \ -maxdepth 1 \
-print0 | \ -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 - uses: actions/download-artifact@v3
with: with:
name: ${{ matrix.tag || matrix.os }} name: ${{ matrix.tag || matrix.os }}
- run: tar xzf artifacts.tgz - 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: bottle:
needs: [test, build] needs: [test, build]
runs-on: ${{ matrix.platform.os }} runs-on: ${{ matrix.platform.os }}
defaults:
run:
working-directory: tea.xyz/var/pantry
strategy: strategy:
matrix: matrix:
platform: platform:
@ -183,16 +182,25 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
path: cli path: tea.xyz/var/cli
repository: teaxyz/cli repository: teaxyz/cli
token: ${{ secrets.TEMP_JACOBS_GITHUB_PAT }} token: ${{ secrets.TEMP_JACOBS_GITHUB_PAT }}
- uses: teaxyz/setup@v0 - uses: teaxyz/setup@v0
id: tea id: tea
with: with:
srcroot: pantry srcroot: tea.xyz/var/pantry
prefix: ${{ github.workspace }} 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 - uses: actions/download-artifact@v3
with: with:
name: ${{ matrix.platform.tag || matrix.platform.os }} name: ${{ matrix.platform.tag || matrix.platform.os }}
@ -201,12 +209,12 @@ jobs:
- run: tar xzf artifacts.tgz - run: tar xzf artifacts.tgz
working-directory: ${{ steps.tea.outputs.prefix }} 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 id: bottle-xz
env: env:
COMPRESSION: xz COMPRESSION: xz
- run: pantry/scripts/bottle.ts ${{ needs.build.outputs.built }} - run: scripts/bottle.ts ${{ needs.build.outputs.built }}
id: bottle-gz id: bottle-gz
env: env:
COMPRESSION: gz COMPRESSION: gz
@ -214,7 +222,7 @@ jobs:
- name: upload bottles - name: upload bottles
id: upload id: upload
if: ${{ inputs.upload }} if: ${{ inputs.upload }}
run: pantry/scripts/upload.ts run: scripts/upload.ts
--pkgs ${{ needs.build.outputs.built }} ${{ needs.build.outputs.built }} --pkgs ${{ needs.build.outputs.built }} ${{ needs.build.outputs.built }}
--srcs ${{ needs.build.outputs.srcs }} ${{ needs.build.outputs.srcs }} --srcs ${{ needs.build.outputs.srcs }} ${{ needs.build.outputs.srcs }}
--bottles ${{ steps.bottle-gz.outputs.bottles }} ${{ steps.bottle-xz.outputs.bottles }} --bottles ${{ steps.bottle-gz.outputs.bottles }} ${{ steps.bottle-xz.outputs.bottles }}

View file

@ -21,6 +21,7 @@ import { Installation } from "types"
import { pkg as pkgutils } from "utils" import { pkg as pkgutils } from "utils"
import { useFlags, usePrefix } from "hooks" import { useFlags, usePrefix } from "hooks"
import { set_output } from "./utils/gha.ts" import { set_output } from "./utils/gha.ts"
import { overlay_this_pantry } from "./utils/misc.ts"
import build, { BuildResult } from "./build/build.ts" import build, { BuildResult } from "./build/build.ts"
import * as ARGV from "./utils/args.ts" import * as ARGV from "./utils/args.ts"
import Path from "path" 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)") throw new Error("builds must be performed in /opt (try TEA_PREFIX=/opt)")
} }
await overlay() await overlay_this_pantry()
for (const rq of dry) { for (const rq of dry) {
const pkg = await pantry.resolve(rq) 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 { interface InstallationPlus extends Installation {
src: Path 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() })
}
}
}

View file

@ -18,8 +18,9 @@ import { usePantry, useFlags, usePrefix } from "hooks"
import useShellEnv, { expand } from "hooks/useShellEnv.ts" import useShellEnv, { expand } from "hooks/useShellEnv.ts"
import { run, undent, pkg as pkgutils } from "utils" import { run, undent, pkg as pkgutils } from "utils"
import { resolve, install, hydrate, link } from "prefab" 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 * as ARGV from "./utils/args.ts"
import Path from "path"
useFlags() useFlags()
@ -30,6 +31,8 @@ for await (const pkg of ARGV.installs()) {
} }
async function test(self: Installation) { async function test(self: Installation) {
await overlay_this_pantry()
const yml = await pantry.getYAML(self.pkg).parse() const yml = await pantry.getYAML(self.pkg).parse()
const deps = await deps4(self.pkg) const deps = await deps4(self.pkg)
const installations = await prepare(deps) const installations = await prepare(deps)
@ -69,7 +72,9 @@ async function test(self: Installation) {
text += "\n" text += "\n"
for await (const [path, {name, isFile}] of pantry.getYAML(self.pkg).path.parent().ls()) { 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 const cmd = tmp

17
scripts/utils/misc.ts Normal file
View file

@ -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() })
}
}
}