Skip to content

pi-gamebook-tools

The same, on plain Debian with Bun as a tool.

pi-gamebook's CI with Bun brought as a tool rather than baked into an image: the steps run on a plain Debian image, and Bun is put on their PATH.

flowchart LR
    s0["check"]
    s1["test"]

The steps this script plans for a push about which nothing is known. An arrow is a needs.

# pi-gamebook's CI with Bun brought as a tool rather than baked into an image:
# the steps run on a plain Debian image, and Bun is put on their PATH.

# Pinned by checksum, one per architecture. The same archive is downloaded once
# per machine and shared, read-only, by every step that lists it.
bun = tool(
    "bun",
    url = "https://github.com/oven-sh/bun/releases/download/bun-v1.3.14/bun-linux-{arch}.zip",
    sha256 = {
        "amd64": "951ee2aee855f08595aeec6225226a298d3fea83a3dcd6465c09cbccdf7e848f",
        "arm64": "a27ffb63a8310375836e0d6f668ae17fa8d8d18b88c37c821c65331973a19a3b",
    },
    arch_names = {"amd64": "x64", "arm64": "aarch64"},
    bin = ["bun-linux-{arch}"],
)

SOURCES = ["src", "test", "rules", "index.ts", "omp.ts", "package.json", "bun.lock", "tsconfig.json"]

def bun_step(name, command):
    return step(
        name,
        image = "debian:12-slim",
        tools = [bun],
        run = "bun install --frozen-lockfile && " + command,
        inputs = SOURCES,
        caches = {"bun": "/root/.bun/install/cache"},
    )

def ci(ctx):
    return [
        bun_step("check", "bun run check"),
        bun_step("test", "bun test"),
    ]
# Generated by `starci compile` from pi-gamebook-tools.ci.star. Edit that, not this.
#
# Each job is one step of the plan: the same image, command, tools and
# packages, given only the step's inputs. A job skips its work when it has
# already passed with the same inputs.
#
# What does not carry over:
#  - Passes are remembered in this repository's Actions cache, which GitHub
#    scopes by branch and evicts when old. starci's own store has neither
#    limit.

name: CI

on:
  push:
    branches: ['**']
    tags: ['**']
  pull_request:
  workflow_dispatch:

