Skip to content
Latchkey home
Documentation menu

Run your workflow file on Latchkey

The Latchkey workflow file: the keys it accepts, the keys it refuses by name and why, where the file lives, and what happens when you push.

In short

  1. Commit a workflow under .latchkey/workflows/<name>.yml, in the shape you already know from GitHub Actions, with uses: for Latchkey's own steps only.
  2. Latchkey refuses a file rather than running it with a key ignored. One refusal per push: the first refused key in the file, named exactly as you wrote it, with its line, or the file or directory where the refusal is about the whole of it.
  3. runs-on: names a Latchkey size, so the runs-on: ubuntu-latest in a copied file becomes runs-on: small.
  4. Checkout is automatic and the runner image carries twelve language toolchains, so actions/checkout goes away, and an actions/setup-* step goes away or becomes a Latchkey setup step that picks a version.
  5. environment: and a Latchkey step's with: input can be a map of branches, such as main: production above "**": staging; the first key that matches the run's branch chooses.

The promise#

Latchkey runs your workflow file. Commit a workflow under .latchkey/workflows/, one file per workflow, in the shape you already know from GitHub Actions: jobs, steps with run:, env:, runs-on: naming a Latchkey runner size, timeout-minutes:, needs: to run a job after another, a matrix, and service containers under services:. Push, and Latchkey concludes a small fixed set of contexts on the run record and reports them as checks your branch protection can bind to. The file you commit keeps working unchanged in every later release.

Branch protection can require the Latchkey and Latchkey / plan contexts, and a job's own check such as Latchkey / ci.yml / test, but do not require any of them yet: a check Latchkey cannot write stays absent, and a required absent check blocks the merge. A job's own check is also absent when a push does not match its workflow file, for a job past a run's first 20, and, on a run's first attempt, for a job that ended without starting because a newer run joined its concurrency group, or that was skipped only because the jobs it needed ended or were skipped that way. Latchkey / plan reports Latchkey's own stops as failures, and a job's own check asks for action on them, so requiring either would block merges on Latchkey's faults.

On a pull request, the Latchkey / plan check also lists what the change does to the plan against the newest run of the base branch: jobs added, removed, renamed and changed, an estimated change in what a run costs, and the job check names it adds or removes. It changes nothing the check concludes; merging the pull request is approving its plan. A merge group's plan check carries no such list, since each pull request in the group showed its own. Nor does the plan check of a fork's pull request, or of a commit whose files were refused, which carries the refusal.

A neutral Latchkey check means Latchkey did not verify this commit. Your code neither passed nor failed: something stopped the run before your jobs could decide, and the check text says what stopped it. A neutral check does not block a merge, so branch protection lets the pull request through even though nothing was verified. A neutral Latchkey check whose title starts with Advisory is different: the repository is in advisory mode or the result is a pipeline on trial's, and the title and the check text say what really happened.

Try Latchkey CI beside your current CI#

Move CI to Latchkey, under Migrate in the dashboard, enrolls a repository in advisory mode. Latchkey runs its workflow file and records every result as usual, but a failure is written to your code host as a neutral check whose title names the real outcome, such as Advisory: failed. No Latchkey check fails, and none blocks a merge. A repository already on Latchkey CI stays on it: each pipeline you move from then on runs on trial, where its failure fails no check, until you switch it. A pipeline written by hand that Latchkey does not record as replacing a GitHub Actions workflow also runs on trial on a commit that holds a moved pipeline's GitHub Actions file but not its Latchkey workflow file.

Compare the two results commit by commit on the Side by side step or the Runs page. A repository whose Latchkey workflow files were written by hand, with no apply, reaches Side by side from Connect once an owner or admin has answered Connect's question. When you trust Latchkey CI, choose Switch to Latchkey CI: a repository in advisory mode leaves it, and from then on a Latchkey CI failure fails its check, unless its pipeline is on trial.

Connect asks an owner or admin which GitHub Actions files the repository's Latchkey workflow files replace, and by which file. Latchkey keeps the answer with the files each apply was made from, and that record decides two things: while a commit still holds one of those files, the pipeline that replaces it is on trial, and Switch to Latchkey CI removes them. A repository with no apply cannot switch until the question is answered. Side by side compares each recorded file with the Latchkey workflow file that replaces it, so while no file in the answer has its replacement named, there is nothing to compare and the switch waits: name one on Connect. When the answer is that they replace none, there is nothing to compare, and switching opens no pull request: it takes a repository in advisory mode out of it or, for one already on Latchkey CI, records the switch. A workflow that stays on GitHub Actions and runs on: workflow_run after a workflow the switch removes stops running once the switch pull request is merged: GitHub Actions starts it only after its own runs of that workflow, and Latchkey CI's runs never start it. So does one that runs only after workflows that stop, as far as GitHub Actions chains them. One with a trigger of its own, or that also runs after a workflow that keeps running, runs less often instead. The switch pull request names each such workflow first; to keep its work, move it into the Latchkey workflow file that replaces the removed workflow it runs after, as a job with needs:.

Do not require a Latchkey check while the repository is in advisory mode: a neutral check satisfies a required one, so a failing commit would merge. After you switch, do not require them yet either, for the reasons under The promise. Before you merge the switch pull request, take out of branch protection any check that comes from a workflow it removes: that check never reports again, so it would block the merge.

What runs today#

In this release a workflow file gives you jobs, steps that run one at a time, env:, a runner size, a timeout, a matrix, service containers, jobs that wait for other jobs with needs:, values a job hands to the jobs that need it with outputs:, jobs that wait for an owner or admin to approve the run with environment: (unless the environment needs none), runs and jobs that take turns in a group with concurrency:, and dry runs or held deploy jobs during a trial run with advisory:. A step can read a secret set in Latchkey for its job's environment, this repository or its workspace: write ${{ secrets.NAME }} as the whole value of a variable in that step's env:, and Latchkey hands the value to that step when it starts. An environment secret wins over a repository secret of the same name, and a repository secret wins over a workspace one; a name set at none of the levels its job can see refuses the run before any job starts, and a run of a pull request from a fork is handed no secrets. A run of a fix self-heal proposed on its own branch is handed them only when the fix changes no workflow file. In a run handed no secrets, the steps that name one are not run. A value shorter than 28 bytes is never delivered, because the log could not hide it.

