diff --git a/.github/actions/verify-directory-sizes/action.yml b/.github/actions/verify-directory-sizes/action.yml new file mode 100644 index 0000000000000..4bc7de81d4fa4 --- /dev/null +++ b/.github/actions/verify-directory-sizes/action.yml @@ -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" diff --git a/.github/actions/verify-directory-sizes/script.sh b/.github/actions/verify-directory-sizes/script.sh new file mode 100644 index 0000000000000..76b787fda78cd --- /dev/null +++ b/.github/actions/verify-directory-sizes/script.sh @@ -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 diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index b92a55b58b87d..262adb74f77af 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -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