polyglot¶
Per-language checks, chosen by which files changed.
One repository, several languages: run each language's checks only when files of that language changed.
flowchart LR
s0["python"]
s1["go"]
s2["typescript"]
s3["shell"]
s4["docker"]
The steps this script plans for a push about which nothing is known. An arrow is a needs.
# One repository, several languages: run each language's checks only when
# files of that language changed.
#
# The rules are a table. Adding a language is adding a row.
RULES = [
# (name, file endings, image, command)
("python", (".py", "pyproject.toml", "uv.lock"), "python:3.13-slim", "pip install -q ruff && ruff check ."),
("go", (".go", "go.mod", "go.sum"), "golang:1.26", "go vet ./... && go test ./..."),
("typescript", (".ts", ".tsx", "package.json"), "node:22-bookworm-slim", "npm ci && npx tsc --noEmit"),
("shell", (".sh",), "koalaman/shellcheck-alpine:stable", "shellcheck $(find . -name '*.sh')"),
("docker", ("Dockerfile",), "hadolint/hadolint:latest-debian", "hadolint $(find . -name Dockerfile)"),
]
def ci(ctx):
steps = []
for name, endings, image, command in RULES:
# With no list of changes to go on, check everything.
if not ctx.changed_files or any([f.endswith(endings) for f in ctx.changed_files]):
steps.append(step(name, image = image, run = command))
return steps
# Generated by `starci compile` from polyglot.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 decides by which files a commit changed. A workflow file
# cannot, so it does what the script does when nothing is known about the
# changes, on every run.
# - 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:
python:
name: "python"
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-python-9cd9555497a86ebc-${{ hashFiles('**', '!.git/**') }}
- name: "python"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
pip install -q ruff && ruff check .
run: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
python:3.13-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"
go:
name: "go"
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-go-a6ed0c0d4c4c1961-${{ hashFiles('**', '!.git/**') }}
- name: "go"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
go vet ./... && go test ./...
run: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
golang:1.26 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"
typescript:
name: "typescript"
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-typescript-20f160b2667a77d7-${{ hashFiles('**', '!.git/**') }}
- name: "typescript"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
npm ci && npx tsc --noEmit
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"
shell:
name: "shell"
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-shell-400dcea7cb647b17-${{ hashFiles('**', '!.git/**') }}
- name: "shell"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
shellcheck $(find . -name '*.sh')
run: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
koalaman/shellcheck-alpine:stable 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"
docker:
name: "docker"
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-docker-73caaf3580179f71-${{ hashFiles('**', '!.git/**') }}
- name: "docker"
if: steps.passed.outputs.cache-hit != 'true'
env:
STARCI_RUN: |-
hadolint $(find . -name Dockerfile)
run: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
hadolint/hadolint:latest-debian 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 polyglot.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.changed_files, 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:
python:
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-python-9cd9555497a86ebc-{{ 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: "python"
environment:
STARCI_RUN: |-
pip install -q ruff && ruff check .
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
python:3.13-slim sh -c "$STARCI_RUN"
- run:
name: "Remember this pass"
command: |
mkdir -p ~/starci-passed && date > ~/starci-passed/at
- save_cache:
key: starci-passed-python-9cd9555497a86ebc-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
go:
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-go-a6ed0c0d4c4c1961-{{ 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: "go"
environment:
STARCI_RUN: |-
go vet ./... && go test ./...
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
golang:1.26 sh -c "$STARCI_RUN"
- run:
name: "Remember this pass"
command: |
mkdir -p ~/starci-passed && date > ~/starci-passed/at
- save_cache:
key: starci-passed-go-a6ed0c0d4c4c1961-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
typescript:
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-typescript-20f160b2667a77d7-{{ 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: "typescript"
environment:
STARCI_RUN: |-
npm ci && npx tsc --noEmit
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-typescript-20f160b2667a77d7-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
shell:
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-shell-400dcea7cb647b17-{{ 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: "shell"
environment:
STARCI_RUN: |-
shellcheck $(find . -name '*.sh')
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
koalaman/shellcheck-alpine:stable sh -c "$STARCI_RUN"
- run:
name: "Remember this pass"
command: |
mkdir -p ~/starci-passed && date > ~/starci-passed/at
- save_cache:
key: starci-passed-shell-400dcea7cb647b17-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
docker:
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-docker-73caaf3580179f71-{{ 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: "docker"
environment:
STARCI_RUN: |-
hadolint $(find . -name Dockerfile)
command: |
docker run --rm \
-v "$PWD:/workspace" \
-w /workspace \
hadolint/hadolint:latest-debian sh -c "$STARCI_RUN"
- run:
name: "Remember this pass"
command: |
mkdir -p ~/starci-passed && date > ~/starci-passed/at
- save_cache:
key: starci-passed-docker-73caaf3580179f71-{{ checksum "/tmp/starci-inputs" }}
paths:
- ~/starci-passed
workflows:
ci:
jobs:
- python
- go
- typescript
- shell
- docker
Download: polyglot.ci.star, GitHub Actions, CircleCI