Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/codeowners-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:

- name: Ensure each CODEOWNER is a team
if: always()
run: ./validate-codeowners.sh ownersAreTeams
run: ./eng/validate-codeowners.sh ownersAreTeams

- name: Check each Dockerfile for a CODEOWNER
if: always()
run: ./validate-codeowners.sh dockerfilesHaveOwners
run: ./eng/validate-codeowners.sh dockerfilesHaveOwners

- name: Check for unused CODEOWNER paths
if: always()
run: ./validate-codeowners.sh pathsAreUsed
run: ./eng/validate-codeowners.sh pathsAreUsed
5 changes: 2 additions & 3 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://help.github.com/articles/about-code-owners/

### General infra ###
/* @dotnet/dotnet-docker-reviewers
* @dotnet/dotnet-docker-reviewers
eng/ @dotnet/dotnet-docker-reviewers

### Dockerfiles ###
Expand All @@ -16,7 +16,7 @@ src/**/webassembly*/ @dotnet/runtime-infrastructure
src/almalinux/**/source-build/ @dotnet/source-build-internal

# alpine
src/alpine/**/amd64/ @dotnet/dotnet-source-build-internal
src/alpine/**/amd64/ @dotnet/source-build-internal

# azurelinux
src/azurelinux/**/android/ @dotnet/runtime-infrastructure
Expand All @@ -35,7 +35,6 @@ src/centos/stream9/amd64/ @dotnet/source-build-internal

# debian
src/debian/11/amd64/ @dotnet/source-build-internal
src/debian/11/arm64v8/ @dotnet/source-build-internal
src/debian/11/opt/arm64v8/ @dotnet/runtime-infrastructure
src/debian/12/gcc14/amd64/ @dotnet/runtime-infrastructure

Expand Down
39 changes: 27 additions & 12 deletions validate-codeowners.sh → eng/validate-codeowners.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

if [ $# -eq 0 ]; then
echo "No function name provided. Usage: ./test.sh <ownersAreTeams|pathsAreUsed|dockerfilesHaveOwners>"
echo "No function name provided. Usage: ./validate-codeowners.sh <ownersAreTeams|pathsAreUsed|dockerfilesHaveOwners>"
exit 1
fi

Expand All @@ -18,8 +18,9 @@ readCodeOwnersFile() {
fi

while IFS= read -r line; do
# Skip blank lines and comments
if [[ "$line" =~ ^\s*# ]] || [[ -z "$line" ]] || [[ "$line" =~ ^[[:space:]]*$ ]]; then

# Skip blank lines, comments, and * paths
if [[ "$line" =~ ^[[:space:]]*# ]] || [[ "$line" =~ ^[[:space:]]*$ ]] || [[ "$line" =~ ^\*[[:space:]] ]]; then
continue
fi

Expand All @@ -29,16 +30,30 @@ readCodeOwnersFile() {
# Escape periods
path=$(echo "$path" | sed 's/\./\\./g')

# Single * matches anything that is not a slash
# Double ** matches anything
# Trailing / matches anything
# Remove leading slashes
path=$(echo "$path" | sed -E 's/([^*]|^)\*([^*]|$)/\1[^\/]*\2/g')
path=$(echo "$path" | sed 's/\*\*/.*/g')
# A single asterisk matches anything that is not a slash (as long as it is not at the beginning of a pattern)
if [[ ! "$path" =~ ^\* ]]; then
path=$(echo "$path" | sed -E 's/([^*]|^)\*([^*]|$)/\1[^\/]*\2/g')
fi

# Trailing /** and leading **/ should match anything in all directories
path=$(echo "$path" | sed 's/\/\*\*$/\/.*/g')
path=$(echo "$path" | sed 's/^\*\*\//.*\//g')

# /**/ matches zero or more directories
path=$(echo "$path" | sed 's/\/\*\*\//\/.*/g')

# If the asterisk is at the beginning of the pattern or the pattern does not start with a slash, then match everything
if [[ "$path" =~ ^\* ]]; then
path=".$path"
elif [[ ! "$path" =~ ^/ && ! "$path" =~ ^\.\* ]]; then
path=".*$path"
fi

# If there is a trailing slash, then match everything below the directory
if [[ "${path: -1}" == "/" ]]; then
path="$path.*"
fi
path=$(echo "$path" | sed 's/^\///')

path="^$path$"

# Use git check-ignore to determine if the path matches the patterns
Expand All @@ -65,7 +80,7 @@ ownersAreTeams() {
}

pathsAreUsed() {
allFiles=$(find . -type f | sed 's/^\.\///')
allFiles=$(find . -type f | sed 's/^\.//')
unusedPaths=()

for path in "${!codeOwnerEntries[@]}"; do
Expand Down Expand Up @@ -94,7 +109,7 @@ pathsAreUsed() {
}

dockerfilesHaveOwners() {
dockerfiles=$(find . -type f -name "Dockerfile" | sed 's/^\.\///')
dockerfiles=$(find . -type f -name "Dockerfile" | sed 's/^\.//')
filesWithoutOwner=()

for file in $dockerfiles; do
Expand Down