-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathbackend_reiew_group_codeowners.yml
More file actions
141 lines (120 loc) Β· 4.92 KB
/
backend_reiew_group_codeowners.yml
File metadata and controls
141 lines (120 loc) Β· 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Check CODEOWNERS for Backend Review Group Directory Assignments
on:
pull_request:
paths:
- '.github/CODEOWNERS'
permissions:
contents: read
pull-requests: write
jobs:
check-codeowners:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v41
with:
files: .github/CODEOWNERS
- name: Check for backend-review-group directory assignments
if: steps.changed-files.outputs.any_changed == 'true'
id: check
continue-on-error: true
run: |
#!/bin/bash
set -e
echo "π Checking for backend-review-group assignments to directories..."
echo ""
# Get the diff for CODEOWNERS file
git diff origin/master/.github/CODEOWNERS .github/CODEOWNERS > codeowners.diff
# Initialize arrays and counters
declare -a violations
violation_count=0
file_count=0
# Process additions
while IFS= read -r line; do
# Process added lines only
if [[ "$line" =~ ^\\+ ]] && [[ ! "$line" =~ ^\\+\\+\\+ ]] && [[ ! "$line" =~ ^\\+--- ]]; then
clean_line="${line:1}"
# Skip empty lines and comments
if [[ -z "$clean_line" ]] || [[ "$clean_line" =~ ^[[:space:]]*# ]]; then
continue
fi
# Check if line contains backend-review-group
if [[ "$clean_line" =~ backend-review-group ]]; then
path=$(echo "$clean_line" | awk '{print $1}')
# Determine if it's a directory
is_directory=false
if [[ "$path" =~ /$ ]]; then
is_directory=true
elif [[ ! "$path" =~ \.[a-zA-Z0-9]+$ ]]; then
# Exception for Makefile, README, etc.
if [[ ! "$path" =~ ^[A-Z][a-z]*file$ ]] && [[ ! "$path" =~ ^README ]] && [[ ! "$path" =~ ^LICENSE ]]; then
is_directory=true
fi
fi
if [ "$is_directory" = true ]; then
violations+=("$path")
((violation_count++))
echo "β οΈ Directory: $path"
else
((file_count++))
echo "β File: $path"
fi
fi
fi
done < codeowners.diff
# Save outputs BEFORE any exit
echo "violation_count=$violation_count" >> $GITHUB_OUTPUT
echo "file_count=$file_count" >> $GITHUB_OUTPUT
# Save violations as multiline string
if [ $violation_count -gt 0 ]; then
{
echo "violations<<EOF"
printf '%s\n' "${violations[@]}"
echo "EOF"
} >> $GITHUB_OUTPUT
fi
# Generate summary
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
echo " SUMMARY "
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
echo "π Statistics:"
echo " β’ Directory assignments added: $violation_count"
echo " β’ File assignments added: $file_count"
echo ""
# Determine exit code
if [ $violation_count -eq 0 ]; then
echo "β
PASSED: No directory assignments detected"
echo ""
if [ $file_count -gt 0 ]; then
echo "β All $file_count backend-review-group assignments are for specific files"
fi
exit 0
else
echo "β FAILED: Found $violation_count directory assignment(s)"
echo ""
echo "Directory assignments detected:"
for violation in "${violations[@]}"; do
echo " β’ $violation"
done
echo ""
echo "ββββββββββββββββββββββββββββββββββββββββββββββββ"
echo ""
echo "β οΈ WARNING"
echo "Assigning backend-review-group to directories causes"
echo "automatic assignment for ALL new files created by"
echo "other VFS teams in those directories."
echo ""
exit 1
fi
- name: Fail workflow if violations found
if: steps.check.outputs.violation_count != '' && steps.check.outputs.violation_count != '0'
run: |
echo "β Workflow failed due to ${{ steps.check.outputs.violation_count }} directory assignment(s)"
exit 1