Ensures the correctness of your CODEOWNERS file.
Codeowners Validator

The Codeowners Validator project validates the GitHub CODEOWNERS file based on specified checks. It supports public and private GitHub repositories and also GitHub Enterprise installations.

Usage
Docker
export GH_TOKEN=<your_token>
docker run --rm -v $(pwd):/repo -w /repo \
-e REPOSITORY_PATH="." \
-e TRUST_WORKSPACE="true" \
-e GITHUB_ACCESS_TOKEN="$GH_TOKEN" \
-e EXPERIMENTAL_CHECKS="notowned" \
-e OWNER_CHECKER_REPOSITORY="org-name/rep-name" \
ghcr.io/mlarraz/codeowners-validator:v0.9.0
Command line
export GH_TOKEN=<your_token>
env REPOSITORY_PATH="." \
GITHUB_ACCESS_TOKEN="$GH_TOKEN" \
EXPERIMENTAL_CHECKS="notowned" \
OWNER_CHECKER_REPOSITORY="org-name/rep-name" \
codeowners-validator
GitHub Action
- uses: actions/checkout@v7
with:
# Only the CODEOWNERS file is needed, see docs/gh-action.md
sparse-checkout: .github/CODEOWNERS
sparse-checkout-cone-mode: false
persist-credentials: false
- uses: mlarraz/codeowners-validator@v0.9.0
with:
checks: "files,owners,duppatterns,syntax"
experimental_checks: "notowned,avoid-shadowing"
Check this document for more information about GitHub Action.
Check the Configuration section for more info on how to enable and configure given checks.
Installation
It's highly recommended to install a fixed version of codeowners-validator. Releases are available on the releases page.
macOS & Linux
Install script
# binary installed into ./bin/
curl -sfL https://raw.githubusercontent.com/mlarraz/codeowners-validator/main/install.sh | sh -s v0.9.0
# binary installed into $(go env GOPATH)/bin/codeowners-validator
curl -sfL https://raw.githubusercontent.com/mlarraz/codeowners-validator/main/install.sh | sh -s -- -b $(go env GOPATH)/bin v0.9.0
# In alpine linux (as it does not come with curl by default)
wget -O - -q https://raw.githubusercontent.com/mlarraz/codeowners-validator/main/install.sh | sh -s v0.9.0
# Print version. Add `-o short` to print just the version number.
codeowners-validator version
You can also download latest version from release page manually.
From Sources
You can install codeowners-validator with go install github.com/mlarraz/codeowners-validator@v0.9.0.
NOTE: please use Go 1.27.3 or greater.
This will put codeowners-validator in $(go env GOPATH)/bin.
Checks
The following checks are enabled by default:
| Name |
Description |
| duppatterns |
[Duplicated Pattern Checker]
Reports if CODEOWNERS file contain duplicated lines with the same file pattern. |
| files |
[File Exist Checker]
Reports if CODEOWNERS file contain lines with the file pattern that do not match any file tracked in a given repository. Patterns are matched the way GitHub matches them. |
| owners |
[Valid Owner Checker]
Reports the errors GitHub finds in the CODEOWNERS file, using the CODEOWNERS errors API: owners that don't exist, aren't visible, or don't have write access to the repository, invalid owners, and invalid patterns. It's the same evaluation GitHub uses to request reviews, so GitHub must have the commit being validated. See GitHub authentication for the credentials it needs. |
| syntax |
[Valid Syntax Checker]
Reports if CODEOWNERS file contain invalid syntax definition. It is imported as: "If any line in your CODEOWNERS file contains invalid syntax, the file will not be detected and will not be used to request reviews. Invalid syntax includes inline comments and user or team names that do not exist on GitHub." source: https://help.github.com/articles/about-code-owners/#codeowners-syntax. |
The experimental checks are disabled by default:
| Name |
Description |
| notowned |
[Not Owned File Checker]
Reports files tracked in a given repository that no CODEOWNERS entry matches. |
| avoid-shadowing |
[Avoid Shadowing Checker]
Reports if entries go from least specific to most specific. Otherwise, earlier entries are completely ignored.
For example: # First entry /build/logs/ @octocat # Shadows * @s1 /b*/logs @s5 # OK /b*/other @o1 /script/* @o2 |
To enable experimental checks set the EXPERIMENTAL_CHECKS environment variable, for example EXPERIMENTAL_CHECKS=notowned.
No check reads the contents of any file but CODEOWNERS: files and notowned read the list of tracked files from Git's index, so a sparse, blobless checkout that contains only the CODEOWNERS file is enough.
Check the Configuration section for more info on how to enable and configure given checks.
Configuration
Use the following environment variables to configure the application:
| Name |
Default |
Description |
| REPOSITORY_PATH * |
|
Path to your repository on your local machine. A sparse checkout that contains only the CODEOWNERS file is enough. |
| TRUST_WORKSPACE |
false |
Specifies whether Git should trust the repository path even though another user owns it, for example when it's mounted into a container. See: https://github.com/actions/checkout/issues/766. |
| GITHUB_ACCESS_TOKEN |
|
GitHub token for the owners check. It needs read access to the repository contents, see GitHub authentication. Without credentials, the check only works for public repositories and is limited to 60 requests per hour. |
| GITHUB_BASE_URL |
https://api.github.com/ |
GitHub base URL for API requests. Defaults to the public GitHub API but can be set to a domain endpoint to use with GitHub Enterprise. |
| GITHUB_UPLOAD_URL |
https://uploads.github.com/ |
GitHub upload URL for uploading files. It is taken into account only when GITHUB_BASE_URL is also set. If only GITHUB_BASE_URL is provided, this parameter defaults to the GITHUB_BASE_URL value. |
| GITHUB_APP_ID |
|
GitHub App ID for authentication. When set, the app is used instead of GITHUB_ACCESS_TOKEN. Instruction for creating a GitHub App can be found here |
| GITHUB_APP_INSTALLATION_ID |
|
Github App Installation ID. Required when GITHUB_APP_ID is set. |
| GITHUB_APP_PRIVATE_KEY |
|
Github App private key in PEM format. Required when GITHUB_APP_ID is set. |
| CHECKS |
|
List of checks to be executed. By default, all checks are executed. Possible values: files,owners,duppatterns,syntax. |
| EXPERIMENTAL_CHECKS |
|
The comma-separated list of experimental checks that should be executed. By default, all experimental checks are turned off. Possible values: notowned,avoid-shadowing. |
| CHECK_FAILURE_LEVEL |
warning |
Defines the level on which the application should treat check issues as failures. Defaults to warning, which treats both errors and warnings as failures, and exits with error code 3. Possible values are error and warning. |
| OWNER_CHECKER_REPOSITORY * |
|
The owner and repository name separated by slash, for example gh-codeowners/codeowners-samples. The owners check validates this repository's CODEOWNERS file on GitHub. |
| OWNER_CHECKER_REF |
commit checked out in REPOSITORY_PATH |
The branch, tag, or commit SHA whose CODEOWNERS file the owners check validates. It must exist on GitHub. If REPOSITORY_PATH isn't a Git repository, defaults to the repository's default branch. |
| OWNER_CHECKER_IGNORED_OWNERS |
@ghost |
The comma-separated list of owners that should not be validated. Example: "@owner1,@owner2,@org/team1,example@email.com". |
| OWNER_CHECKER_ALLOW_UNOWNED_PATTERNS |
true |
Specifies whether CODEOWNERS may have unowned files. For example: /infra/oncall-rotator/ @sre-team /infra/oncall-rotator/oncall-config.yml The /infra/oncall-rotator/oncall-config.yml file is not owned by anyone. |
| OWNER_CHECKER_OWNERS_MUST_BE_TEAMS |
false |
Specifies whether only teams are allowed as owners of files. |
| NOT_OWNED_CHECKER_SKIP_PATTERNS |
|
The comma-separated list of patterns that should be ignored by not-owned-checker. For example, you can specify * and as a result, the * pattern from the CODEOWNERS file will be ignored and files owned by this pattern will be reported as unowned unless a later specific pattern will match that path. It's useful because often we have default owners entry at the begging of the CODOEWNERS file, e.g. * @global-owner1 @global-owner2 |
| NOT_OWNED_CHECKER_SUBDIRECTORIES |
|
The comma-separated list of subdirectories to check in not-owned-checker. When specified, only files in the listed subdirectories will be checked if they do not have specified owners in CODEOWNERS. |
* - Required (OWNER_CHECKER_REPOSITORY only by the owners check)
Exit status codes
Application exits with different status codes which allow you to easily distinguish between error categories.
| Code |
Description |
| 1 |
The application startup failed due to the wrong configuration or internal error. |
| 2 |
The application was closed because the OS sends a termination signal (SIGINT or SIGTERM). |
| 3 |
The CODEOWNERS validation failed - executed checks found some issues. |
Contributing
Contributions are greatly appreciated! The project follows the typical GitHub pull request model. See CONTRIBUTING.md for more details.