pi-gamebook¶
A real repository's CI.
pi-gamebook's CI as a plan: the same things its Forgejo Actions workflow does, as two steps that can run at the same time on different machines.
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 as a plan: the same things its Forgejo Actions workflow
# does, as two steps that can run at the same time on different machines.
BUN = "oven/bun:1"
# What the type-checker and the tests read. A commit that changes nothing
# under these paths (the README, the CI config) reuses the last passing result.
SOURCES = ["src", "test", "rules", "index.ts", "omp.ts", "package.json", "bun.lock", "tsconfig.json"]
def bun_step(name, command):
return step(
name,
image = 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.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-c6f009914a378669-${{ 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: "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 run --rm \
-v "$PWD:/workspace" \
-w /workspace \
-v "$RUNNER_TEMP/starci-cache/bun:/root/.bun/install/cache" \
oven/bun:1 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-bbcb3fc8d6ed8a2d-${{ 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: "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 run --rm \
-v "$PWD:/workspace" \
-w /workspace \
-v "$RUNNER_TEMP/starci-cache/bun:/root/.bun/install/cache" \
oven/bun:1 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.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-c6f009914a378669-{{ 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
- restore_cache:
name: "Cache: bun"
keys:
- starci-cache-bun-
- run:
name: "check"
environment:
STARCI_RUN: |-
bun install --frozen-lockfile && bun run check
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
-v "$HOME/starci-cache/bun:/root/.bun/install/cache" \
oven/bun:1 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-c6f009914a378669-{{ 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-bbcb3fc8d6ed8a2d-{{ 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
- restore_cache:
name: "Cache: bun"
keys:
- starci-cache-bun-
- run:
name: "test"
environment:
STARCI_RUN: |-
bun install --frozen-lockfile && bun test
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
-v "$HOME/starci-cache/bun:/root/.bun/install/cache" \
oven/bun:1 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-bbcb3fc8d6ed8a2d-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
workflows:
ci:
jobs:
- check
- test
Download: pi-gamebook.ci.star, GitHub Actions, CircleCI