Something went wrong. Try again.
An Atmosphere in a box
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111#!/usr/bin/env bash# CI entry points, shared by .tangled/workflows/* and local runs (scripts/ci-local.ts).## scripts/ci.sh check install, lint, typecheck, test# scripts/ci.sh npm publish every npm package (needs NPM_CONFIG_TOKEN;# NPM_DRY_RUN=1 builds and stages without uploading)# scripts/ci.sh docker publish the multi-arch image (needs ATCR_APP_PASSWORD)## Bun runs in a pinned oven/bun container rather than on the runner: the stock# bun binary doesn't run on a NixOS runner, and `bun build --compile` embeds# the running Bun, so published binaries must be built by the packageManager# version. The runner only needs docker (with buildx for `docker`).## On a tag push (TANGLED_REF_TYPE=tag) the tag must be v<version>.set -euo pipefail
cd "$(dirname "$0")/.."
BUN_VERSION="$(sed -n 's/.*"packageManager": "bun@\([^"]*\)".*/\1/p' package.json)"NODE_VERSION=22VERSION="$(sed -n 's/^ "version": "\(.*\)",$/\1/p' packages/cli/package.json)"
log() { printf '\033[1m==> %s\033[0m\n' "$*" >&2; }die() { printf 'error: %s\n' "$*" >&2; exit 1; }
command -v docker >/dev/null || die "docker not found"
# Run a script in oven/bun at the workspace's own path. Local runs# (scripts/ci-local.ts) keep the workspace in a docker volume at /workspace,# named by VIVARIUM_CI_VOLUME, since the daemon there can't see the runner's files.workspace_mount() { if [[ -n "${VIVARIUM_CI_VOLUME:-}" ]]; then echo "$VIVARIUM_CI_VOLUME:/workspace"; else echo "$PWD:$PWD"; fi}
in_bun() { local mount mount="$(workspace_mount)" local env_args=(-e CI=true) for v in NPM_CONFIG_TOKEN NPM_DRY_RUN; do [[ -n "${!v:-}" ]] && env_args+=(-e "$v"); done docker run --rm "${env_args[@]}" -v "$mount" -w "$PWD" "oven/bun:$BUN_VERSION" \ bash -euo pipefail -c "$1"}
check_tag() { if [[ "${TANGLED_REF_TYPE:-}" == tag && "${TANGLED_REF_NAME:-}" != "v$VERSION" ]]; then die "tag ${TANGLED_REF_NAME} doesn't match the package version v$VERSION" fi}
cmd_check() { log "check with bun $BUN_VERSION" # Node is for the cli launcher's tests (it runs under Node in the wild): # the official binary, copied out of the node image (apt is slow and flaky). docker run --rm -v "$(workspace_mount)" -w "$PWD" "node:$NODE_VERSION-bookworm-slim" \ sh -c 'mkdir -p .ci/bin && cp /usr/local/bin/node .ci/bin/node' # Core's suite runs one file per process: Bun 1.3.8 crashes (SIGTRAP) # running all of it in one process, though every file passes alone. in_bun ' export PATH="$PWD/.ci/bin:$PATH" bun install --frozen-lockfile bun run lint bunx turbo run typecheck bunx turbo run test --filter="!@vivarium-dev/core" cd packages/core for f in test/*.test.ts; do echo "--- $f" bun test "$f" done '}
cmd_npm() { check_tag [[ -n "${NPM_CONFIG_TOKEN:-}" ]] || die "NPM_CONFIG_TOKEN is not set (an npm token that can publish without 2FA)" local dry="" [[ "${NPM_DRY_RUN:-}" == 1 ]] && dry="--dry-run" log "publishing npm packages $VERSION${dry:+ (dry run)}" # Fail fast on a bad token. npm.ts refuses a dirty tree, so it needs git. in_bun " bun -e ' const res = await fetch(\"https://registry.npmjs.org/-/whoami\", { headers: { authorization: \"Bearer \" + process.env.NPM_CONFIG_TOKEN }, }) if (!res.ok) { console.error(\"npm rejected NPM_CONFIG_TOKEN: HTTP \" + res.status); process.exit(1) } console.log(\"npm token belongs to \" + (await res.json()).username) ' apt-get -qq update >/dev/null && apt-get -qq install -y --no-install-recommends git ca-certificates >/dev/null git config --global --add safe.directory '*' bun install --frozen-lockfile bun scripts/npm.ts publish $dry "}
cmd_docker() { check_tag [[ -n "${ATCR_APP_PASSWORD:-}" ]] || die "ATCR_APP_PASSWORD is not set" # nixpkgs' docker-buildx installs the plugin binary; make the CLI find it. if ! docker buildx version >/dev/null 2>&1 && command -v docker-buildx >/dev/null; then mkdir -p "$HOME/.docker/cli-plugins" ln -sf "$(command -v docker-buildx)" "$HOME/.docker/cli-plugins/docker-buildx" fi VERSION="$VERSION" scripts/docker.sh publish}
case "${1:-}" in check) cmd_check ;; npm) cmd_npm ;; docker) cmd_docker ;; *) sed -n '2,14p' "$0" | sed 's/^# \{0,1\}//'; exit 2 ;;esac