jobs:
  check:
    name: "check"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /bun.lock
            /index.ts
            /omp.ts
            /package.json
            /rules
            /src
            /test
            /tsconfig.json
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-check-ec8db2e6a4b7d1c4-${{ hashFiles('bun.lock', 'bun.lock/**', 'index.ts', 'index.ts/**', 'omp.ts', 'omp.ts/**', 'package.json', 'package.json/**', 'rules', 'rules/**', 'src', 'src/**', 'test', 'test/**', 'tsconfig.json', 'tsconfig.json/**') }}
      - name: "Tool: bun"
        if: steps.passed.outputs.cache-hit != 'true'
        run: |
          mkdir -p "$RUNNER_TEMP/starci-tools/bun"
          curl -fsSL 'https://github.com/oven-sh/bun/releases/download/bun-v1.3.14/bun-linux-x64.zip' -o "$RUNNER_TEMP/bun.download"
          echo "951ee2aee855f08595aeec6225226a298d3fea83a3dcd6465c09cbccdf7e848f  $RUNNER_TEMP/bun.download" | sha256sum -c -
          unzip -q "$RUNNER_TEMP/bun.download" -d "$RUNNER_TEMP/starci-tools/bun"
      - name: "Cache: bun"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/bun
          key: starci-cache-bun-${{ github.run_id }}
          restore-keys: starci-cache-bun-
      - name: "check"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            bun install --frozen-lockfile && bun run check
        run: |
          docker pull -q debian:12-slim
          image_path=$(docker image inspect debian:12-slim --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -v "$RUNNER_TEMP/starci-tools/bun:/opt/starci/tools/bun:ro" \
            -v "$RUNNER_TEMP/starci-cache/bun:/root/.bun/install/cache" \
            -e "PATH=/opt/starci/tools/bun/bun-linux-x64:$image_path" \
            debian:12-slim sh -c "$STARCI_RUN"
      - name: Remember this pass
        if: steps.passed.outputs.cache-hit != 'true'
        run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"

  test:
    name: "test"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          sparse-checkout-cone-mode: false
          sparse-checkout: |
            /bun.lock
            /index.ts
            /omp.ts
            /package.json
            /rules
            /src
            /test
            /tsconfig.json
      - name: Has this already passed with these inputs?
        id: passed
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-passed
          key: starci-passed-test-6b293961e36e63ef-${{ hashFiles('bun.lock', 'bun.lock/**', 'index.ts', 'index.ts/**', 'omp.ts', 'omp.ts/**', 'package.json', 'package.json/**', 'rules', 'rules/**', 'src', 'src/**', 'test', 'test/**', 'tsconfig.json', 'tsconfig.json/**') }}
      - name: "Tool: bun"
        if: steps.passed.outputs.cache-hit != 'true'
        run: |
          mkdir -p "$RUNNER_TEMP/starci-tools/bun"
          curl -fsSL 'https://github.com/oven-sh/bun/releases/download/bun-v1.3.14/bun-linux-x64.zip' -o "$RUNNER_TEMP/bun.download"
          echo "951ee2aee855f08595aeec6225226a298d3fea83a3dcd6465c09cbccdf7e848f  $RUNNER_TEMP/bun.download" | sha256sum -c -
          unzip -q "$RUNNER_TEMP/bun.download" -d "$RUNNER_TEMP/starci-tools/bun"
      - name: "Cache: bun"
        if: steps.passed.outputs.cache-hit != 'true'
        uses: actions/cache@v4
        with:
          path: ${{ runner.temp }}/starci-cache/bun
          key: starci-cache-bun-${{ github.run_id }}
          restore-keys: starci-cache-bun-
      - name: "test"
        if: steps.passed.outputs.cache-hit != 'true'
        env:
          STARCI_RUN: |-
            bun install --frozen-lockfile && bun test
        run: |
          docker pull -q debian:12-slim
          image_path=$(docker image inspect debian:12-slim --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
          docker run --rm \
            -v "$PWD:/workspace" \
            -w /workspace \
            -v "$RUNNER_TEMP/starci-tools/bun:/opt/starci/tools/bun:ro" \
            -v "$RUNNER_TEMP/starci-cache/bun:/root/.bun/install/cache" \
            -e "PATH=/opt/starci/tools/bun/bun-linux-x64:$image_path" \
            debian:12-slim sh -c "$STARCI_RUN"
      - name: Remember this pass
        if: steps.passed.outputs.cache-hit != 'true'
        run: mkdir -p "$RUNNER_TEMP/starci-passed" && date > "$RUNNER_TEMP/starci-passed/at"
# Generated by `starci compile --target circleci` from pi-gamebook-tools.ci.star. Edit that, not this.
#
# Each job is one step of the plan: the same image, command, tools and
# packages, given only the step's inputs. A job skips its work when it has
# already passed with the same inputs.
#
# What does not carry over:
#  - Passes are remembered in this project's CircleCI cache, which expires.
#    starci's own store does not.

version: 2.1

jobs:
  check:
    machine:
      image: ubuntu-2404:current
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "Keep only this step's inputs"
          command: |
            git sparse-checkout set --no-cone '/bun.lock' '/index.ts' '/omp.ts' '/package.json' '/rules' '/src' '/test' '/tsconfig.json'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)bun.lock' ':(top,literal)index.ts' ':(top,literal)omp.ts' ':(top,literal)package.json' ':(top,literal)rules' ':(top,literal)src' ':(top,literal)test' ':(top,literal)tsconfig.json' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-check-ec8db2e6a4b7d1c4-{{ checksum "/tmp/starci-inputs" }}
      - run:
          name: "Stop here if it has"
          command: |
            if [ -e ~/starci-passed/at ]; then
              echo "Passed before with the same inputs, on $(cat ~/starci-passed/at). Nothing to do."
              circleci-agent step halt
            fi
      - run:
          name: "Tool: bun"
          command: |
            mkdir -p "$HOME/starci-tools/bun"
            curl -fsSL 'https://github.com/oven-sh/bun/releases/download/bun-v1.3.14/bun-linux-x64.zip' -o /tmp/bun.download
            echo "951ee2aee855f08595aeec6225226a298d3fea83a3dcd6465c09cbccdf7e848f  /tmp/bun.download" | sha256sum -c -
            unzip -q "/tmp/bun.download" -d "$HOME/starci-tools/bun"
      - restore_cache:
          name: "Cache: bun"
          keys:
            - starci-cache-bun-
      - run:
          name: "check"
          environment:
            STARCI_RUN: |-
              bun install --frozen-lockfile && bun run check
          command: |
            docker pull -q debian:12-slim
            image_path=$(docker image inspect debian:12-slim --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -v "$HOME/starci-tools/bun:/opt/starci/tools/bun:ro" \
              -v "$HOME/starci-cache/bun:/root/.bun/install/cache" \
              -e "PATH=/opt/starci/tools/bun/bun-linux-x64:$image_path" \
              debian:12-slim sh -c "$STARCI_RUN"
      - save_cache:
          name: "Save cache: bun"
          key: starci-cache-bun-{{ .Revision }}
          paths:
            - ~/starci-cache/bun
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-check-ec8db2e6a4b7d1c4-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

  test:
    machine:
      image: ubuntu-2404:current
    resource_class: medium
    steps:
      - checkout
      - run:
          name: "Keep only this step's inputs"
          command: |
            git sparse-checkout set --no-cone '/bun.lock' '/index.ts' '/omp.ts' '/package.json' '/rules' '/src' '/test' '/tsconfig.json'
      - run:
          name: "Identify the inputs"
          command: |
            git ls-files -s -- ':(top,literal)bun.lock' ':(top,literal)index.ts' ':(top,literal)omp.ts' ':(top,literal)package.json' ':(top,literal)rules' ':(top,literal)src' ':(top,literal)test' ':(top,literal)tsconfig.json' > /tmp/starci-inputs
      - restore_cache:
          name: Has this already passed with these inputs?
          keys:
            - starci-passed-test-6b293961e36e63ef-{{ checksum "/tmp/starci-inputs" }}
      - run:
          name: "Stop here if it has"
          command: |
            if [ -e ~/starci-passed/at ]; then
              echo "Passed before with the same inputs, on $(cat ~/starci-passed/at). Nothing to do."
              circleci-agent step halt
            fi
      - run:
          name: "Tool: bun"
          command: |
            mkdir -p "$HOME/starci-tools/bun"
            curl -fsSL 'https://github.com/oven-sh/bun/releases/download/bun-v1.3.14/bun-linux-x64.zip' -o /tmp/bun.download
            echo "951ee2aee855f08595aeec6225226a298d3fea83a3dcd6465c09cbccdf7e848f  /tmp/bun.download" | sha256sum -c -
            unzip -q "/tmp/bun.download" -d "$HOME/starci-tools/bun"
      - restore_cache:
          name: "Cache: bun"
          keys:
            - starci-cache-bun-
      - run:
          name: "test"
          environment:
            STARCI_RUN: |-
              bun install --frozen-lockfile && bun test
          command: |
            docker pull -q debian:12-slim
            image_path=$(docker image inspect debian:12-slim --format '{{range .Config.Env}}{{println .}}{{end}}' | sed -n 's/^PATH=//p')
            docker run --rm \
              -v "$PWD:/workspace" \
              -w /workspace \
              -v "$HOME/starci-tools/bun:/opt/starci/tools/bun:ro" \
              -v "$HOME/starci-cache/bun:/root/.bun/install/cache" \
              -e "PATH=/opt/starci/tools/bun/bun-linux-x64:$image_path" \
              debian:12-slim sh -c "$STARCI_RUN"
      - save_cache:
          name: "Save cache: bun"
          key: starci-cache-bun-{{ .Revision }}
          paths:
            - ~/starci-cache/bun
      - run:
          name: "Remember this pass"
          command: |
            mkdir -p ~/starci-passed && date > ~/starci-passed/at
      - save_cache:
          key: starci-passed-test-6b293961e36e63ef-{{ checksum "/tmp/starci-inputs" }}
          paths:
            - ~/starci-passed

workflows:
  ci:
    jobs:
      - check
      - test

Download: pi-gamebook-tools.ci.star, GitHub Actions, CircleCI