branches¶
Publish from main only; cache = False for steps with effects.
Different work for different branches.
Amber steps have effects outside the run, so a pass is never reused. Pause it, or step through it, with the controls.
# Different work for different branches.
#
# Everything is checked everywhere. Only main publishes, and a publish is
# never reused from an earlier run: it has an effect outside its inputs.
IMAGE = "node:22-bookworm-slim"
def ci(ctx):
test = step("test", image = IMAGE, run = "npm ci && npm test")
steps = [test]
if ctx.ref == "main":
steps.append(step(
"publish",
image = IMAGE,
run = "npm ci && npm publish",
needs = [test],
cache = False,
))
elif ctx.ref.startswith("release/"):
steps.append(step("changelog", image = IMAGE, run = "npm run check-changelog", needs = [test]))
return steps
# Generated by `starci compile` from branches.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:
# - The script looks at the branch. Whether it is main carries over; any other
# rule about branch names does not, and every other branch is treated alike.
# - 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-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"
publish:
name: "publish"
runs-on: ubuntu-latest
needs: [test]
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' }}
steps:
- uses: actions/checkout@v4
- name: "publish"
env:
STARCI_RUN: |-
npm ci && npm publish
run: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
node:22-bookworm-slim sh -c "$STARCI_RUN"
# Generated by `starci compile --target circleci` from branches.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:
# - The script reads ctx.ref, so its plan depends on the commit. This file is
# the plan for a commit about which nothing is known, and is the same for
# every push: steps the script would add or drop for a particular branch or
# set of changed files are not represented.
# - 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-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
workflows:
ci:
jobs:
- test
Download: branches.ci.star, GitHub Actions, CircleCI