From 694f3511cae02aa53920e8957d51ff6bf27efe08 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Sun, 4 Feb 2024 06:54:59 -0500 Subject: [PATCH] Gratuitous gardening --- .github/workflows/ci.cli.yml | 9 +++----- audit/action.yml | 7 +++--- bin/cmd/audit => audit/audit.ts | 0 bin/bk | 12 +++++----- bin/bk-audit | 1 + bin/bk-build | 1 + bin/{cmd/docker => bk-docker} | 40 ++++++++++++++++++++++++--------- bin/{cmd/edit => bk-edit} | 2 +- bin/{cmd/init => bk-init} | 2 +- bin/{cmd/status => bk-status} | 0 bin/bk-test | 1 + build/action.yml | 7 +++--- bin/cmd/build => build/build.ts | 2 +- id/action.yml | 3 ++- lib/resolve-pkg.ts | 2 +- test/action.yml | 7 +++--- bin/cmd/test => test/test.ts | 0 17 files changed, 57 insertions(+), 39 deletions(-) rename bin/cmd/audit => audit/audit.ts (100%) create mode 120000 bin/bk-audit create mode 120000 bin/bk-build rename bin/{cmd/docker => bk-docker} (66%) rename bin/{cmd/edit => bk-edit} (95%) rename bin/{cmd/init => bk-init} (97%) rename bin/{cmd/status => bk-status} (100%) create mode 120000 bin/bk-test rename bin/cmd/build => build/build.ts (99%) rename bin/cmd/test => test/test.ts (100%) diff --git a/.github/workflows/ci.cli.yml b/.github/workflows/ci.cli.yml index 0e015f0d..e98d5523 100644 --- a/.github/workflows/ci.cli.yml +++ b/.github/workflows/ci.cli.yml @@ -36,11 +36,7 @@ jobs: - uses: pkgxdev/setup@v2 - name: precache # makes it easier to read the real output - run: | # we have to make symlinks because deno cache doesn’t take a --ext=ts flag - ln -s bin/cmd/build build.ts - ln -s bin/cmd/test test.ts - pkgx deno cache *.ts - rm *.ts + run: pkgx deno cache test/test.ts build/build.ts - run: bin/bk build ${{matrix.pkg}} - run: bin/bk test ${{matrix.pkg}} @@ -65,8 +61,9 @@ jobs: PKGX_PANTRY_PATH: null steps: - uses: actions/checkout@v4 - - uses: pkgxdev/dev@main + - uses: pkgxdev/dev@v0 - run: deno test --allow-env --allow-net --ignore=.data + working-directory: lib unavailable: runs-on: ubuntu-latest diff --git a/audit/action.yml b/audit/action.yml index 2ff44f7a..3b99345a 100644 --- a/audit/action.yml +++ b/audit/action.yml @@ -25,12 +25,11 @@ runs: shell: bash run: | echo "::group::fetch deno deps" - tmpdir=$(mktemp -d) - ln -s ${GITHUB_ACTION_PATH}/../bin/cmd/audit $tmpdir/audit.ts - pkgx deno cache $tmpdir/audit.ts --config=${GITHUB_ACTION_PATH}/../deno.jsonc + cd $GITHUB_ACTION_PATH + pkgx deno cache ./audit.ts echo "::endgroup::" - - run: ${GITHUB_ACTION_PATH}/../bin/cmd/audit '${{ inputs.pkg }}' + - run: ${GITHUB_ACTION_PATH}/audit.ts '${{ inputs.pkg }}' shell: bash env: GITHUB_TOKEN: ${{inputs.token}} diff --git a/bin/cmd/audit b/audit/audit.ts similarity index 100% rename from bin/cmd/audit rename to audit/audit.ts diff --git a/bin/bk b/bin/bk index 03359007..a1621969 100755 --- a/bin/bk +++ b/bin/bk @@ -35,13 +35,15 @@ if test "$arg" = "-v" || test "$arg" = "--version"; then exit 0 fi -if test -x "$d/cmd/$arg"; then - exec "$d/cmd/$arg" "$@" -elif test "$(find "$d/cmd" -name "$arg*" | wc -l)" -eq 1; then - exec "$d"/cmd/"$arg"* "$@" +if test -x "$d/bk-$arg"; then + exec "$d/bk-$arg" "$@" +elif test "$(find "$d" -name "bk-$arg*" | wc -l)" -eq 1; then + exec "$d/bk-$arg"* "$@" else echo "error: unknown or ambiguous command \`$arg\`, available commands:" >&2 echo >&2 - echo " "$(ls "$d"/cmd) >&2 + for x in $(cd "$d" && ls | grep '^bk-'); do + echo $x | sed 's/^bk-//' >&2 + done exit 64 fi diff --git a/bin/bk-audit b/bin/bk-audit new file mode 120000 index 00000000..60115f39 --- /dev/null +++ b/bin/bk-audit @@ -0,0 +1 @@ +../audit/audit.ts \ No newline at end of file diff --git a/bin/bk-build b/bin/bk-build new file mode 120000 index 00000000..afdc611d --- /dev/null +++ b/bin/bk-build @@ -0,0 +1 @@ +../build/build.ts \ No newline at end of file diff --git a/bin/cmd/docker b/bin/bk-docker similarity index 66% rename from bin/cmd/docker rename to bin/bk-docker index 5348e012..f70d20ac 100755 --- a/bin/cmd/docker +++ b/bin/bk-docker @@ -6,7 +6,7 @@ if [ "$1" == --help ]; then echo >&2 echo 'bk docker interactive tty of your pantry checkout' >&2 echo 'bk docker build same as `bk build` but in linux' >&2 - echo 'bk docker --x86-64 build builds for intel' >&2 + echo 'bk docker --x86-64 build builds for PLATFORM' >&2 exit 0 fi @@ -30,37 +30,55 @@ if [ "$1" = --pull ]; then shift fi -if [ "$1" = --x86-64 ]; then - INTEL="--platform linux/amd64" - shift -fi +case "$1" in +--x86-64|--amd64) + PLATFORM=linux/amd64 + shift;; +--aarch64|--arm64) + PLATFORM=linux/arm64 + shift;; +*) + case "$(uname -m)" in + x86_64) + PLATFORM=linux/amd64;; + aarch64|arm64) + PLATFORM=linux/arm64;; + esac;; +esac if [ -z "$1" ]; then INTERACTIVE="-it" CMD="/bin/bash" else - CMD="/brewkit/bin/cmd/$1" + CMD="/brewkit/bin/bk $1" shift fi -VOLUME_NAME="brewkit.pkgx.dev" +SPECIFIER="${PLATFORM//\//-}" +VOLUME_NAME="brewkit.pkgx.dev.${SPECIFIER:-unknown}" + +PLATFORM="${PLATFORM:+--platform $PLATFORM}" # Create volume if it doesn't exist if [ -z "$(docker volume ls -q -f name=^${VOLUME_NAME}$)" ]; then - docker volume create ${VOLUME_NAME} + set -x + docker volume create ${VOLUME_NAME} >/dev/null +else + set -x fi exec docker run \ - --name $VOLUME_NAME \ + --name brewkit.pkgx.dev \ --rm \ - $INTERACTIVE $INTEL \ + $INTERACTIVE $PLATFORM \ --volume "$d:/brewkit" \ --volume "$PKGX_PANTRY_PATH:/work" \ --volume "${XDG_CACHE_HOME:-$HOME/Library/Caches/pkgx}:/root/.cache/pkgx" \ --volume "$VOLUME_NAME:/root/.pkgx" \ + --env DENO_DIR=/root/.pkgx/.cache/deno \ --env PKGX_PANTRY_PATH=/work \ --env GITHUB_TOKEN=$GITHUB_TOKEN \ --env CLICOLOR_FORCE=1 \ --workdir /work \ pkgxdev/pkgx \ - "$CMD" "$@" + $CMD "$@" diff --git a/bin/cmd/edit b/bin/bk-edit similarity index 95% rename from bin/cmd/edit rename to bin/bk-edit index 66d72c53..c9b742bd 100755 --- a/bin/cmd/edit +++ b/bin/bk-edit @@ -13,7 +13,7 @@ if [ -z "$1" ]; then for x in $(echo "$PKGX_PANTRY_PATH" | tr ':' '\n'); do if [ -z "$PKGS" -a -d "$x"/.git ]; then #^^^^^^^^^^^^^^^ stop at first match - PKGS=($(GIT_WORK_TREE="$x" bash "$d/bin/cmd/status" --print-paths)) + PKGS=($(GIT_WORK_TREE="$x" bash "$d/bin/bk-status" --print-paths)) fi done elif [ -f "$d"/projects/$1/package.yml ]; then diff --git a/bin/cmd/init b/bin/bk-init similarity index 97% rename from bin/cmd/init rename to bin/bk-init index 6e266e43..d73edea3 100755 --- a/bin/cmd/init +++ b/bin/bk-init @@ -56,4 +56,4 @@ we typically name packages after their homepage. if you aren’t sure about the name you can submit and we’ll assist. EOF -exec bash "$d/bin/cmd/edit" $BLEND +exec bash "$d/bin/bk-edit" $BLEND diff --git a/bin/cmd/status b/bin/bk-status similarity index 100% rename from bin/cmd/status rename to bin/bk-status diff --git a/bin/bk-test b/bin/bk-test new file mode 120000 index 00000000..340baa8d --- /dev/null +++ b/bin/bk-test @@ -0,0 +1 @@ +../test/test.ts \ No newline at end of file diff --git a/build/action.yml b/build/action.yml index 0cf67dda..e7f6e681 100644 --- a/build/action.yml +++ b/build/action.yml @@ -48,9 +48,8 @@ runs: shell: bash run: | echo "::group::fetch deno deps" - tmpdir=$(mktemp -d) - ln -s ${GITHUB_ACTION_PATH}/../bin/cmd/build $tmpdir/build.ts - pkgx deno cache $tmpdir/build.ts --config=${GITHUB_ACTION_PATH}/../deno.jsonc + cd $GITHUB_ACTION_PATH + pkgx deno cache ./build.ts echo "::endgroup::" - name: build @@ -60,7 +59,7 @@ runs: fi set +e - ${GITHUB_ACTION_PATH}/../bin/cmd/build '${{ inputs.pkg }}' + ${GITHUB_ACTION_PATH}/build.ts '${{ inputs.pkg }}' status=$? if [ $status -eq 2 ]; then echo noop=true >> $GITHUB_OUTPUT diff --git a/bin/cmd/build b/build/build.ts similarity index 99% rename from bin/cmd/build rename to build/build.ts index e0b57ce7..8ff8d07c 100755 --- a/bin/cmd/build +++ b/build/build.ts @@ -202,5 +202,5 @@ function make_toolchain() { symlink(["strip"], {to: "llvm-strip"}) } - return new Path(new URL(import.meta.url).pathname).join("../../../share/toolchain/bin") + return new Path(new URL(import.meta.url).pathname).join("../../share/toolchain/bin") } diff --git a/id/action.yml b/id/action.yml index b15426f3..54c96e4d 100644 --- a/id/action.yml +++ b/id/action.yml @@ -39,7 +39,8 @@ runs: - name: fetch deno deps run: | echo "::group::fetch deno deps" - pkgx deno cache ${GITHUB_ACTION_PATH}/id.ts --config=${GITHUB_ACTION_PATH}/../deno.jsonc + cd ${GITHUB_ACTION_PATH} + pkgx deno cache ./id.ts echo "::endgroup::" shell: bash diff --git a/lib/resolve-pkg.ts b/lib/resolve-pkg.ts index ca564c71..3d66e964 100644 --- a/lib/resolve-pkg.ts +++ b/lib/resolve-pkg.ts @@ -35,7 +35,7 @@ export default async function(arg?: string) { async function get_pantry_status() { const bkroot = new Path(new URL(import.meta.url).pathname).parent().parent() - const proc = new Deno.Command("bash", {args: [bkroot.join('bin/cmd/status').string], stdout: 'piped'}).spawn() + const proc = new Deno.Command("bash", {args: [bkroot.join('bin/bk-status').string], stdout: 'piped'}).spawn() const [out, { success }] = await Promise.all([proc.output(), proc.status]) if (success) { return new TextDecoder().decode(out.stdout).split(/\s+/).filter(x => x) diff --git a/test/action.yml b/test/action.yml index 90860064..b783c022 100644 --- a/test/action.yml +++ b/test/action.yml @@ -23,13 +23,12 @@ runs: shell: bash run: | echo "::group::fetch deno deps" - tmpdir=$(mktemp -d) - ln -s ${GITHUB_ACTION_PATH}/../bin/cmd/test $tmpdir/test.ts - pkgx deno cache $tmpdir/test.ts --config=${GITHUB_ACTION_PATH}/../deno.jsonc + cd ${GITHUB_ACTION_PATH} + pkgx deno cache ./test.ts echo "::endgroup::" - name: test - run: ${GITHUB_ACTION_PATH}/../bin/cmd/test '${{ inputs.pkg }}' + run: ${GITHUB_ACTION_PATH}/test.ts '${{ inputs.pkg }}' shell: bash env: GITHUB_TOKEN: ${{inputs.token}} diff --git a/bin/cmd/test b/test/test.ts similarity index 100% rename from bin/cmd/test rename to test/test.ts