Skip to content

Commit

Permalink
Update GHA for deleted files (#13812)
Browse files Browse the repository at this point in the history
* test deletion

* test deletion vs codeowners

* update logic and debugging

* copy/paste oopsie

* test out the delete action

* remove continue on error

* Revert "test out the delete action"

This reverts commit dffde55aa2d363c34f2fdc644d933c9586802a1f.
  • Loading branch information
LindseySaari committed Sep 13, 2023
1 parent c947c04 commit 9e6a303
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
27 changes: 13 additions & 14 deletions .github/scripts/check_deleted_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ DELETED_FILES=$(git diff --name-only --diff-filter=D ${BASE_SHA}...${HEAD_SHA})
file_in_codeowners() {
local file="$1"
while [[ "$file" != '.' && "$file" != '/' ]]; do
echo "Checking CODEOWNERS for: $file"
# Check for exact match or trailing slash
if grep -qE "^\s*${file}(/)?(\s|\$)" .github/CODEOWNERS; then
echo "Found in CODEOWNERS: $file"
Expand All @@ -32,26 +33,24 @@ file_in_codeowners() {
return 0
fi
# Move to the parent directory
echo "PARENT DIR: Checking CODEOWNERS for: $file"
file=$(dirname "$file")
done
return 1
}

for FILE in $DELETED_FILES
do
# Check if the deleted file's or its parent directory's reference is still in CODEOWNERS
for FILE in $DELETED_FILES; do
# Ignore files starting with a dot
if [[ $FILE == .* ]]; then
echo "Ignoring file $FILE"
continue
fi

echo "Checking file: $FILE"
if file_in_codeowners "$FILE"; then
# Check if other files in the same directory still exist
PARENT_DIR=$(dirname "$FILE")
if [ "$(ls -A "$PARENT_DIR" 2>/dev/null)" ]; then
# Other files in the directory still exist, so it's okay
continue
else
# The entire directory has been deleted, but its reference still exists in CODEOWNERS
echo "Error: $FILE (or its parent directories) is deleted but its reference still exists in CODEOWNERS."
echo "offending_file=$FILE" >> $GITHUB_ENV
exit 1
fi
echo "Error: $FILE (or its parent directories) is deleted but its reference still exists in CODEOWNERS."
echo "offending_file=$FILE" >> $GITHUB_ENV
exit 1
fi
done

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/check_codeowners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ jobs:
GITHUB_TOKEN: ${{ env.VA_VSP_BOT_GITHUB_TOKEN }}

- name: Check CODEOWNERS for removal when files deleted
continue-on-error: true
id: check_deleted_files
run: |
chmod +x .github/scripts/check_deleted_files.sh
Expand Down

0 comments on commit 9e6a303

Please sign in to comment.