diff --git a/.github/workflows/validate-codeowners.yml b/.github/workflows/validate-codeowners.yml
index e7a8159d..d3d0b280 100644
--- a/.github/workflows/validate-codeowners.yml
+++ b/.github/workflows/validate-codeowners.yml
@@ -1,30 +1,41 @@
name: Validate Codeowners
on:
workflow_dispatch:
-
pull_request:
+permissions:
+ contents: read
+
jobs:
validate-codeowners:
runs-on: ubuntu-latest
steps:
- - name: "Checkout source code at current commit"
- uses: actions/checkout@v2
- # Leave pinned at 0.7.1 until https://github.com/mszostok/codeowners-validator/issues/173 is resolved
- - uses: mszostok/codeowners-validator@v0.7.1
- if: github.event.pull_request.head.repo.full_name == github.repository
- name: "Full check of CODEOWNERS"
- with:
- # For now, remove "files" check to allow CODEOWNERS to specify non-existent
- # files so we can use the same CODEOWNERS file for Terraform and non-Terraform repos
- # checks: "files,syntax,owners,duppatterns"
- checks: "syntax,owners,duppatterns"
- owner_checker_allow_unowned_patterns: "false"
- # GitHub access token is required only if the `owners` check is enabled
- github_access_token: "${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}"
- - uses: mszostok/codeowners-validator@v0.7.1
- if: github.event.pull_request.head.repo.full_name != github.repository
- name: "Syntax check of CODEOWNERS"
+ - name: Checkout source code at current commit
+ uses: actions/checkout@v4
+
+ - name: Check CODEOWNERS syntax and duplicate patterns
+ uses: mszostok/codeowners-validator@v0.7.1
with:
checks: "syntax,duppatterns"
owner_checker_allow_unowned_patterns: "false"
+
+ - name: Check owners with GitHub's CODEOWNERS validation
+ uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
+ with:
+ script: |
+ // GitHub resolves team membership and repository access server-side,
+ // so validation only needs the workflow's read-only repository token.
+ const { data } = await github.rest.repos.codeownersErrors({
+ ...context.repo,
+ ref: context.sha,
+ });
+ for (const error of data.errors) {
+ core.error(error.message, {
+ file: error.path,
+ startLine: error.line,
+ startColumn: error.column,
+ });
+ }
+ if (data.errors.length > 0) {
+ core.setFailed(`Found ${data.errors.length} CODEOWNERS errors`);
+ }
diff --git a/README.md b/README.md
index b536101b..6f695d53 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@

-