How to Fail a Pull Request When the Docs Are Out of Date

Tests fail a pull request when the code is wrong. Type checks fail it when the types are wrong. Nothing fails it when the documentation is wrong, and that is exactly why documentation falls behind: work with no consequence gets skipped.

This guide sets up a check that changes that. When a pull request touches a file whose documentation has fallen behind the code, the check fails and the pull request cannot merge until the docs catch up. It takes one workflow file and one setting in GitHub.

If you want the background on why docs drift and how drift is measured, start with What Is Documentation Drift, and How Do You Catch It?. This post is the hands-on part.

What you will end up with

What you need

Step 1: Add the workflow

Create .github/workflows/writulos-docs.yml:

name: Writulos Auto-Docs

on:
  workflow_dispatch:
  push:
    branches: [main, master]
  pull_request:

jobs:
  docs:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - uses: actions/checkout@v7
        with:
          # Full history, so drift can be counted.
          fetch-depth: 0
      - uses: writulos/scribe-action@v1
        with:
          writulos_api_key: ${{ secrets.WRITULOS_API_KEY }}
          github_token: ${{ secrets.GITHUB_TOKEN }}
          max_files: '25'
          fail_on_drift: 'true'

Three lines matter more than the rest.

fetch-depth: 0. Drift is the number of commits that have touched a source file since its doc was generated, and counting commits needs history. A shallow checkout has none, so drift is reported as "Unknown" instead. The check never quietly claims a stale doc is up to date.

max_files. Every documented file costs one generation from your monthly quota. Push and pull request runs only document the files that changed, but the workflow_dispatch button runs a full-repository scan, and the cap keeps one click from spending a month's quota. Without it, the Action refuses to start an uncapped scan of more than 25 files.

fail_on_drift. This decides what a stale doc does to the job:

ValueWhat happens
org (the default)Follows your account's setting: the team's switch on a team plan, or the toggle on your Drift page on a solo plan. Off until you turn it on, except Business, where it starts on.
trueFails this repository's job when a changed file's docs are behind. Honored on Pro and Business; on Free it warns and stays advisory.
falseNever fails this repository's job, whatever the account setting.

You can leave it at org and switch the gate from the dashboard instead. Either way, whether a run may fail is decided by your plan on Writulos's servers, not by the YAML, so editing the workflow file cannot turn the gate on for a plan that does not include it.

Step 2: Generate a baseline

Drift is measured against existing docs, so start by documenting what you already have. Open the Actions tab, pick Writulos Auto-Docs, and click Run workflow. With max_files: '25', each run documents up to 25 files and lists the ones it skipped; run it again for the next batch, or raise the cap once you know the cost.

Every doc it writes lands at a path that mirrors your source tree, so src/utils/auth.ts becomes docs/src/utils/auth.md.

Step 3: Make the check required

A failing check only blocks a merge if GitHub is told to require it.

  1. Go to Settings → Branches (or Rules → Rulesets) for your repository.
  2. Add or edit the protection rule for your main branch.
  3. Turn on Require status checks to pass before merging.
  4. Search for the job name, docs, and add it as a required check.

From now on, a pull request whose docs job fails cannot be merged.

Step 4: Watch it work

Open a pull request that changes a function in a file you documented in step 2, but do not touch its doc. The Action:

  1. Finds the files the pull request changed.
  2. Checks each one's existing doc against the code, before regenerating anything, and annotates every file whose doc is behind, for example "Docs for src/utils/auth.ts are 2 commits behind the code".
  3. In the default commit mode, writes fresh docs for the changed files and commits them to the pull request's branch.
  4. With the gate on and at least one stale doc found, fails the job.

The failure is deliberate even though fresh docs were just written. The question the check answers is "did this change go out with documentation that described it?", and the answer was no. Pull the branch, read what the regenerated docs now say about your change, and push again so the check runs on the new head.

If your team would rather review docs separately, set mode: 'pr', and the Action opens a pull request with the docs instead of committing to the branch.

Step 5: Catch it before you push (optional)

A CI check runs after the push, so it can stop a merge but not the push itself. To catch stale docs on your own machine first, install the pre-push hook:

curl -fsSL https://scribe.writulos.com/pre-push.sh -o .git/hooks/pre-push
chmod +x .git/hooks/pre-push

It is plain POSIX shell, reads only your git history, and needs no network or API key. It looks at the files your push contains and stops the push when one of their docs is behind. Treat it as a courtesy, not a control: git push --no-verify skips it, and it is only installed where someone installs it. The CI check is the guarantee.

Common questions

Will this fail on files that have no docs yet? No. A file with no existing doc has nothing to be stale, so it is documented, not flagged.

Does it fail on files the pull request did not touch? No. The pull request check looks only at the files the pull request changes. Drift for every documented file still shows on your Drift page, where each file reads "Up to date", "N commits ago" or "Unknown".

Can I gate some repositories and not others? Yes. fail_on_drift: 'false' in a repository's workflow always wins for that repository, and 'true' turns the gate on for one repository on Pro or Business.

What does it cost? Checking drift is pure git arithmetic and costs no generations. Only writing docs does, one per file.

Wrapping up

The point is not to punish anyone for forgetting the docs. It is to make the docs part of the same definition of done as the tests: a change is finished when its documentation describes it.

Set up the GitHub Action, or see what each plan's drift gate can do. New to the idea? Start with what documentation drift is, or check any public repository's docs for free.