Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# export PKGX_DIR="$PWD/artifacts/$(uname)/$(uname -m)"
# export PKGX_PANTRY_DIR="$PWD/builds/pantry"
PATH_add bin
export DOCKER_DEFAULT_PLATFORM=linux/amd64
export AWS_PROFILE=tea
21 changes: 21 additions & 0 deletions .github/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM debian:buster-slim AS stage1
RUN apt-get update && apt-get install -y curl
RUN curl https://pkgx.sh/$(uname)/$(uname -m).tgz | tar xz -C /usr/local/bin
ENV PKGX_DIST_URL="https://dist.pkgx.dev/v2"
RUN pkgx +llvm.org +jq +make +patchelf +deno^2 >/dev/null
COPY ./brewkit /work/brewkit
COPY ./deno.jsonc /work/deno.jsonc
COPY ./deno.lock /work/deno.lock
RUN cd /work && find ./brewkit -name \*.ts | xargs pkgx deno cache

FROM debian:buster-slim AS stage2
COPY --from=stage1 /usr/local/bin/pkgx /usr/local/bin/pkgx
COPY --from=stage1 /root/.pkgx /root/.pkgx
COPY --from=stage1 /root/.cache/deno /root/.cache/deno

# libc6-dev: platform specific c-headers that LLVM doesn’t provide
# libgcc-8-dev: provides the c runtime `crtbeginS.o`
# libstdc++-8-dev: or we can’t build c++ pkgs
RUN apt-get update && apt-get install --yes libc6-dev libgcc-8-dev libstdc++-8-dev

ENV PKGX_DIST_URL="https://dist.pkgx.dev/v2"
48 changes: 48 additions & 0 deletions .github/actions/plan/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
runs:
using: composite
steps:
- id: changed-files
uses: tj-actions/changed-files@v45
with:
files: |
projects/**/build.ts
projects/**/test.ts
projects/**/versions.ts

- name: crunch diff
id: cruncher
run: |
PROJECTS=()
declare -A SEEN
for x in ${{ steps.changed-files.outputs.all_changed_files }}; do
x="$(dirname "${x#projects/}")"
if [ -z "${SEEN[$x]}" ]; then
PROJECTS+=("$x")
SEEN["$x"]=1
fi
done
echo "projects=${PROJECTS[@]}" >> "$GITHUB_OUTPUT"

shell: bash
if: ${{ ! inputs.pkgs }}

- name: compute matrix
id: computer
run: |
${GITHUB_ACTION_PATH}/compute-matrix.js ${{ inputs.pkgs || steps.cruncher.outputs.projects || inputs.default }}
shell: bash
if: ${{ inputs.compute-matrix }}

inputs:
compute-matrix:
default: true
pkgs:
required: false
default:
required: false

outputs:
projects:
value: ${{ steps.cruncher.outputs.projects }}
matrix:
value: ${{ steps.computer.outputs.matrix }}
63 changes: 63 additions & 0 deletions .github/actions/plan/compute-matrix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env node

const fs = require("fs");

(async function () {
const rvv = [];
for (const arg of process.argv.slice(2)) {
const config = await get_config();

for (const platform of config.platforms) {
const rv = {};
rv["platform"] = get_matrix(platform);
rv["pkg"] = arg;
rvv.push(rv);
}
}

const json = JSON.stringify(rvv);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `matrix=${json}\n`);
})();

///////////////////////////////////////////////////////////////////////

async function get_config() {
return { platforms: ["linux/x86-64", "darwin/aarch64", "windows/x86-64"] };
}

function get_matrix(platform) {
const name = platform.replace("/", "+");
switch (platform) {
case "darwin/aarch64":
return {
os: "macos-latest",
name,
tinyname: "²",
};
case "darwin/x86-64":
return {
os: ["self-hosted", "macOS", "X64"],
name,
tinyname: "x64",
};
case "linux/x86-64":
return {
os: "ubuntu-latest",
name,
container: "ghcr.io/pkgxdev/bldbot",
tinyname: "*nix64",
};
case "linux/aarch64":
return {
os: ["self-hosted", "linux", "ARM64"],
name,
tinyname: "*nix·ARM64",
};
case "windows/x86-64":
return {
os: "windows-latest",
name,
tinyname: "win64",
};
}
}
41 changes: 41 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
runs:
using: composite
steps:
- uses: denoland/setup-deno@v2
if: runner.os == 'Windows'