Where the file lives#

One file per workflow under .latchkey/workflows/. .yml is the canonical spelling and .yaml is read too, so a file copied out of .github/workflows/ keeps its extension. Renaming a workflow file starts a new pipeline; the runs under the old name stay under it.

.latchkey/workflows/ci.yml
name: CI

on:
  push:
    branches: [main]
  pull_request:

latchkey:
  schema: 1

jobs:
  test:
    runs-on: small
    timeout-minutes: 20
    env:
      NODE_ENV: test
    steps:
      - name: Install dependencies
        run: npm ci
      - name: Run the suite
        run: npm test

Choosing a runner#

runs-on: valuevCPUMemoryDisk
small or latchkey-small28 GB100 GB
medium or latchkey-medium416 GB100 GB
large or latchkey-large832 GB100 GB
xlarge or latchkey-xlarge1664 GB200 GB

Every job names a runs-on:. Both spellings are accepted and name the same runner, so a runs-on: line copied from a Latchkey Actions workflow works unchanged. The line a copied GitHub-hosted file usually carries is runs-on: ubuntu-latest; Latchkey is not GitHub-hosted and will not map that name to a size silently, so change it to runs-on: small, or to the size the job needs. All runners are Ubuntu 24.04 LTS on x86_64; see Limits and concurrency for what each size gives you.

What we do not emulate#

Latchkey does not run GitHub actions. A uses: step runs one of Latchkey's own steps, written uses: latchkey/<name>@<version> (see Latchkey steps). Any other uses: is refused. In its place: checkout is automatic (the runner clones your repository at the commit with a per-job token, or with none for a released fork), actions/cache is latchkey/cache-restore and latchkey/cache-save, aws-actions/configure-aws-credentials is latchkey/aws-login, the setup actions are the image's own toolchains (Node, Python, Go, Rust, Java are on the standard runner image), with latchkey/setup-node, latchkey/setup-go and latchkey/setup-java to pick another version the image carries and latchkey/setup-python for a Python that a plain pip install installs into, actions/upload-artifact and actions/download-artifact are latchkey/artifact-upload and latchkey/artifact-download, and a third-party action becomes a run: step. We do not promise an Actions-compatible runtime, and we will not.

The toolchains are already there#

The standard runner image carries Python, Node, Go, Java, Rust, Ruby, PHP, .NET, Haskell, Swift, Kotlin and Julia, and the image build fails if any of the twelve is missing. A uses: actions/setup-* step needs no replacement when the default version suits you: delete it and call the tool. To pick another version the image carries, write uses: latchkey/setup-node@1.0.1, latchkey/setup-go@1.0.0 or latchkey/setup-java@1.0.0. Python is the exception when a step runs pip install: the image's own Python refuses one, so write uses: latchkey/setup-python@1.0.0, which makes a virtual environment for it to install into.

The checkout#

The runner clones your repository at the pushed commit before your first step runs, so a workflow file needs no checkout step. A pull request from a fork runs only once released, and its commit is fetched from this repository's own address with no token at all. The clone is shallow and carries no tags, which is the same default the vendor's own checkout action uses. A step that needs history, tags or another branch fetches them itself: git fetch from the workspace's origin reaches this repository with the job's read-only token, which reads this repository alone, cannot push and expires within the hour, so a long job fetches early. A job running a pull request from a fork has no token, so its fetches carry none. A step that sets up its own git credentials, for example to push or to reach another private repository, keeps them, and git may then fetch this repository with those instead.

How a job runs#

Latchkey runs a job's steps one at a time, in file order, each as its own bash --noprofile --norc -e -o pipefail script started in the job's workspace with the job's environment. A step stops at its first failing command, and a command that fails inside a pipeline fails the pipeline. Once a step fails, a later step runs only when its if: asks for failure() or always(), and the job fails with the first failing step's exit code. A cd or an export in one step does not carry into the next. A variable in a step's env: does carry. Latchkey merges the workflow's, the job's and every step's env: into one environment for the job, so a variable a step sets applies to every step of the job, the steps before it included, and when two steps set the same variable, the later value applies to all of them. Only a secret stays with its step: Latchkey hands it to the step that names it and to no other.

Because each step is its own script in its own process group, a step that ends its own shell or process group, for example with kill $$ or kill 0, ends that step only: the step fails with exit code 143 and a later failure() or always() step still runs. Each step's script is also read on its own, so a step that does not parse fails alone with exit code 2 and every later step its if: admits still runs; a job whose own if: does not hold runs none of its steps, parseable or not. And each step's script is written to the job's temporary directory ($RUNNER_TEMP) when that step starts, so a step that removes that directory or the job's working directory, or otherwise takes away what the next step needs to start, stops the job at the next step: that step does not start, no later step runs, not even an always() step, and the job fails without an exit code.

if: accepts success(), failure() and always(), and == tests on a matrix value, an env value, an output of a job it needs, or the result of a job it needs, needs.<job>.result. Join them with && or with ||; to use both, put each || group in parentheses inside the && chain, one level deep, as the test job does here:

yaml
on:
  push:
  pull_request:
jobs:
  build:
    runs-on: small
    steps:
      - run: make build
  lint:
    if: env.LATCHKEY_CI_EVENT_CLASS == 'pr_update'
    runs-on: small
    steps:
      - run: make lint
  test:
    needs: [build, lint]
    if: always() && needs.build.result == 'success' && (needs.lint.result == 'success' || needs.lint.result == 'skipped')
    runs-on: small
    steps:
      - run: make test

An if: outside that set is refused by name rather than evaluated to something Latchkey guessed at. Each == test compares text, so write the value in quotes, as in matrix.shard == '1'. A matrix value is the text its list gives, so '1' matches the leg whose shard is 1; an unquoted number, true, false or word is refused. A job whose own if: does not hold is skipped: its steps do not run, and the run's checks count it as skipped, neither passed nor failed.

