|
| 1 | +name: "CodeOwners Enforcement" |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + |
| 6 | +jobs: |
| 7 | + enforce-codeowners: |
| 8 | + name: "Enforce" |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: read |
| 12 | + pull-requests: write |
| 13 | + env: |
| 14 | + COMMENT_FINGERPRINT: '<!-- chainlink-codeowners-enforcement -->' |
| 15 | + steps: |
| 16 | + - name: Checkout repo |
| 17 | + uses: actions/checkout@v5 |
| 18 | + with: |
| 19 | + fetch-depth: 1 |
| 20 | + persist-credentials: false |
| 21 | + |
| 22 | + - name: Check for CODEOWNERS file |
| 23 | + id: codeowners-file |
| 24 | + run: | |
| 25 | + # check at ./CODEOWNERS and .github/CODEOWNERS |
| 26 | + if [ ! -f CODEOWNERS ] && [ ! -f .github/CODEOWNERS ]; then |
| 27 | + echo "CODEOWNERS file not found" |
| 28 | + echo "found=false" | tee -a "$GITHUB_OUTPUT" |
| 29 | + else |
| 30 | + echo "found=true" | tee -a "$GITHUB_OUTPUT" |
| 31 | + fi |
| 32 | +
|
| 33 | + - name: Find PR Comment |
| 34 | + id: find-comment |
| 35 | + uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0 |
| 36 | + with: |
| 37 | + issue-number: ${{ github.event.number }} |
| 38 | + body-includes: ${{ env.COMMENT_FINGERPRINT }} |
| 39 | + |
| 40 | + - name: Upsert comment if no CODEOWNERS exists |
| 41 | + if: ${{ steps.codeowners-file.outputs.found == 'false' }} |
| 42 | + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 |
| 43 | + with: |
| 44 | + issue-number: ${{ github.event.number }} |
| 45 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 46 | + edit-mode: 'replace' |
| 47 | + body: | |
| 48 | + ### No CODEOWNERS file detected - @${{ github.actor }} |
| 49 | +
|
| 50 | + This repository doesn't contain a CODEOWNERS file. Please add one at one of the following paths: |
| 51 | + 1. `CODEOWNERS` (root of repository) |
| 52 | + 2. `.github/CODEOWNERS` |
| 53 | +
|
| 54 | + If this repository is owned/used by a single team the default entry for a CODEOWNERS would be: |
| 55 | +
|
| 56 | + ``` |
| 57 | + * @smartcontractkit/<your team> |
| 58 | + ``` |
| 59 | +
|
| 60 | + For more information see: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners |
| 61 | +
|
| 62 | + ${{ env.COMMENT_FINGERPRINT }} |
| 63 | +
|
| 64 | + - name: Update comment if CODEOWNERS was added |
| 65 | + if: ${{ steps.codeowners-file.outputs.found == 'true' && steps.find-comment.outputs.comment-id != '' }} |
| 66 | + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 |
| 67 | + with: |
| 68 | + issue-number: ${{ github.event.number }} |
| 69 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 70 | + edit-mode: 'replace' |
| 71 | + body: | |
| 72 | + Thank you for adding a CODEOWNERS file - @${{ github.actor }}. |
| 73 | +
|
| 74 | + ${{ env.COMMENT_FINGERPRINT }} |
| 75 | +
|
| 76 | + - name: Fail if no CODEOWNERS file is found |
| 77 | + if: ${{ steps.codeowners-file.outputs.found == 'false' }} |
| 78 | + run: | |
| 79 | + echo "::error::No CODEOWNERS file found." |
| 80 | + exit 1 |
0 commit comments