|
| 1 | +--- |
| 2 | +title: CI integration |
| 3 | +sidebar-title: CI |
| 4 | +--- |
| 5 | + |
| 6 | +Run Doc Detective in continuous integration (CI) pipelines using the GitHub Action. Test your docs on every push or pull request. |
| 7 | + |
| 8 | +## Set up the GitHub Action |
| 9 | + |
| 10 | +To add Doc Detective to your GitHub Actions workflow, create a YAML file in your `.github/workflows` directory: |
| 11 | + |
| 12 | +```yaml |
| 13 | +name: doc-detective |
| 14 | +on: [pull_request] |
| 15 | + |
| 16 | +jobs: |
| 17 | + runTests: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + - uses: doc-detective/github-action@v1 |
| 22 | +``` |
| 23 | +
|
| 24 | +This runs Doc Detective tests whenever a pull request is opened or updated. |
| 25 | +
|
| 26 | +## Configuration options |
| 27 | +
|
| 28 | +Customize the action with inputs by adding a `with` key to the `uses` block: |
| 29 | + |
| 30 | +```yaml |
| 31 | +- uses: doc-detective/github-action@v1 |
| 32 | + with: |
| 33 | + version: latest |
| 34 | + input: ./docs |
| 35 | + config: .doc-detective.json |
| 36 | +``` |
| 37 | + |
| 38 | +### Common inputs |
| 39 | + |
| 40 | +| Input | Default | Description | |
| 41 | +|-------|---------|-------------| |
| 42 | +| `version` | `latest` | Doc Detective version (npm version or tag) | |
| 43 | +| `working_directory` | Repository root | Directory to run the action in | |
| 44 | +| `config` | None | Path to configuration file | |
| 45 | +| `input` | None | Path to input file or directory (overrides config) | |
| 46 | +| `command` | `runTests` | Command to run (`runTests` or `runCoverage`) | |
| 47 | +| `exit_on_fail` | `false` | Exit with non-zero code if tests fail | |
| 48 | + |
| 49 | +## Create pull requests automatically |
| 50 | + |
| 51 | +Doc Detective might update files in your repository when it runs—like refreshing screenshots or updating command output. You can automatically create a pull request with these changes. |
| 52 | + |
| 53 | +```yaml |
| 54 | +name: doc-detective |
| 55 | +on: |
| 56 | + schedule: |
| 57 | + - cron: '0 0 * * *' # Run daily at midnight |
| 58 | +
|
| 59 | +jobs: |
| 60 | + runTests: |
| 61 | + runs-on: ubuntu-latest |
| 62 | + permissions: |
| 63 | + contents: write |
| 64 | + pull-requests: write |
| 65 | +
|
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v4 |
| 68 | + - uses: doc-detective/github-action@v1 |
| 69 | + with: |
| 70 | + create_pr_on_change: true |
| 71 | + pr_title: Doc Detective found changes |
| 72 | + pr_labels: doc-detective,for-review |
| 73 | +``` |
| 74 | + |
| 75 | +<Note> |
| 76 | + |
| 77 | +You must enable GitHub Actions to create pull requests for your repository. Go to **Settings** > **Actions** > **General** and select **Allow GitHub Actions to create and approve pull requests**. |
| 78 | + |
| 79 | +</Note> |
| 80 | + |
| 81 | +### Pull request options |
| 82 | + |
| 83 | +| Input | Default | Description | |
| 84 | +|-------|---------|-------------| |
| 85 | +| `create_pr_on_change` | `false` | Create a PR if files change | |
| 86 | +| `pr_branch` | `doc-detective-{DATE}` | Branch name for the PR | |
| 87 | +| `pr_title` | `Doc Detective Changes` | PR title | |
| 88 | +| `pr_body` | See default | PR description (`$RUN_URL` inserts the workflow URL) | |
| 89 | +| `pr_labels` | `doc-detective` | Comma-separated labels | |
| 90 | +| `pr_assignees` | None | Comma-separated usernames to assign | |
| 91 | +| `pr_reviewers` | None | Comma-separated usernames to request reviews | |
| 92 | + |
| 93 | +## Create issues on test failure |
| 94 | + |
| 95 | +If tests fail, you can automatically create a GitHub issue to track the problem. You can also trigger [integrations](/docs/get-started/integrations) to investigate and fix failures. |
| 96 | + |
| 97 | +```yaml |
| 98 | +name: doc-detective |
| 99 | +on: [pull_request] |
| 100 | +
|
| 101 | +jobs: |
| 102 | + runTests: |
| 103 | + runs-on: ubuntu-latest |
| 104 | + permissions: |
| 105 | + contents: read |
| 106 | + issues: write |
| 107 | + steps: |
| 108 | + - uses: actions/checkout@v4 |
| 109 | + - uses: doc-detective/github-action@v1 |
| 110 | + with: |
| 111 | + create_issue_on_fail: true |
| 112 | + issue_title: Doc Detective found documentation issues |
| 113 | + integrations: claude |
| 114 | +``` |
| 115 | + |
| 116 | +### Issue options |
| 117 | + |
| 118 | +| Input | Default | Description | |
| 119 | +|-------|---------|-------------| |
| 120 | +| `create_issue_on_fail` | `false` | Create an issue if tests fail | |
| 121 | +| `issue_title` | `Doc Detective Failure` | Issue title | |
| 122 | +| `issue_body` | See default | Issue body (`$RESULTS` inserts test results, `$RUN_URL` inserts workflow URL) | |
| 123 | +| `issue_labels` | `doc-detective` | Comma-separated labels | |
| 124 | +| `issue_assignees` | None | Comma-separated usernames to assign | |
| 125 | +| `integrations` | None | Comma-separated integrations to trigger (see [Integrations](/docs/get-started/integrations)) | |
| 126 | +| `prompt` | See default | Custom prompt to pass to integrations | |
| 127 | + |
| 128 | +## Action outputs |
| 129 | + |
| 130 | +The action provides outputs you can use in subsequent workflow steps: |
| 131 | + |
| 132 | +| Output | Description | |
| 133 | +|--------|-------------| |
| 134 | +| `results` | JSON-formatted test results | |
| 135 | +| `pull_request_url` | URL of created PR (if applicable) | |
| 136 | +| `issue_url` | URL of created issue (if applicable) | |
| 137 | + |
| 138 | +Example using outputs: |
| 139 | + |
| 140 | +```yaml |
| 141 | +- uses: doc-detective/github-action@v1 |
| 142 | + id: doc-detective |
| 143 | +- run: echo "Results: ${{ steps.doc-detective.outputs.results }}" |
| 144 | +``` |
| 145 | + |
| 146 | +## Browser modes |
| 147 | + |
| 148 | +On Ubuntu runners, the action only supports headless browser mode. Chrome and Firefox contexts automatically fall back to headless mode when necessary. |
| 149 | + |
| 150 | +If your tests require non-headless mode (like video recording with `startRecording`), use macOS or Windows runners instead: |
| 151 | + |
| 152 | +```yaml |
| 153 | +jobs: |
| 154 | + runTests: |
| 155 | + runs-on: macos-latest # or windows-latest |
| 156 | + steps: |
| 157 | + - uses: actions/checkout@v4 |
| 158 | + - uses: doc-detective/github-action@v1 |
| 159 | +``` |
0 commit comments