To run a job only on a branch or an event, compare a run variable with a quoted value in the job's if:. LATCHKEY_CI_REF is the full ref: refs/heads/<branch> on a branch push or a scheduled run, refs/tags/<tag> on a tag push, refs/pull/<number>/head on a pull request, the queue branch refs/heads/gh-readonly-queue/<branch>/... on a merge group, and the branch or tag in full on a manual run. LATCHKEY_CI_EVENT_CLASS is branch_push, tag_push, pr_update, merge_group, schedule or workflow_dispatch. A test of a run variable against a value written another way, such as env.LATCHKEY_CI_EVENT_CLASS == 'push' or env.LATCHKEY_CI_REF == 'main', is refused by name: write an event as one of the words above, in lower case, and a ref in full, as in refs/heads/main. So a job with if: env.LATCHKEY_CI_REF == 'refs/heads/main' runs on a push to main, on a scheduled run on main and on a manual run started on main, never on a pull request or a merge group. Put such a test on the job, not on a step: when a branch moves to a commit that already has a run, a job its if: skipped can run again in a new attempt, as What a failed job means for you below says, and a step its if: skipped cannot. LATCHKEY_CI_BASE_REF and the other run variables are listed under The environment Latchkey sets below.

When Latchkey can already answer a job's if: as the run starts, for example a test of a matrix value, of a value the file's own env: sets, or of a run variable such as LATCHKEY_CI_REF, the job is skipped before it starts: no runner is spent on it, and it is not billed. A job whose if: only its runner can answer starts as before, and its time on the runner is billed.

Jobs that need other jobs#

A job with needs: starts after every job it names has passed, or, when its own if: names failure() or always(), once every one of them has ended and its if: holds. Name one job (needs: build) or several (needs: [build, test]) by their keys under jobs:, in the same file. A matrix job has passed when every one of its legs has. A job with no needs: does not wait for another job to pass, though its concurrency group can still hold it for its turn. A job still waiting for the jobs it needs 24 hours after it was queued is stopped, and its tile reads "Stopped". If a job it needs ended without passing by then, and its own if: names neither, it is skipped instead.

While it waits, the job's tile on the run page names the jobs it is still waiting for ("Waiting for build."). When a job it needs fails, is cancelled or is skipped, a job whose own if: names neither failure() nor always() is skipped before it starts: the run's checks count it as skipped, neither passed nor failed, no runner is spent on it, and its tile says which ("Skipped: a job it needs failed."). Skipping runs down the chain: a job that needs a skipped job is skipped too, unless its own if: names failure() or always() and holds once its needs have ended.

app.latchkey.dev / acme / runs / ci

A run of the workflow ci on acme/api with four jobs, on the run page. build and lint are running; test waits with its tile reading Waiting for build., and deploy reads Waiting for test. lint passes, then build passes and test starts. test fails with Failed. Exit code 1., so deploy is skipped before it starts: its tile reads Skipped: a job it needs failed. and needs test (failed), and the line into it turns dotted. The run fails: the Latchkey / plan check passed with Compiled 4 jobs from 1 workflow file., the Latchkey check failed with 1 of 4 jobs failed: test. 1 job skipped., the advisory Latchkey / tests check reads Not run, and Cancel run becomes Re-run jobs that did not pass.

FIG. 8.1-AA job starts only after every job it needs has passed. When one fails, everything that needs it is skipped without spending a runner, and the tile says why.

On a job with needs:, a job-level if: is read only once the jobs it needs have ended. Without failure() or always(), the job runs only when every job it needs succeeded, whatever else its if: tests. failure() there holds when a job it lists failed or expired, and always() whatever they ended as. needs.<job>.result is how a job it lists ended: success, failure (an expired job included), cancelled or skipped. All of these read only the jobs this job lists, not the jobs those need, where GitHub's failure() and its default success test read those too. A cancelled run ends every job that has not started, always() jobs included, where GitHub still runs them.

Jobs that wait for an approval#

A job can name an environment with environment: in one of three forms. The first is one plain name, such as environment: production: the name starts with a letter or a digit and then uses letters, digits, ., _ and - only, up to 64 characters, and case counts, so Production and production are two environments. The second is a whole ${{ matrix.<axis> }}, so each leg of a matrix names its own environment from its value. The third is a map of branches, which chooses the name by the run's branch. The GitHub Actions mapping with name: and url:, a list and any other expression are each refused by name.

yaml
on:
  push:
jobs:
  deploy:
    runs-on: small
    environment:
      main: production
      "**": staging
    steps:
      - run: ./deploy.sh

