Run in CI with the GitHub Action
The Doc Detective GitHub Action runs your tests inside a GitHub Actions workflow. It’s the recommended way to run Doc Detective in CI. It installs Doc Detective for you and fails the job when tests fail. It can also open a pull request or file an issue when a run finds a problem. This guide covers adding the action to a workflow, failing the build on test failures, and wiring up the pull request and issue features.
For the full list of inputs and outputs, see the action’s README.
Before you begin
- A GitHub repository with documentation tests. That’s either a spec you can run, or docs with inline or detected tests.
- Permission to add a workflow file under
.github/workflows/in that repository.
Step 1: Add the action to a workflow
Create a workflow file in .github/workflows/. Check out the repository first so the action can read your tests. Set up Node.js, then add the Doc Detective step:
This runs Doc Detective on every pull request. Doc Detective 5 needs Node.js 24.15 or later, and GitHub-hosted runners default to an older version. On older Node.js, the action warns:
Pin to the major version (@v2) to pick up fixes automatically, or pin to a full version such as @v2.0.0 for a fixed release. Action @v2 runs CLI 5, and @v1 stays on CLI 4. If you’re moving from @v1, see Upgrade to Doc Detective 5.
Step 2: Point the action at your tests
By default, the action runs from the repository root and uses the config file Doc Detective discovers there. To override either one, set the corresponding input:
Leave version empty to skip the registry install and run whatever doc-detective is already resolvable in the working directory. One example is a local build you exposed with npm link in an earlier step. This lets a repository test the action against its own build under review rather than the published package. The action expects version 5’s exit codes, so the local build must be version 5 or later.
Step 3: Fail the build when tests fail
By default, a failing test fails the job and blocks the pull request. To report failures without failing the job, for example while you triage an existing suite, set exit_on_fail to false:
The action follows the exit code from the CLI:
The job also fails when the CLI writes no results file, whatever exit_on_fail says. The action treats that as a run that never happened, not as a failing test. For example, a network error while npx installs Doc Detective exits 1 with no results.
When the CLI does write results, the action sets the results output and runs the issue and pull request steps before it fails the job.
exit_on_fail acts only on exit code 1. If a test fails but the CLI exits 0, the job passes and the action logs a warning. The CLI exits 0 on a failing test when your config sets exitOnFail: false, or when version runs a CLI older than 5. To stay on CLI 4, use doc-detective/github-action@v1.
See Reporters and artifacts for the exit codes in detail.
Step 4: Open a pull request when files change
Doc Detective sometimes updates files during a run, refreshing screenshots, recording new command output, or writing “Last verified on” dates. A passing run updates those dates at most once a day. A scheduled workflow can open a pull request whenever a run falls on a new UTC day. The action can commit those changes to a branch and open a pull request for review. To enable this, set create_pr_on_change to true and grant the job permission to write contents and pull requests:
The action commits to one branch, doc-detective-changes by default, and force-pushes it on each run. If that branch already has an open pull request, the action updates it rather than opening another. The pull request targets GITHUB_BASE_REF, the base of the pull request that triggered the run. Otherwise it targets GITHUB_REF_NAME, the branch the run is on. Git commands run in working_directory.
By default, the action stages every changed file, including screenshots and recordings the run takes. They can show unreleased UI or customer data. Set pr_paths to limit what the pull request commits.
You must allow GitHub Actions to create pull requests for the repository. Go to Settings > Actions > General and select Allow GitHub Actions to create and approve pull requests.
A created pull request means files changed, not that tests passed or failed. Review the diff before merging.
Step 5: File an issue when tests fail
When a run has failing tests, the action can open a GitHub issue to track the failure and mention an AI assistant to investigate it. To enable this, set create_issue_on_fail to true and grant the job permission to write issues:
This workflow runs on pushes to main. By default, a fork’s pull request gets a read-only GITHUB_TOKEN and no secrets, so the action can’t open an issue for it. Keep pull request checks in a separate pull_request workflow without create_issue_on_fail.
If an open issue has the same title and the first label in issue_labels, the action updates that issue. Otherwise it creates one. A daily schedule then keeps one issue current rather than opening one per run. In a pull_request workflow, every pull request shares that issue. To keep one issue per pull request, put the number in the title, such as issue_title: "Doc Detective failures in PR #${{ github.event.pull_request.number }}". Quote the value, because YAML treats a space followed by # as the start of a comment and drops the rest of the title.
$SUMMARY is the run folder’s testResults.md, the run’s Markdown summary. When the run wrote no run folder, or the run folder has no testResults.md, it reads Doc Detective wrote no summary for this run. See the workflow run.
$SUMMARY and $RESULTS come from masked output, so environment variable values appear as ***NAME***. GitHub masks secrets in logs but not in issue bodies, so this keeps them out of the issue. See Keep secrets out of logs, reports, and captures.
GitHub limits an issue body to 65,536 characters. When the body would be longer, the action shortens $SUMMARY or $RESULTS to fit. Each shortened value ends with a note that links to the workflow run. A shortened $SUMMARY ends on a whole line. If issue_body and issue_prompt leave no room for results, the action logs an error and doesn’t create the issue.
The issue_mentions input mentions an AI assistant in the issue so it can investigate the failure and suggest a fix. Options include claude, copilot, cursor, and promptless. For the full list, see AI issue mentions. For prompts that get useful analysis back, see Hand off test failures to an AI agent.
The example sets token because claude needs it. Claude Code answers from a workflow, and GitHub doesn’t start workflows for an issue that the default GITHUB_TOKEN opens. That page shows how to create the token.
GitHub Action @v2 renames integrations to issue_mentions and prompt to issue_prompt. The old names still work, but the action logs a deprecation warning. Setting both an old and a new name fails the job before tests run.
Step 6: Use the results in later steps
The action exposes the run’s results so later steps can act on them. Give the step an id, then read its outputs:
Find reports and the run folder
The action passes Doc Detective a temporary path with --output, and reads the results file from there to set the results output. Use that output rather than the file.
Everything else lands under your config’s outputDir, as it does on the command line. That’s the run folder, <outputDir>/.doc-detective/runs/<runId>/, and files from reporters you turn on with reporters, such as junit.xml. outputDir defaults to the config file’s folder, or working_directory with no config file. See Choose your reporters.
The action adds .doc-detective/, junit.xml, doc-detective-summary.md, and testResults-* to .git/info/exclude. Git then ignores them, so create_pr_on_change doesn’t commit the run’s own reports. Screenshots and recordings aren’t excluded. A screenshot: true image lands in outputDir, beside the reference image you committed, so each run compares against it. A changed image reaches the pull request. To keep images out of the pull request, set pr_paths.
GitHub discards the checkout when the job ends. To keep the reports, upload them in a later step. This example assumes outputDir is the repository root. Leave out any path your config doesn’t produce:
if: always() uploads the files even when a failing test fails the job. upload-artifact treats files in a folder whose name starts with . as hidden and skips them by default, so set include-hidden-files: true to upload the run folder. Upload the run folder with junit.xml, because its attachments are relative to that file.
Tests are code
Running Doc Detective on a repository runs that repository’s tests, the same way npm test runs its test suite. Tests can run shell commands, run code, and send HTTP requests. That’s true of inline tests in your docs and of standalone spec files alike. Anyone who can change your tests can change what your workflow runs.
bash, python, py, javascript, and js code blocks that Doc Detective detects in Markdown are the exception. Nobody wrote them as tests, so they’re marked unsafe, and a run skips them unless you allow unsafe steps. The official Docker image allows them by default. Detected HTTP request blocks aren’t marked unsafe, so a run sends those requests. To turn detection off, set detectSteps to false.
What protects your workflow is who can start a run that has your secrets:
- Trigger pull request checks on
pull_request. By default, a fork’s pull request runs without your repository’s secrets and with a read-onlyGITHUB_TOKEN. A private repository, or its organization, can send write tokens or secrets to those runs under Settings > Actions > General > Fork pull request workflows. With either setting on, a fork’s tests run with them. The read-only token also stops the action from opening issues or pull requests for a fork’s pull request. Runcreate_issue_on_failandcreate_pr_on_changeonpush,schedule, orworkflow_dispatchinstead. - Never check out and run a pull request’s code in a
pull_request_targetworkflow. That trigger runs with your secrets and a read/writeGITHUB_TOKEN, even if no step uses a secret.actions/checkoutalso saves that token in the Git config by default.
Browser modes
On Ubuntu runners, the action runs browsers headless. Chrome and Firefox contexts fall back to headless mode automatically when there’s no display.
Doc Detective records headless Chrome with the browser engine, so Chrome recordings work on Ubuntu. Headless Firefox can’t record, because it needs the ffmpeg engine and a display. To record Firefox on Ubuntu, install Xvfb in a step before the action:
Installing the package is all you do. When a run records Firefox, Doc Detective finds the Xvfb binary, starts its own display for the recording, and runs Firefox headed on it. Without Xvfb, Doc Detective skips Firefox record steps instead of failing them.
You can also run the job on a macOS or Windows runner, which has a display:
See Docker and headless for how headless environments affect a run.
Speed up iOS tests on macOS
Tests against the ios platform run on macOS runners, where the first XCUITest session compiles WebDriverAgent with xcodebuild. On a cold, ephemeral runner, that compile takes around 10 minutes. To pay that cost once, persist Doc Detective’s cache directory between runs, then run doc-detective install ios --yes in your setup steps. It compiles WebDriverAgent once into the cache, keyed by your Xcode and XCUITest driver versions. Test sessions use the build automatically and read-only, which is safe to share across parallel jobs.
The actions/cache step’s path reads the same DOC_DETECTIVE_CACHE_DIR value, so the two stay in sync if you change the directory.
Use a rotating key (github.run_id) with restore-keys rather than a static key. Doc Detective already keys the build by Xcode and driver version inside the cache directory. The actions/cache key doesn’t need those versions, because its only job is to keep the stored copy fresh. An exact cache hit never re-uploads, so a static key keeps serving the first build it saved. That build goes stale the first time your runner picks up a new Xcode or driver version. A run-scoped key always saves the latest build, and restore-keys restores the newest earlier entry.
Runtime caching
Doc Detective installs heavy runtime assets on first use, including browsers, drivers, and npm packages. To speed up CI, cache them between runs.
Cache the runtime directory
Point DOC_DETECTIVE_CACHE_DIR at a path under the workspace, then use GitHub’s cache action to persist it between runs:
Because DOC_DETECTIVE_CACHE_DIR points to a path under ${{ github.workspace }}, the cache action can store and restore those assets across runs.
Pre-install assets
To control exactly when assets download, install them before the action runs:
Setting env at the job level makes DOC_DETECTIVE_CACHE_DIR visible to every step, so the pre-install step and the action share the same cached directory.
Verify it works
Open a pull request that touches a documented command, screenshot, or API response, then confirm:
- The
doc-detectivejob runs and its log shows the terminal summary. - A failing test fails the job and blocks the pull request, unless you set
exit_on_fail: false. - With
create_pr_on_change: true, a run that changes files opens a pull request, or updates the open one. - With
create_issue_on_fail: true, a run with failing tests opens an issue, or updates the open one.
Troubleshooting
The job passes even though a test failed
Cause: One of these settings keeps the job green:
- The step sets
exit_on_fail: false. - The workflow still uses
@v1, whereexit_on_faildefaults tofalse. - Your config sets
exitOnFail: false, orversionruns a CLI older than 5. The CLI then exits0when a test fails, and the job log shows a warning.
Solution: Use @v2, remove exit_on_fail: false from the step and exitOnFail: false from your config, and remove any version value below 5. See Step 3.
Reports or the run folder aren’t where you expect
Cause: They land under your config’s outputDir, which resolves against the config file’s folder. The action writes only the results file to a temporary path.
Solution: Check outputDir in your config, or read the results output. See Find reports and the run folder.
The pull request commits screenshots
Cause: create_pr_on_change stages every changed file by default, including screenshots and recordings the run takes.
Solution: Set pr_paths to the paths the pull request should commit. See Step 4.
The job warns about the Node.js version
Cause: Doc Detective 5 needs Node.js 24.15 or later, and the job runs an older version.
Solution: Add actions/setup-node with node-version: 24 before the action. See Step 1.
The action can’t create a pull request or issue
Cause: The job lacks the required permissions, or the repository doesn’t allow Actions to create pull requests.
Solution: Add permissions: { contents: write, pull-requests: write } for pull requests or permissions: { issues: write } for issues. For pull requests, also enable Allow GitHub Actions to create and approve pull requests under Settings > Actions > General.
Runs are slow because assets download every time
Cause: The runtime cache isn’t persisted between runs.
Solution: Set DOC_DETECTIVE_CACHE_DIR to a cached workspace path and pre-install assets. See Runtime caching.
What’s next
- Consume results and fail the build correctly with reporters and artifacts.
- Run in Docker and headless for containerized or non-GitHub pipelines.
- Troubleshoot a failing or flaky test when a run isn’t green.