Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub actions: add new automation to limit directory sizes #17928

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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: 6 additions & 0 deletions .github/actions/verify-directory-sizes/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Verify directories are not too big
runs:
using: composite
steps:
- shell: bash
run: bash "${GITHUB_WORKSPACE}/.github/actions/verify-directory-sizes/script.sh"
47 changes: 47 additions & 0 deletions .github/actions/verify-directory-sizes/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

set -eu
set +x

# Bash script to check directory sizes, we want to keep each directory under
# at most 1000 entries so that the GitHub online interface can be used to
# browse without excluding files
MAX_DIR_SIZE=0
MAX_DIR_NAME=0

# This is enforced limit
DIR_SIZE_LIMIT=1000

check_directory () {
local CURR_DIR=$1
local CURR_DIR_SIZE=$(ls -l $CURR_DIR | wc -l)
if [ "$CURR_DIR_SIZE" -gt "$DIR_SIZE_LIMIT" ]; then
# Show the same message but in red
echo -e "\033[0;31m$CURR_DIR has $CURR_DIR_SIZE entries\033[0m"
else
echo "$CURR_DIR has $CURR_DIR_SIZE entries"
fi
if [ "$CURR_DIR_SIZE" -gt "$MAX_DIR_SIZE" ]; then
MAX_DIR_SIZE=$CURR_DIR_SIZE
MAX_DIR_NAME=$CURR_DIR
fi

# Sending stderr to /dev/null is used to suppress errors about no such
# file or directory when a directory has no sub directories
local SUBDIRS=$(ls -d $CURR_DIR*/ 2>/dev/null)
for SUBDIR in $SUBDIRS
do
check_directory $SUBDIR
done
}

check_directory ./

echo "Biggest directory: $MAX_DIR_NAME"
echo "Size: $MAX_DIR_SIZE"

if [ "$MAX_DIR_SIZE" -gt "$DIR_SIZE_LIMIT" ]; then
echo -e "\033[0;31mMaximum allowed size: $DIR_SIZE_LIMIT\033[0m"
# Action is unsuccessful
exit 1
fi
3 changes: 3 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ jobs:
- name: Verify generated files are up to date
if: ${{ !matrix.asan }}
uses: ./.github/actions/verify-generated-files
- name: Verify directories are not too big
if: ${{ !matrix.asan }}
uses: ./.github/actions/verify-directory-sizes
LINUX_X32:
if: github.repository == 'php/php-src' || github.event_name == 'pull_request'
name: LINUX_X32_DEBUG_ZTS
Expand Down
Loading