Each key of a map of branches is one branch pattern, as branches: under on: push takes them but never starting with !, and each value is a plain name. The first key, in the file's order, that matches the run's branch chooses: a push chooses by its own branch, a pull request and a merge group by the branch they target, a scheduled run by the default branch, and a manual run by the branch it was started on. So "**" as the last key covers every branch the keys above it do not, and a key that a key above it already covers, or any key after "**", is refused, since it could never be chosen. Patterns that overlap are not refused: with release/** above release/beta*, the upper key wins on every branch both match. A tag push keys on no branch and matches no key. When a push and a pull request arrive at one commit, they share one run, and its first attempt chooses by whichever arrived first. The same map chooses an input's value under a Latchkey step's with: (see Latchkey steps).

When a job would run on a branch that no key of its map matches, the whole run is refused before any job starts: the Latchkey check names the file, the job, the key and the branch, and this commit runs nothing more for four days, on any branch. A job needs no key when its own if: is false for the run, or when a job it needs, directly or through others, is skipped when the run is planned. To clear the refusal, add a key for the branch or a last "**" key, or move the job into a file whose on: names only the map's branches, and push a new commit. Until an if: can test one of several branches, a file that runs its tests on every branch and deploys from two of them is two files: one whose on: push takes every branch, for the tests, and one whose on: push names the two branches, for the deploy. The same holds for the branch self-heal pushes to verify a fix, latchkey/heal-*: in a file whose on: push takes every branch, a job with a map and no key for it refuses that verification run, and the heal pull request says so.

A job that names an environment waits, in every run that reaches it, until an owner or admin of the workspace approves or rejects that run for that environment, unless the environment is set to need no approval (see below). That includes runs Latchkey starts itself, such as the run that checks a fix self-heal proposed. A re-run asks again. One decision covers every job of the run that names that environment, every leg of a matrix included. A matrix whose environment: is ${{ matrix.<axis> }} asks one decision for each environment its legs name. The run's other jobs go on meanwhile, and a job that needs a waiting job waits with it.

An owner or admin approves or rejects from the run page's Approval panel; a member sees the same panel without the buttons. An agent or a script decides through the Jobs API, with POST /jobs/{id}/approval on any of the waiting jobs and {"decision": "approve"} or {"decision": "reject"}, using a key created with Allow approving runs for an environment, which works only while the person who created it is an owner or admin. The person who pushed the commit can decide like any other owner or admin. A decision cannot be taken back.

An approval sends the jobs on to run, and only an approved job, or one whose environment needs no approval, is handed the secrets set for its environment. A rejection ends each of them without starting it, and the jobs that need them are skipped. Where an approval is required, a run nobody decides within 24 hours ends the same way. Neither is billed, and neither counts as a failure of your code: the jobs read Stopped, and a run with no failing job concludes neutral, so its Latchkey check does not block a merge.

An owner or admin can set which branches may use an environment, in Settings, Environments. A job that names an environment with branches set goes on only in a run on one of those branches: there it waits for its approval, or starts without one when the environment needs none. In any other run, including a run of a tag and one Latchkey started for a pull request's own ref, it ends without starting and without asking for an approval, and the jobs that need it are skipped. It is not billed, and it never fails the run's Latchkey check. A scheduled run is judged by the default branch it runs on, and each run and each re-run reads the branches when it starts and again when an approval would release one of its jobs. The patterns are the ones branches: under on: push takes: main, release/*, and !release/old after it to leave one out. An environment with no branches set accepts every branch, and its jobs always wait for an approval. Only an environment with branches set can be set to need no approval. Its jobs then start as soon as a run on one of its branches reaches them, with its secrets and an identity token in the environment form, and nobody is asked; a job already waiting on one of those branches starts within about a minute, and setting approval back never stops a job already released. Its branches cannot be cleared until it requires an approval again. No workflow file and no API key can change these settings; latchkey environments list and the list_environments MCP tool read them.

For a pull request, a map of branches and an environment's branches read different refs. A pull request into main takes the key for main, but the environment's branches are judged against the pull request's own ref: if they are main alone, that job ends without starting, and if the environment has no branches set, its approval is asked to run the pull request's code. To keep pull requests off such a job, gate it with if: env.LATCHKEY_CI_EVENT_CLASS == 'branch_push'. A merge group is judged the same way: it takes the key for the branch it targets, and the environment's branches are judged against its queue branch, so a job of a group runs in an environment only when the environment's branches include the queue, such as gh-readonly-queue/main/*.

Every environment a file names waits for an approval on a branch it accepts, unless an owner or admin has set it to need none. Reviewer lists and wait timers are not supported yet: an environment is the name a workflow file writes, with its secrets set in Settings, Secrets and its branches and its approval in Settings, Environments. A job whose environment Migrate carries keeps it, so on Latchkey CI the job waits for an approval once its pipeline runs live, whether or not its GitHub environment requires a reviewer, unless that environment's settings in Settings, Environments say otherwise. The Plan step says so under each such job.

Concurrency groups#

concurrency: puts a run of the workflow file, or one job, in a group that one holder uses at a time. Write it at the top of the file for all of the file's jobs in a run, or on a job for that job alone, either as a group name or as a mapping with group: and an optional cancel-in-progress: false. A group name is plain text of 1 to 128 bytes and may use ${{ github.workflow }} and ${{ github.ref }}. A group is shared by every workflow file of the repository, never across repositories, and on a job each matrix leg takes the group by itself.

While a run or a job holds its group, a newer one waits: its jobs park before they ask for an approval or a runner, so nothing of it runs. The holder keeps the group until it has nothing left running or waiting, and Latchkey never cancels it or cuts it off, so cancel-in-progress: true is refused. When a newer run joins a group that an older one is waiting in, the older one ends without starting, and when the holder lets go, the group goes to the newest run waiting in it. As on GitHub Actions, a re-run of an older commit counts as newer. Jobs of one run take turns in a group rather than replace each other. A job that has waited in its group for 24 hours is stopped, and queue time is never billed. While a whole run waits for the group of its file, the Runs page and its run page show it as "Waiting for" followed by the group name in place of "Running", and each of its jobs that waits in the group names it.

Trial runs and dry runs#

A run is a trial run while its repository is in advisory mode, or, once the repository has been through Connect on the Migrate page, until someone says which GitHub Actions files its Latchkey files replace. In a repository on Latchkey CI, while a GitHub Actions file that one of its Latchkey files replaces is still in the commit, that Latchkey file's pipeline is on trial. When the commit holds a GitHub Actions file Latchkey records as replaced but not the Latchkey file recorded as its replacement, each pipeline at the commit that Latchkey does not record as a replacement is on trial too, since one of them may be that file under another name. This holds whether the migration pull request that moved the file is still open or merged. The run's other pipelines run live, a job moved into one of them from a GitHub Actions file still in the commit included, and GitHub Actions can run that file too, so such a job can run in both places, and a deploy job can deploy twice. Latchkey never cancels or disables a GitHub Actions workflow to prevent this, so to keep such a job from running in both places, remove that file, or the job from it, on the branch GitHub Actions reads the file from: the commit's own branch for a push or a pull request, and the default branch for schedule, workflow_run, pull_request_target and the other events GitHub Actions runs from there. The run is a trial run when every pipeline it runs is on trial. Everything this page says a trial run does to a job, it also does to a job of a pipeline on trial. Every other run is live. A re-run of a trial run is a trial run too, a pipeline on trial stays on trial when its run is re-run, and both hold for a new attempt when a branch moves to its commit, whatever has changed since. A run on a new commit is judged afresh. When Latchkey cannot read the mode or those files, the run waits and reads them again, and if the fault lasts, the run ends as Latchkey's own fault, with none of your code run. In a trial run, advisory: decides what a deploy job does: it runs the dry run its file writes, or it is held and runs nothing. A job that is not held and has no dry run runs as written, its deploy included.

advisory: on a job is run or hold. In a trial run a held job runs nothing: it ends skipped, the run page and the Latchkey check say it was held, and the jobs that need it are held too. A job that names an environment: and writes no advisory: is held, and so is a job that writes no advisory: anywhere and whose every step can publish. Every other job runs in a trial run, with its steps chosen by the step key below.

A job of a live run whose pipeline runs live and that is still waiting when its repository is switched to advisory mode is held if a trial run would hold it, or if it has a dry run, because it was created to run live and its dry run cannot take its place.

advisory: on a step is skip or only. In a trial run a skip step is left out and an only step runs; once its pipeline runs live it is the other way around. A step with no advisory: runs in both. So a deploy job writes its dry run beside its deploy:

.latchkey/workflows/deploy.yml
name: Deploy

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: small
    environment: production
    advisory: run
    steps:
      - run: npm ci
      - run: npm run deploy
        advisory: skip
      - run: npm run deploy -- --dry-run
        advisory: only

A latchkey/npm-publish step can publish unless it sets dry-run: true, and a latchkey/docker-build-push step can publish when it sets push: true; a value Latchkey cannot settle when it reads the file, such as an expression, counts as one that can publish. A step that can publish is skip when it writes no advisory:, and it cannot be only. A job that writes advisory:, on itself or on a step, needs at least one step that runs in a trial run; when it would have none, write advisory: hold on it.

A job that names an environment and writes advisory: run still waits for its approval in a trial run unless the environment needs none, and then runs its dry run. A job has a dry run when one of its steps is skip or only, and its dry run is every step but its skip steps, so a step that deploys runs in it unless it is skip. Latchkey refuses a file in which a job names an environment and writes advisory: run with no dry run.

A job's identity token carries a sub that starts with advisory: in a trial run and when the job's pipeline is on trial, so a cloud role that trusts only live runs does not match it. The role a dry run signs in with lists that form, and should be able to read only. A secret named only by skip steps or by held jobs is handed to no job in a trial run.

Switching a repository to Latchkey CI removes the GitHub Actions files its Latchkey files replace, in one pull request, so after it merges each commit's deploy comes from one CI, unless GitHub Actions can still run a file whose deploy job a Latchkey file at the commit also runs.

The run page lists the jobs a trial run held and the ones that ran their dry runs and says why the run was a trial run, and the Latchkey check counts them. A live run that ran a pipeline on trial names that pipeline on its run page, with the GitHub Actions file that keeps it on trial, and its Latchkey check counts that pipeline's held jobs and dry runs.

Passing files between jobs#

A job hands files to the jobs that need it with the artifact steps. In the job that builds, uses: latchkey/artifact-upload@1.0.0 with name: dist and path: build/ packs the paths into one artifact under that name, and in a job that names it in needs:, uses: latchkey/artifact-download@1.0.0 with name: dist fetches the artifact and extracts it into the workspace, or into the directory into names (see Latchkey steps). In a run: step, latchkey artifact upload --name dist build/ and latchkey artifact download --name dist do the same after the CLI is installed (npm install -g @latchkeydev/cli). Either way, an upload leaves out files and directories whose names start with a dot, such as .git and .env, unless it is told to include them, and an upload that names one of them without that, or finds no regular file under its paths, fails. Both talk to the runner the job runs on, never to the Latchkey API, so they take no API key.

A job downloads only what the jobs it names in needs: uploaded. A name is uploaded once in each run attempt: another job's upload of the same name is refused, and a job that uploads a name again keeps its first upload, and its step fails if the new bytes differ. When you re-run a run, a job carried over from the earlier attempt keeps the artifacts it uploaded, and the jobs that need it download them. Unlike latchkey cache, a failed upload or download fails the step.

An artifact name has 1 to 128 characters, each a letter, a digit, a period, an underscore or a hyphen, and is never . or ... One artifact holds up to 2 GiB, one job uploads up to 20 artifacts and 5 GiB in all, and a workspace holds up to 20 GiB of artifacts that have not expired. An artifact is kept 7 days after it is uploaded, and until then the run page lists it and offers its download. Artifacts are not billed. A job of a pull request from a fork, and a job started with latchkey run, cannot use them.

Passing values between jobs#

A job hands a value to the jobs that need it with outputs:, a list of the names it records, each starting with a letter or _ and then using letters, digits and _ only, up to 128 characters. Its steps write each value as one name=value line to the file at $LATCHKEY_CI_OUTPUT, for example echo "tag=v1.2.3" >> "$LATCHKEY_CI_OUTPUT", and the last line written for a name is its value. Every step of the job writes the same file, so append with >>: a > would remove what the steps before it wrote. Latchkey CI records the values when the job succeeds.

A job reads an output of a job its own needs: lists as ${{ needs.<job>.outputs.<name> }}, in three places: one side of an equality in a job's or a step's if:, the whole value of a variable in a job's or a step's env:, and the whole value of a with: input. To use a value in a script, set it as a variable in the step's env:, and read that variable in run:. Like any variable in an env:, it is set for every step of the job.

A value read into a with: input is held to that input's rule before any step runs, as a value written in the file is.

A job whose if: reads an output is decided when its needs finish, never when the run is planned. When its condition is false then, the job is skipped before Latchkey CI takes a runner for it, and it is not billed.

Latchkey never reads a missing output as empty. A job that reads a value its need did not write, or one Latchkey CI did not record, ends without starting, and its page says which. So a job whose if: uses always() or failure() and reads an output ends without starting when the job it reads from did not succeed, where GitHub still runs it.

A value holding anything that job's log masks, such as a secret the job was given or a service setting of 28 bytes or more, is not recorded. A secret a step fetches for itself is unknown to Latchkey CI and would be recorded as written, so never write one to $LATCHKEY_CI_OUTPUT.

Latchkey CI records only the names a job lists under outputs:. Any other name a step writes to $LATCHKEY_CI_OUTPUT is dropped, and a file in which a job reads one is refused before any job starts.

The outputs a job reads join its environment, which holds at most what one job can hold, 64 variables and 32 KiB in all. A job records at most 1 MiB of outputs, and a job whose outputs would take its run attempt past 50 MiB of recorded outputs records none. Jobs that finish at the same moment are each measured without the others, so a run attempt can pass 50 MiB, by at most 1 MiB for each job beyond the first that finished at that moment.

When you re-run a run, a job carried over from the earlier attempt keeps the values it recorded, and the jobs that need it read them.

outputs: is not supported on a job with strategy.matrix, and neither are a step id: and step outputs, a value of more than one line (the << form), or an output anywhere but the three places above.

The environment Latchkey sets#

On a job Latchkey started from your workflow file, these names are exported for you:

NameValue
LATCHKEY_CI_RUN_IDThe run this job belongs to
LATCHKEY_CI_ATTEMPTThe attempt number, counting from 1
LATCHKEY_CI_REPOSITORY_IDLatchkey identifier for the repository
LATCHKEY_CI_PROVIDERThe git provider, for example github
LATCHKEY_CI_SHAThe commit the run is pinned to: on a pull request, its head commit
LATCHKEY_CI_REFThe ref as the provider delivered it
LATCHKEY_CI_ACTORWho triggered the run, or who created the API key that started it; empty on a scheduled run
LATCHKEY_CI_PR_NUMBERSPull requests carrying this commit, comma joined, at most 16, with a trailing + when there are more.
LATCHKEY_CI_FORKtrue when the pull request comes from a fork; such a job runs with no repository token, no cache, no secrets and no self-heal, and its steps reach only GitHub and a fixed set of public package registries, with no sudo, no Docker and no service containers
LATCHKEY_CI_BASE_REFThe base ref as a full refs/heads/ path: the base branch of a pull request or of a merge group, or, on a push, the push's own base_ref when the code host sends one. Empty otherwise.
LATCHKEY_CI_EVENT_CLASSThe normalized event that started the run
LATCHKEY_CI_REPOSITORYThe repository this run belongs to, as owner/name
LATCHKEY_INPUT_<NAME>An input the file declares under on: workflow_dispatch, by its name in capitals with - written as _: its value on a manual run, and empty text on any other run
LATCHKEY_CI_STEP_NUMBERThe number of the step that is running, counting from 1. Readable in the step's commands, not in its if:
LATCHKEY_CI_OUTPUTA file a step writes this job's outputs to, one name=value line each; the names under the job's outputs: are recorded when it succeeds

The repository's full name is exported as bare owner/name, never a URL. LATCHKEY_CI_REPOSITORY carries the repository's name as Latchkey last read it from your code host, so it changes when a rename reaches Latchkey. Every name beginning with LATCHKEY_ belongs to Latchkey, so a workflow file may not set one.

The latchkey: block#

One optional top-level block carrying exactly one member. Values are read as text, so schema: 1 and schema: "1" are the same file. A file with no latchkey: block is read as schema version 1. A block that is present must carry schema: and nothing else.

When the file runs#

on: accepts push, with optional branches: and tags:, pull_request, with optional branches: and types:, merge_group, with optional branches: and types:, schedule, and workflow_dispatch, with optional inputs:. A bare on: push runs on branch pushes only; a tag push runs the file only when the push block names tags:. Under on: pull_request, branches: matches the base branch of the pull request and never its head ref. Under on: merge_group, branches: matches the branch the group targets, and types: may name only checks_requested.

Latchkey runs a pull request workflow on opened, synchronize and reopened, all three, always, so a types: list must name exactly those three or be left out.

With on: merge_group, Latchkey builds each group a GitHub merge queue makes, at the group's commit, and writes the same checks there as on a pull request, so the queue waits on the checks your branch protection already requires. Each queued pull request is built again in its group, and those minutes are billed like any run. A group the queue withdraws before merging has its unfinished jobs cancelled. A group no workflow file runs on gets a failing Latchkey / plan check, so a queue that requires it never merges a commit nothing built; in advisory mode that check is neutral and the queue is not held. Latchkey does not build the queue's own push to its branch, except for an organization that has not accepted the Latchkey app's merge queue permission: there that push runs the files whose on: push matches the queue branch. Self-heal opens no pull request from a group's run, since the queue's branch is not one a fix can be pushed to.

on: schedule takes a list of entries, each with one cron: in UTC, such as - cron: '0 3 * * *' for 03:00 UTC every day. A cron is five fields, minute, hour, day of month, month and day of week (0 is Sunday), each *, a number, a range, a step or a comma list of those, in numbers only. A schedule runs at most once every five minutes, and a file holds at most 20 entries. At each matching minute, Latchkey runs the file as committed at the head of the repository's default branch, so a schedule starts with the first push to the default branch that carries it. A minute Latchkey could not run within 30 minutes is skipped, not run late. A scheduled run writes no check on any commit; it shows on the Runs page with the event schedule.

If you require the Latchkey checks, a held pull request from a fork blocks the merge until a maintainer approves its commit or the change is pushed to a branch of this repository as a new commit.

Start a run on demand#

workflow_dispatch under on: lets a person or an agent start a run of that one file, on a branch or tag of this repository, with no push: a manual run. It can stand beside other triggers or alone. A file whose only trigger it is runs on no push, pull request or schedule.

.latchkey/workflows/deploy.yml
name: Deploy

on:
  workflow_dispatch:
    inputs:
      region:
        description: Where to deploy
        type: choice
        options: [us-east-1, eu-west-1]
        required: true
      dry-run:
        type: boolean
        default: true
      reason:
        description: Why this deploy runs

jobs:
  deploy:
    runs-on: small
    environment: production
    steps:
      - run: npm ci
      - run: ./deploy.sh "$LATCHKEY_INPUT_REGION" "$LATCHKEY_INPUT_DRY_RUN"
      - run: echo "$LATCHKEY_INPUT_REASON"

inputs: declares up to 25 inputs, each named by the rule a job's key follows: a letter or _, then letters, digits, - and _, up to 100 characters. An input may take description:, required:, default:, type: and options:, and any other key is refused by name. type: is string, which is what an input with no type: is, boolean or choice; any other type is refused, number included. A choice lists its options:, up to 100, each once, and its default: must be one of them. A boolean's default: is true or false. A description, a default and an option are each one line of plain text of at most 1,000 characters.

Every job of the file reads each input as the variable LATCHKEY_INPUT_ and its name in capitals, with - written as _, so dry-run is $LATCHKEY_INPUT_DRY_RUN. Two names that would make one variable are refused. That variable is the only way to read an input: ${{ inputs.region }} is refused by name. A job's if: can test it, as in if: env.LATCHKEY_INPUT_REGION == 'eu-west-1', and Latchkey answers that as the run starts, so a job it skips takes no runner and is not billed.

On a manual run an input's value is the one given, else the file's default, else false for a boolean and empty text otherwise. A required input with no default must be given, and empty text does not count as given. A value is one line of at most 1,000 characters. On any other run of the file, such as a push, every input it declares is empty text, even one with a default.

Latchkey refuses a start by name, with no run recorded, when it gives an input the file does not declare, leaves out a required one, gives a value a choice does not list or a boolean value other than true or false (or True, TRUE, False, FALSE), or would take a job's environment past 32 KiB. It does the same when the file does not declare workflow_dispatch at that branch or tag, and when any workflow file there, not only the one started, holds a key Latchkey refuses, which it names with the file and its line.

An input is recorded on the run and shown on its page, and a job's log does not hide it, so never put a token or password in one: set it as a secret in Latchkey and read it with ${{ secrets.NAME }} instead.

Any owner, admin or member of the workspace starts a run with Run workflow on the Runs page, choosing the repository, the workflow file, the branch or tag and the inputs. An agent or a script uses the run_workflow MCP tool or latchkey workflows run from the Latchkey CLI (CLI 0.10.0 or later), with a key created with the Full access preset or with Allow starting Latchkey CI workflows under Customize access (see Connect your AI agent). With no branch or tag named, it runs at the repository's default branch. A name that is both a branch and a tag runs at the branch, so give refs/tags/<name> for the tag. Latchkey reads the file as committed at the head of that branch or tag. Each start is a run of its own, billed as its own, so starting again starts a second run.

latchkey workflows run deploy.yml --repository acme/api --ref main --input region=eu-west-1 --input dry-run=false

The command takes the file's name, as deploy.yml, or its whole path, and each input as --input name=value. It prints the run's page once the run has started and does not wait for it to end, so exit 0 says the run started, not how it ended. A key that can start workflows but cannot read jobs is saved by latchkey login only with --force.

A manual run writes no check on any commit, as a scheduled run writes none. It shows on the Runs page with the event workflow_dispatch, and its page lists its inputs. In its jobs LATCHKEY_CI_EVENT_CLASS is workflow_dispatch, LATCHKEY_CI_REF is the full ref of the branch or tag, and LATCHKEY_CI_ACTOR is the code host login of the person who started it or who created the key, empty when that person has none. Its jobs bill like a push's, and it takes the file's concurrency group, as a push to the same branch does.

A job with a map of branches chooses by the branch the run was started on. A tag keys on no branch, so a map matches no key on one. When a job that would run matches no key, the start is refused before any run is recorded. A job that names an environment still waits for its approval unless the environment needs none, and the environment's branches judge the branch or tag the run was started on. In a trial run, advisory: decides what a job does, as in any trial run.

A re-run, with Re-run jobs that did not pass on the run in the dashboard, serves the same file, commit and inputs; a manual run has no check on GitHub to re-run from. A start at the workspace's spend limit or its included minutes is not refused: the run ends before any job runs, and its page says why.

When nothing runs#

Three outcomes mean the push was read and nothing matched, and a fourth means Latchkey does not run the pull request. None of them is a failure.

ReasonWhat it means
no_workflow_fileNo workflow file under .latchkey/workflows/ at this commit, so nothing ran.
no_workflow_matchedNo workflow under .latchkey/workflows/ matches this event, so nothing ran.
fork_base_no_workflow_fileNo workflow file at the base commit this pull request targets, so nothing ran. A fork's own workflow files never run; add the file to a branch of this repository first.
fork_private_repositoryLatchkey does not run pull requests from forks of a private repository, so this code has not been verified. To run it, push the change to a branch of this repository as a new commit.

A matrix#

A matrix expands to one job per combination. A leg key appends the leg values to the job key, sorted by key and joined with commas, so a job named build with os: linux and node: 20 produces the leg key build(node=20,os=linux). No job may expand past 50 legs, no single workflow file may hold more than 50 legs across all of its jobs, and no run may hold more than 150 jobs, counted across every workflow file the event matched.

In Actions, fail-fast defaults to true and cancels the other legs when one fails. Latchkey runs every leg and cancels none, so fail-fast: false is accepted because it is exactly what Latchkey does, fail-fast: true is refused rather than quietly ignored, and max-parallel is refused too.

Split a test suite across runners#

A slow test suite finishes sooner when each leg of a matrix runs one shard of it, chosen with the test runner's own flag. Vitest, Jest and Playwright take --shard=<index>/<total>, and pytest splits with the pytest-split plugin, as in pytest --splits 4 --group ${{ matrix.shard }}. Pass the flag through the package's own test script. Going through the script runs the package's pretest steps (a typecheck of the tests, say) in every shard, as CI runs them, where calling the test runner directly skips them. This job runs a Vitest suite in four shards, each on its own large runner, and lints once, on the first leg:

yaml
on:
  push:
  pull_request:
jobs:
  test:
    runs-on: large
    strategy:
      matrix:
        shard: [1, 2, 3, 4]
    steps:
      - run: npm ci
      - run: npm test -- --shard=${{ matrix.shard }}/4
      - if: matrix.shard == '1'
        run: npm run lint

The four legs are keyed test(shard=1) to test(shard=4), and each has its own check, such as Latchkey / ci.yml / test(shard=2) for a file named ci.yml. The total after the slash is written by hand and must equal the number of values in the list: Latchkey has no strategy.job-total, and ${{ strategy.job-total }} is refused. Each leg is a job on its own runner, so each installs its own dependencies; to reuse them between runs, cache them with the latchkey/cache-restore and latchkey/cache-save steps. Every leg runs even after another fails, the job has passed only when every leg has, and a job that names it in needs: waits for all of them. The lint step's if: compares text, so its value is quoted: '1' matches the leg whose shard is 1.

Service containers#

A job may declare service containers under services:, each a label with an image:. Latchkey starts every service before the job's first step, on a network of the job's own, and your steps reach a service by its label as a host name, on the port its image listens on, so a service labelled cache running redis:7 is cache:6379 to every step of the job. A service can also publish a port on the runner under ports:, written <runner port>:<service port>, and your steps then reach it at localhost:<runner port> too. A label is lowercase letters, digits and -, starts with a letter, does not end with a hyphen, is at most 63 characters and is not localhost; a job declares at most 10 services. Steps of a pull request from a fork reach no service container.

.latchkey/workflows/ci.yml
on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    runs-on: small
    services:
      cache:
        image: redis:7
    steps:
      - run: nc -z cache 6379
.latchkey/workflows/ci.yml
on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    runs-on: small
    services:
      db:
        image: postgres:16
        env:
          POSTGRES_PASSWORD: postgres
        ports:
          - 5432:5432
    steps:
      - run: pg_isready -h localhost -p 5432

Latchkey waits until each service is ready: healthy, when its image declares a health check; otherwise accepting a connection on a port its image exposes; otherwise running. It waits up to 5 minutes for all of them, pulls included. A service whose image cannot be pulled, that stops, or that is not ready in time fails the job before its first step runs, and the job log names the service, its image and the reason. When the job ends, however it ends, Latchkey removes the services and everything it created for them, and the runner itself is destroyed after its one job in any case.

A service runs a public image. Under a service, env: sets the variables its image reads at start, such as POSTGRES_PASSWORD for postgres, and ports: publishes a port on the runner's loopback address. options:, volumes: and credentials: are refused by name, so an image that needs a credential to pull cannot run as a service: start it in a run: step instead. A matrix value cannot be used in a service's image: or env:, and a service's env: cannot read a secret.

Latchkey never writes a service's settings to the job log. A setting of 28 bytes or more is also hidden wherever a step prints it, in the log and in what self-heal reads. A shorter one, such as a test database's password, is not hidden, so keep real credentials out of service settings: a value that reads as a credential is refused, and a secret belongs in a step's env:.

How a refusal reads#

Latchkey refuses a file rather than running it with a key ignored. One refusal per push: the first refused key in the file, named exactly as you wrote it, with its line, or the file or directory where the refusal is about the whole of it. The plan context concludes with the refusal on the run record. The Latchkey / plan check names where it was refused.

Latchkey reads at most 50 files and folders directly in .latchkey/workflows/. A commit whose directory holds more is refused as a whole: the Latchkey / plan check names the directory, and none of its workflow files run.

The three you are most likely to meet when you port a file:

  • uses: actions/github-script@v7 is not a Latchkey step. Latchkey runs only its own steps, written uses: latchkey/<name>@<version>, and never runs GitHub actions. Use a Latchkey step, listed at https://latchkey.dev/documentation/steps, or write this step as run:.
  • options:, volumes: and credentials: under a service are not supported: a service runs a public image with the settings in its env: and the ports in its ports:, and your steps reach it by its label or at its published port.
  • cancelled() is not supported in if:: cancelling a run ends its jobs that have not started and stops the ones running, so no job or step runs because a run was cancelled. To run a job whatever its needs ended as, use always().
app.latchkey.dev / acme / runs / ci

The workflow file .latchkey/workflows/ci.yml, whose test job has the step uses: actions/checkout@v4 on line 7, above the run page for its push to main on acme/api. The run is queued and not yet decided, with Cancel run in the title bar and the banner This run is still going. This page updates as its jobs start and finish. Then Latchkey refuses the file before any job starts: line 7 is marked, the run reads Stopped and No pipeline, and under 01 Jobs the banner reads Latchkey refused this run before any job started. A workflow file could not be used, so no jobs were created. The Latchkey / plan check names where it was refused. The Latchkey / plan check reads Stopped, the Latchkey check reads No result with Your code did not run; Latchkey / plan says why., the advisory Latchkey / tests check reads Not run with No Latchkey verification tests ran., and the title bar offers Re-run jobs that did not pass.

FIG. 8.1-BA refused file never runs with a key ignored. The run stops before any job, the Latchkey check reads No result because nothing of yours ran, and the refusal's own words, with the line, are on the Latchkey / plan check on your commit.

What a failed job means for you#

A job that fails is routed to Latchkey's self-heal, and the heal is reported for the job as a whole, not per step. Self-heal does not run on a pull request from a fork. Nor does it run on a step that a trial run would leave out: a step written advisory: skip, a step that can publish and writes no advisory:, and every step of a job that writes advisory: hold or names an environment and writes no advisory:. Nor does it run on a step that starts once the job holds more than 64 values to hide, counting its secrets, its service settings of 28 bytes or more and the credentials Latchkey hands its steps; Self-healing says what counts. Not every failure is your code: Latchkey tells its own faults, your cancellations, an approval refused or never given, and billing or connection problems apart from your command's own outcome. Red on the Latchkey check means your command failed or your job reported the failure itself; a fault Latchkey can attest as its own never turns the Latchkey check red, and the check text says the fault was Latchkey's. A job started by a push or a pull request serves its log today through latchkey logs <job id> and the MCP get_job_logs tool, and appears in the job list and on the run page, where each step shows its own log as it runs. A job Latchkey could not place on a runner says so and is never billed.

To run a finished run's jobs again, press Re-run on the Latchkey check on GitHub, or Re-run jobs that did not pass on the run in the dashboard. Latchkey runs, as a new attempt of the same run, every job that did not pass and every job that needs one of them. Every other job that passed is carried over and is not run or billed again. Cancel run in the dashboard cancels every job in the run that has not finished, and the run then reads Cancelled.

When a branch moves to a commit that already has a run, for example main fast-forwarded to a commit built on another branch, Latchkey runs the workflow files that match the new push and that the run did not run, as a new attempt of the same run. A file the run already ran is run again in that attempt when it matches the new push, a job of it ended because its environment does not accept the run, and the environment accepts the branch that moved. A file the run already ran is also run again in that attempt when it matches the new push and a job of it was skipped before it started because its if: did not hold for the run, as a deploy whose if: tests LATCHKEY_CI_REF for main is skipped on another branch, unless that if: does not hold for the new push either. A file the run already ran is also run again in that attempt when it matches the new push and a job of it had its if: decided by its runner, because Latchkey could not answer that if: when it planned the run, and Latchkey can tell that it holds for the new push. Latchkey does this once the run has passed, or once a re-run of it passes, or once every job of the run or of a re-run of it that neither passed nor was skipped ended because its environment does not accept the run, within four days of the push. Jobs that already passed are not run again. If every job of a file run again this way already passed, the attempt runs no job and passes, and the run page shows it.

What stays the same for your other repositories#

Your GitHub Actions jobs on latchkey-* runners keep running exactly as they do today, on the same organization, the same bill and the same free-minute pool. You move repositories to Latchkey CI one at a time.

Forward-compatibility#

A file you commit in this release is never migrated: the same compiler reads it in every later release.