diamond¶
Steps that depend on each other. needs takes the step itself or its name.
flowchart LR
s0["build"]
s1["lint"]
s2["test"]
s3["package"]
s0 --> s1
s0 --> s2
s1 --> s3
s2 --> s3
The steps this script plans for a push about which nothing is known. An arrow is a needs.
# Steps that depend on each other. `needs` takes the step itself or its name.
#
# build
# / \
# lint test
# \ /
# package
#
# lint and test start together once build has passed. If either fails,
# package is skipped rather than run against something broken.
IMAGE = "node:22-bookworm-slim"
def ci(ctx):
build = step("build", image = IMAGE, run = "npm ci && npm run build")
lint = step("lint", image = IMAGE, run = "npm ci && npm run lint", needs = [build])
test = step("test", image = IMAGE, run = "npm ci && npm test", needs = [build])
package = step("package", image = IMAGE, run = "npm ci && npm pack", needs = [lint, test])
return [build, lint, test, package]
# Generated by `starci compile` from diamond.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:
build:
name: "build"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Has this already passed with these inputs?
id: passed
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/starci-passed
key: starci-passed-build-1f97bf004cbb6c20-${{ hashFiles('**', '!.git/**') }}
- name: "build"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
npm ci && npm run build
run: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
node:22-bookworm-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"
lint:
name: "lint"
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v4
- name: Has this already passed with these inputs?
id: passed
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/starci-passed
key: starci-passed-lint-d309b4ed71edb687-${{ hashFiles('**', '!.git/**') }}
- name: "lint"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
npm ci && npm run lint
run: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
node:22-bookworm-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
needs: [build]
steps:
- uses: actions/checkout@v4
- name: Has this already passed with these inputs?
id: passed
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/starci-passed
key: starci-passed-test-3dce010675ea0e57-${{ hashFiles('**', '!.git/**') }}
- name: "test"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
npm ci && npm test
run: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
node:22-bookworm-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"
package:
name: "package"
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- uses: actions/checkout@v4
- name: Has this already passed with these inputs?
id: passed
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/starci-passed
key: starci-passed-package-33c496384cdf1a14-${{ hashFiles('**', '!.git/**') }}
- name: "package"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
npm ci && npm pack
run: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
node:22-bookworm-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 diamond.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:
build:
machine:
image: ubuntu-2404:current
resource_class: medium
steps:
- checkout
- run:
name: "Identify the inputs"
command: |
git ls-files -s -- ':(top)' > /tmp/starci-inputs
- restore_cache:
name: Has this already passed with these inputs?
keys:
- starci-passed-build-1f97bf004cbb6c20-{{ 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: "build"
environment:
STARCI_RUN: |-
npm ci && npm run build
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
node:22-bookworm-slim sh -c "$STARCI_RUN"
- run:
name: "Remember this pass"
command: |
mkdir -p ~/starci-passed && date > ~/starci-passed/at
- save_cache:
key: starci-passed-build-1f97bf004cbb6c20-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
lint:
machine:
image: ubuntu-2404:current
resource_class: medium
steps:
- checkout
- run:
name: "Identify the inputs"
command: |
git ls-files -s -- ':(top)' > /tmp/starci-inputs
- restore_cache:
name: Has this already passed with these inputs?
keys:
- starci-passed-lint-d309b4ed71edb687-{{ 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: "lint"
environment:
STARCI_RUN: |-
npm ci && npm run lint
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
node:22-bookworm-slim sh -c "$STARCI_RUN"
- run:
name: "Remember this pass"
command: |
mkdir -p ~/starci-passed && date > ~/starci-passed/at
- save_cache:
key: starci-passed-lint-d309b4ed71edb687-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
test:
machine:
image: ubuntu-2404:current
resource_class: medium
steps:
- checkout
- run:
name: "Identify the inputs"
command: |
git ls-files -s -- ':(top)' > /tmp/starci-inputs
- restore_cache:
name: Has this already passed with these inputs?
keys:
- starci-passed-test-3dce010675ea0e57-{{ 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: "test"
environment:
STARCI_RUN: |-
npm ci && npm test
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
node:22-bookworm-slim sh -c "$STARCI_RUN"
- run:
name: "Remember this pass"
command: |
mkdir -p ~/starci-passed && date > ~/starci-passed/at
- save_cache:
key: starci-passed-test-3dce010675ea0e57-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
package:
machine:
image: ubuntu-2404:current
resource_class: medium
steps:
- checkout
- run:
name: "Identify the inputs"
command: |
git ls-files -s -- ':(top)' > /tmp/starci-inputs
- restore_cache:
name: Has this already passed with these inputs?
keys:
- starci-passed-package-33c496384cdf1a14-{{ 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: "package"
environment:
STARCI_RUN: |-
npm ci && npm pack
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
node:22-bookworm-slim sh -c "$STARCI_RUN"
- run:
name: "Remember this pass"
command: |
mkdir -p ~/starci-passed && date > ~/starci-passed/at
- save_cache:
key: starci-passed-package-33c496384cdf1a14-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
workflows:
ci:
jobs:
- build
- lint:
requires: [build]
- test:
requires: [build]
- package:
requires: [lint, test]
Download: diamond.ci.star, GitHub Actions, CircleCI