- run: |
"$PWD\\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

git fetch origin pkgx
git checkout FETCH_HEAD -- pkgx.exe
Move-Item -Path pkgx.exe -Destination bin

Get-ChildItem -Path brewkit -Recurse -Filter *.ts | ForEach-Object { deno cache $_.FullName }

choco install make -y
shell: pwsh
if: runner.os == 'Windows'

- run: |
echo "$PWD/bin" >> $GITHUB_PATH

case $(uname) in
Linux)
# $HOME is different in the docker image vs. github actions
ln -s /root/.pkgx $HOME
ln -s /root/.cache $HOME
./bin/pkg-convert
;;
Darwin)
curl https://pkgx.sh/$(uname)/$(uname -m).tgz | sudo tar xz -C /usr/local/bin
find brewkit -name \*.ts | xargs pkgx deno^2 cache
./bin/pkg-convert
;;
*)
make -f ./bin/pkg-convert
;;
esac


shell: bash
34 changes: 34 additions & 0 deletions .github/scripts/generate-versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env -S pkgx deno run --quiet --allow-net --allow-read --allow-env --allow-sys
import { ListObjectsV2Command, S3Client } from "npm:@aws-sdk/client-s3@3.743.0";
import SemVer, { compare } from "https://deno.land/x/libpkgx@v0.20.3/src/utils/semver.ts";
import { basename } from "jsr:@std/path@^1.0.8";

const s3 = new S3Client();
const Bucket = "dist.tea.xyz";
const Prefix = Deno.args[0];
const Key = `${Prefix}/versions.txt`;

async function listObjects() {
const cmd = new ListObjectsV2Command({ Bucket, Prefix });
const rsp = await s3.send(cmd);

if (!rsp.Contents || rsp.Contents.length === 0) {
return [];
}

const rv = new Set<string>();
for (const obj of rsp.Contents) {
const base = basename(obj!.Key);
if (/^v\d+/.test(base)) {
rv.add(base.replace(/\.tar\.[gx]z$/, ""));
}
}
return [...rv];
}

const versions = (await listObjects()).map((x) => new SemVer(x)).sort(compare)
.join("\n");

console.log(versions);

//TODO upload, I tried but Deno and the AWS SDK don’t mix. Maybe bun’ll work?
59 changes: 59 additions & 0 deletions .github/workflows/cd.docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: cd·docker
run-name: cd·docker

on:
push:
branches:
- main
paths:
- .github/workflows/cd.docker.yml
- .github/Dockerfile
- brewkit/**/*.ts
workflow_dispatch:

concurrency:
group: docker
cancel-in-progress: true

permissions:
contents: read
packages: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: docker/auth
run: echo "${{ github.token }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/bldbot

- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3

# TODO --platform linux/amd64,linux/arm64
- name: docker/buildx
run: |
docker buildx build \
--push \
--tag ghcr.io/${{ github.repository_owner }}/bldbot:latest \
--platform linux/amd64 \
--file .github/Dockerfile \
.

prune:
needs: deploy
runs-on: ubuntu-latest
steps:
- uses: actions/delete-package-versions@v5
with:
package-name: bldbot
package-type: container
min-versions-to-keep: 10
# ^^ despite telling it to only delete untagged versions
# it deletes images attached to latest like a lolfactory
delete-only-untagged-versions: true
38 changes: 38 additions & 0 deletions .github/workflows/cd.pantry.tgz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: cd·pantry.tgz
run-name: cd·pantry.tgz

on:
push:
branches: main
paths:
- projects/**/*
- .github/workflows/cd.pantry.tgz.yml

concurrency:
group: cd.pantry.tgz
cancel-in-progress: true

jobs:
tarball:
runs-on: ubuntu-latest
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- uses: actions/checkout@v4
- uses: pkgxdev/setup@v3

- run: bin/pkg-convert

- run: tar -C artifacts/pantry -czf pantry.tgz projects

- run: aws s3 cp
./pantry.tgz
s3://dist.tea.xyz/v2/pantry.tgz

- run: aws cloudfront create-invalidation
--distribution-id EWF6XUK8J11DP
--paths /v2/pantry.tgz
Loading
Loading