From cc13d8ea4fcb7ed91a2064aa50f6876db656c3a4 Mon Sep 17 00:00:00 2001 From: Erik Burton Date: Tue, 26 Aug 2025 10:50:15 -0700 Subject: [PATCH 1/3] feat(ci): codeowners enforcement workflow --- .github/workflows/codeowners-enforcement.yml | 80 ++++++++++++++++++++ README.md | 3 + 2 files changed, 83 insertions(+) create mode 100644 .github/workflows/codeowners-enforcement.yml diff --git a/.github/workflows/codeowners-enforcement.yml b/.github/workflows/codeowners-enforcement.yml new file mode 100644 index 0000000..b40e10f --- /dev/null +++ b/.github/workflows/codeowners-enforcement.yml @@ -0,0 +1,80 @@ +name: "CodeOwners Enforcement" + +on: + pull_request: + +jobs: + enforce-codeowners: + name: "Enforce" + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + env: + COMMENT_FINGERPRINT: '' + steps: + - name: Checkout repo + uses: actions/checkout@v5 + with: + fetch-depth: 1 + persist-credentials: false + + - name: Check for CODEOWNERS file + id: codeowners-file + run: | + # check at ./CODEOWNERS and .github/CODEOWNERS + if [ ! -f CODEOWNERS ] && [ ! -f .github/CODEOWNERS ]; then + echo "CODEOWNERS file not found" + echo "found=true" | tee -a "$GITHUB_OUTPUT" + else + echo "found=false" | tee -a "$GITHUB_OUTPUT" + fi + + - name: Find PR Comment + id: find-comment + uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0 + with: + issue-number: ${{ github.event.number }} + body-includes: ${{ env.COMMENT_FINGERPRINT }} + + - name: Upsert comment if no CODEOWNERS exists + if: ${{ steps.codeowners-file.outputs.found == 'false' }} + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 + with: + issue-number: ${{ github.event.number }} + comment-id: ${{ steps.find-comment.outputs.comment-id }} + edit-mode: 'replace' + body: | + ### No CODEOWNERS file detected - @${{ github.actor }} + + This repository doesn't contain a CODEOWNERS file. Please add one at one of the following paths: + 1. `CODEOWNERS` (root of repository) + 2. `.github/CODEOWNERS` + + If this repository is owned/used by a single team the default entry for a CODEOWNERS would be: + + ``` + * @smartcontractkit/ + ``` + + For more information see: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners + + ${{ env.COMMENT_FINGERPRINT }} + + - name: Update comment if CODEOWNERS was added + if: ${{ steps.codeowners-file.outputs.found == 'true' && steps.find-comment.outputs.comment-id != '' }} + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 + with: + issue-number: ${{ github.event.number }} + comment-id: ${{ steps.find-comment.outputs.comment-id }} + edit-mode: 'replace' + body: | + Thank you for adding a CODEOWNERS file - @${{ github.actor }}. + + ${{ env.COMMENT_FINGERPRINT }} + + - name: Fail if no CODEOWNERS file is found + if: ${{ steps.codeowners-file.outputs.found == 'false' }} + run: | + echo "::error::No CODEOWNERS file found." + exit 1 diff --git a/README.md b/README.md index 1288512..0346108 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ Uses [`gha-workflow-validator`](https://github.com/smartcontractkit/.github/tree Uses [patrickhuie19/codeowners-validator](https://github.com/patrickhuie19/codeowners-validator/) action. * Validates the contents of a CODEOWNERS file when it is modified. Enforces certain criteria to ensure healthy CODEOWNERS. +### CODEOWNERS Enforcement + +Enforces that every repository has a CODEOWNERS file. ## Help From 5409e5f4edc5b070c5037b9c6f482f8e44fa6916 Mon Sep 17 00:00:00 2001 From: Erik Burton Date: Tue, 26 Aug 2025 10:56:07 -0700 Subject: [PATCH 2/3] fix: un-reverse conditional --- .github/workflows/codeowners-enforcement.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeowners-enforcement.yml b/.github/workflows/codeowners-enforcement.yml index b40e10f..bcc5466 100644 --- a/.github/workflows/codeowners-enforcement.yml +++ b/.github/workflows/codeowners-enforcement.yml @@ -25,9 +25,9 @@ jobs: # check at ./CODEOWNERS and .github/CODEOWNERS if [ ! -f CODEOWNERS ] && [ ! -f .github/CODEOWNERS ]; then echo "CODEOWNERS file not found" - echo "found=true" | tee -a "$GITHUB_OUTPUT" - else echo "found=false" | tee -a "$GITHUB_OUTPUT" + else + echo "found=true" | tee -a "$GITHUB_OUTPUT" fi - name: Find PR Comment From dd54b1694f118d210f41400b303668b8f083215a Mon Sep 17 00:00:00 2001 From: Erik Burton Date: Tue, 26 Aug 2025 15:14:19 -0700 Subject: [PATCH 3/3] chore: empty commit to trigger dependency review