|
| 1 | +# Documentation Check |
| 2 | + |
| 3 | +The Soundness workflow can verify that your Swift package's [DocC](https://www.swift.org/documentation/docc/) documentation builds without warnings. Two jobs are available: |
| 4 | + |
| 5 | +- **`docs-check`** — runs on Linux. Enabled by default. |
| 6 | +- **`docs-check-macos`** — runs on a self-hosted macOS runner. Opt-in. |
| 7 | + |
| 8 | +Running both lets you catch documentation issues that only surface on one toolchain. |
| 9 | + |
| 10 | +Documentation warnings (and, by default, DocC analyzer findings) cause the job to fail. |
| 11 | + |
| 12 | +## Requirements |
| 13 | + |
| 14 | +For either job to run, your repository needs: |
| 15 | + |
| 16 | +1. A `Package.swift` (or any `Package*.swift`) at the repository root. |
| 17 | +2. A `.spi.yml` at the repository root listing the targets to document. Read the [official documentation](https://swiftpackageindex.com/SwiftPackageIndex/SPIManifest/1.12.0/documentation/spimanifest/commonusecases) on how to generate the `.spi.yml`. For example: |
| 18 | + |
| 19 | + ```yaml |
| 20 | + version: 1 |
| 21 | + builder: |
| 22 | + configs: |
| 23 | + - documentation_targets: [MyLibrary, MyOtherLibrary] |
| 24 | + custom_documentation_parameters: |
| 25 | + - --include-extended-types |
| 26 | + ``` |
| 27 | +
|
| 28 | + Targets listed under `documentation_targets` must match real SwiftPM target names. Any `custom_documentation_parameters` are forwarded to DocC for that group of targets. |
| 29 | + |
| 30 | +You do not need to add `swift-docc-plugin` to your package — CI provides it for you. |
| 31 | + |
| 32 | +## Enabling the check |
| 33 | + |
| 34 | +Add (or extend) a workflow file under `.github/workflows/` in your repository: |
| 35 | + |
| 36 | +```yaml |
| 37 | +name: Pull request |
| 38 | +
|
| 39 | +on: |
| 40 | + pull_request: |
| 41 | + branches: [main] |
| 42 | +
|
| 43 | +jobs: |
| 44 | + soundness: |
| 45 | + name: Soundness |
| 46 | + uses: swiftlang/github-workflows/.github/workflows/soundness.yml@<to-be-updated>> |
| 47 | + with: |
| 48 | + docs_check_enabled: true |
| 49 | +``` |
| 50 | + |
| 51 | +This enables the Linux documentation check along with the other soundness checks. The macOS variant remains off unless you opt in. |
| 52 | + |
| 53 | +## Configuration |
| 54 | + |
| 55 | +### Linux job (`docs-check`) |
| 56 | + |
| 57 | +| Input | Type | Default | Description | |
| 58 | +|---|---|---|---| |
| 59 | +| `docs_check_enabled` | boolean | `true` | Enable or disable the job. | |
| 60 | +| `docs_check_container_image` | string | `swift:6.2-noble` | Docker image used to run the check. | |
| 61 | +| `docs_check_additional_arguments` | string | `""` | Extra arguments to pass to DocC. | |
| 62 | +| `docs_check_analyze` | boolean | `true` | Set to `false` to skip DocC's analyzer pass. | |
| 63 | +| `linux_pre_build_command` | string | `""` | Shell command to run before the check (e.g., installing system dependencies). | |
| 64 | + |
| 65 | +### macOS job (`docs-check-macos`) |
| 66 | + |
| 67 | +| Input | Type | Default | Description | |
| 68 | +|---|---|---|---| |
| 69 | +| `docs_check_macos_enabled` | boolean | `false` | Enable or disable the job. | |
| 70 | +| `docs_check_macos_version` | string | `tahoe` | macOS version label of the runner to target. | |
| 71 | +| `docs_check_macos_arch` | string | `ARM64` | Architecture label of the runner to target. | |
| 72 | +| `docs_check_macos_xcode_version` | string | `26.0` | Xcode version to use. | |
| 73 | +| `docs_check_macos_additional_arguments` | string | `""` | Extra arguments to pass to DocC. | |
| 74 | +| `docs_check_macos_analyze` | boolean | `true` | Set to `false` to skip DocC's analyzer pass. | |
| 75 | + |
| 76 | +The macOS job requires a self-hosted runner registered with the label set `[self-hosted, macos, <version>, <arch>]`. |
| 77 | + |
| 78 | +## Common scenarios |
| 79 | + |
| 80 | +### Enable the macOS check |
| 81 | + |
| 82 | +```yaml |
| 83 | +jobs: |
| 84 | + soundness: |
| 85 | + uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main |
| 86 | + with: |
| 87 | + docs_check_macos_enabled: true |
| 88 | + docs_check_macos_version: "tahoe" |
| 89 | + docs_check_macos_arch: "ARM64" |
| 90 | + docs_check_macos_xcode_version: "26.0" |
| 91 | +``` |
| 92 | + |
| 93 | +### Pin a different Swift toolchain or pass extra DocC flags |
| 94 | + |
| 95 | +```yaml |
| 96 | +jobs: |
| 97 | + soundness: |
| 98 | + uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main |
| 99 | + with: |
| 100 | + docs_check_container_image: "swift:nightly-noble" |
| 101 | + docs_check_additional_arguments: "--include-extended-types" |
| 102 | + linux_pre_build_command: "apt-get update && apt-get install -y libxml2-dev" |
| 103 | +``` |
| 104 | + |
| 105 | +### Skip the DocC analyzer |
| 106 | + |
| 107 | +```yaml |
| 108 | +jobs: |
| 109 | + soundness: |
| 110 | + uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main |
| 111 | + with: |
| 112 | + docs_check_analyze: false |
| 113 | +``` |
| 114 | + |
| 115 | +### Disable the check |
| 116 | + |
| 117 | +If your package has no documentation targets, disable the job rather than letting it fail on a missing `.spi.yml`: |
| 118 | + |
| 119 | +```yaml |
| 120 | +jobs: |
| 121 | + soundness: |
| 122 | + uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main |
| 123 | + with: |
| 124 | + docs_check_enabled: false |
| 125 | +``` |
| 126 | + |
| 127 | +## Troubleshooting |
| 128 | + |
| 129 | +| Symptom | Likely cause | |
| 130 | +|---|---| |
| 131 | +| `No '.spi.yml' found.` | Add a `.spi.yml` at the repo root, or disable the job. | |
| 132 | +| `Package.swift not found.` | The check expects a SwiftPM package at the repo root. | |
| 133 | +| Warnings cause the job to fail. | Intentional. Resolve the DocC warnings, or pass DocC flags via `.spi.yml`'s `custom_documentation_parameters` to suppress them. | |
| 134 | +| macOS job stays queued. | No self-hosted runner matches the requested labels. Verify the `version` and `arch` inputs against your runner inventory. | |
| 135 | +| macOS job cannot find Xcode. | The requested Xcode version is not installed on the runner. | |
0 commit comments