placement¶
worker, prefer and avoid.
Saying where steps may run.
flowchart LR
s0["test"]
s1["benchmark"]
s2["migrate staging"]
The steps this script plans for a push about which nothing is known. An arrow is a needs.
# Saying where steps may run.
#
# worker the step runs only on a worker with these labels
# prefer it would like such a worker, and takes another if none is free
# avoid it never runs on a worker with these labels
#
# Workers advertise labels when they start: STARCI_LABELS=network=home,speed=fast
def ci(ctx):
return [
# Anything that runs code from a pull request stays off the home network.
step("test", image = "alpine:3", run = "./scripts/test.sh", avoid = {"network": "home"}),
# Heavy, but not picky.
step("benchmark", image = "alpine:3", run = "./scripts/bench.sh", prefer = {"speed": "fast"}),
# Needs to reach the staging database, which only one site can.
step("migrate staging", image = "alpine:3", run = "./scripts/migrate.sh", worker = {"site": "office"}, cache = False),
]
# Generated by `starci compile` from placement.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:
# - `prefer` and `avoid` have no equivalent here and are dropped (test,
# benchmark). `worker` becomes runner labels.
# - 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:
test:
name: "test"
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-test-234d278c02bd2642-${{ hashFiles('**', '!.git/**') }}
- name: "test"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
./scripts/test.sh
run: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
alpine:3 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"
benchmark:
name: "benchmark"
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-benchmark-fdbe6488f44082da-${{ hashFiles('**', '!.git/**') }}
- name: "benchmark"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
./scripts/bench.sh
run: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
alpine:3 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"
migrate-staging:
name: "migrate staging"
runs-on: ["self-hosted", "site=office"]
steps:
- uses: actions/checkout@v4
- name: "migrate staging"
env:
STARCI_RUN: |-
./scripts/migrate.sh
run: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
alpine:3 sh -c "$STARCI_RUN"
# Generated by `starci compile --target circleci` from placement.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:
# - `worker`, `prefer` and `avoid` have no equivalent here and are dropped
# (test, benchmark, migrate staging): CircleCI chooses machines by resource
# class, not by label. Every job uses medium.
# - Passes are remembered in this project's CircleCI cache, which expires.
# starci's own store does not.
version: 2.1
jobs:
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-234d278c02bd2642-{{ 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: |-
./scripts/test.sh
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
alpine:3 sh -c "$STARCI_RUN"
- run:
name: "Remember this pass"
command: |
mkdir -p ~/starci-passed && date > ~/starci-passed/at
- save_cache:
key: starci-passed-test-234d278c02bd2642-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
benchmark:
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-benchmark-fdbe6488f44082da-{{ 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: "benchmark"
environment:
STARCI_RUN: |-
./scripts/bench.sh
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
alpine:3 sh -c "$STARCI_RUN"
- run:
name: "Remember this pass"
command: |
mkdir -p ~/starci-passed && date > ~/starci-passed/at
- save_cache:
key: starci-passed-benchmark-fdbe6488f44082da-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
migrate-staging:
machine:
image: ubuntu-2404:current
resource_class: medium
steps:
- checkout
- run:
name: "migrate staging"
environment:
STARCI_RUN: |-
./scripts/migrate.sh
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
alpine:3 sh -c "$STARCI_RUN"
workflows:
ci:
jobs:
- test
- benchmark
- migrate-staging
Download: placement.ci.star, GitHub Actions, CircleCI