Skip to content

Commit b2aba3b

Browse files
authored
feat(ci): codeowners enforcement workflow (#13)
* feat(ci): codeowners enforcement workflow * fix: un-reverse conditional * chore: empty commit to trigger dependency review
1 parent ce897b5 commit b2aba3b

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Uses [`gha-workflow-validator`](https://github.com/smartcontractkit/.github/tree
2323
Uses [patrickhuie19/codeowners-validator](https://github.com/patrickhuie19/codeowners-validator/) action.
2424
* Validates the contents of a CODEOWNERS file when it is modified. Enforces certain criteria to ensure healthy CODEOWNERS.
2525

26+
### CODEOWNERS Enforcement
27+
28+
Enforces that every repository has a CODEOWNERS file.
2629

2730
## Help
2831

0 commit comments

Comments
 (0)