How to write CI/CD¶
Every Patina Network repo runs GitHub Actions along with TypeScript scripts powered by
tahminator/pipeline. This page serves to be
the baseline every new pipeline should follow.
You can find fully built examples at
Patina-Network/platform-infraPatina-Network/k8s-manifestsPatina-Network/codebloomPatina-Network/patchats
and more.
For deeper dives, see:
- Secrets: how to read a secret in a pipeline
- Deployments: tagging, CD, and how releases reach the cluster
- Automation: slash commands, bots, gated auto-merge
Directory layout¶
.github/
workflows/ # thin: trigger, permissions, job graph only
composite/<name>/action.yml # reusable step groups, `uses: ./.github/composite/<name>`
scripts/src/<name>/index.ts # the actual logic, called via `bun run`
Workflows stay declarative. Composite actions are the reusable "verbs".
Imperative logic (parsing PRs, hitting the GitHub API, running kustomize,
talking to Pulumi) lives in TypeScript under .github/scripts, not inline
run: blocks. See .github/scripts/src/ in any of the four repos. This
makes the logic unit-testable; run bun run --cwd .github/scripts test as
an explicit step early in the job, right after the shared setup action,
before anything else in the pipeline executes.
Baseline conventions¶
Every workflow file should have:
- A schema comment for editor validation, as the first line:
# yaml-language-server: $schema=https://raw.githubusercontent.com/SchemaStore/schemastore/refs/heads/master/src/schemas/json/github-workflow.json
Every workflow in platform-infra and k8s-manifests has this.
codebloom/patchats are inconsistent; add it to new files regardless
of what the rest of the repo does.
- A
run-namethat includes the actor's name, so the Actions tab is scannable without opening each run:
run-name: Running continuous integration on ${{ github.actor }}'s commits
- A
concurrencygroup that matches the semantics of the job: - Racy/cancelable work (CI on a branch, a PR's own checks) ->
group: ci-${{ github.ref }},cancel-in-progress: true. Pushing a new commit cancels the old commit's still-running pipeline instead of letting both finish, since only the latest commit's result matters. - Work that must never interleave (Pulumi apply, a shared staging
database) -> a single fixed group name,
cancel-in-progress: false, with a comment explaining why.platform-infra'scd.yamlusesgroup: cdbecause concurrentpulumi upruns would corrupt state.codebloom'smigrate-command.ymlusesgroup: staging-db-migrationsbecause every PR shares the same staging database. -
Single-flight environments (
patchatsdeploy-staging/deploy-prod) -> one fixed group per environment so a second deploy can't start mid-flight. -
Least-privilege
permissions, set at the workflow level and re-declared per job only where a job needs more.platform-infra'sci.yamlsetscontents: readat the top and only addspull-requests: writeon thepreviewjob andcontents: writeon thecreateTagjob. Thetestjob gets nothing beyond the default. Prefer this job-scoped style over grantingcontents: write, issues: write, pull-requests: write, checks: writefor the whole workflow the waycodebloom/patchatsdo. -
Call the shared setup action directly, no wrapper. Call
tahminator/pipeline/actions/setupstraight from the workflow:
- name: Setup
uses: tahminator/pipeline/actions/setup@4ee08420b0e0e291761d9c7d5e3983f5b3abbd39 # 1.0.88
with:
SECRETS: ${{ toJSON(secrets) }}
Tip
It is recommended that you keep all setup logic inside of .github/workflows/*.yaml instead
of moving the setup inside of .github/composite/*.yaml.
Leave the composite workflows for wiring together one or multiple scripts.
Warning
It is no longer recommended to wrap @tahminator/pipeline/actions/setup behind a composite like
.github/composite/setup-ci. It is too much of a hassle to keep them in sync.
Instead, if it is missing functionality, ask someone on @Patina-Network/infra for help,
or fork tahminator/pipeline,
add it yourself, and open a PR back.
- Explicit
needs:gating. Nothing builds or deploys without its test job(s) passing first; every pipeline in all four repos forms a strict dependency tree (test->preview/createTag;backendPreTest/e2ePreTest->backendTests/frontendTests->buildImage->deploy).
CI shape (pull_request + push)¶
Standard shape, seen in patchats/.github/workflows/ci.yml:
on:
push:
branches:
- main
pull_request:
push is scoped to main only: a feature-branch push already triggers the
pull_request event, so an unscoped push trigger would run every job
twice per commit. Document that scoping decision in a comment the way
patchats does; it's not obvious from the YAML alone.
Job graph: *-pretest (fast, typecheck/lint) -> *-test (needs pretest) ->
build. Keep pretest fast and cheap so a broken build fails in seconds, not
after a multi-minute test suite runs.
Checklist for a new pipeline¶
- [ ]
$schemacomment on line 1 - [ ]
run-namewith${{ github.actor }} - [ ]
concurrencygroup whosecancel-in-progressmatches the job's actual safety requirements - [ ]
permissionsdeclared per job, not blanketwriteat the top - [ ] shared setup action pinned to a commit SHA for each job
- [ ] jobs that rely on other jobs to pass has
needs: - [ ] logic lives in
.github/scripts, not inlinerun:blocks (exceptions can be made, but not for a majority)
Examples¶
| Repo | File | Shows |
|---|---|---|
platform-infra |
ci.yaml |
$schema comment, job-scoped permissions, tag creation |
platform-infra |
cd.yaml |
serialized tag-triggered CD, pulumi up |
hello-world-grpc-service |
ci.yaml / cd.yaml |
minimal tag-triggered CD, image promotion to a tag |
k8s-manifests |
ci.yaml |
manifest linting pipeline |
k8s-manifests |
merge-command.yml + OWNERS.yaml |
OWNERS-gated auto-merge |
codebloom |
ci-cd.yml |
secrets passthrough, pre-deploy DB schema validation gate |
codebloom |
migrate-command.yml |
slash-command-driven DB migration |
patchats |
deploy-staging.yml |
pretest -> test -> build -> migrate -> update-tag pipeline |
patchats |
update-tag composite |
bumping the image tag in k8s-manifests for GitOps |