[GitHub Action] Add filename case check (#1228)

This commit is contained in:
Kristo Copani 2025-01-04 13:51:34 +02:00 committed by GitHub
parent 8a35df4f59
commit eee58b43db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

92
.github/workflows/check-lowercase.yml vendored Normal file
View File

@ -0,0 +1,92 @@
name: Check Lowercase Filenames
on:
pull_request:
paths:
- 'ct/*.sh'
- 'install/*.sh'
- 'json/*.json'
jobs:
check_lowercase:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensure the full history is fetched for accurate diffing
# Step 2: Fetch the base branch
- name: Fetch base branch
run: git fetch origin ${{ github.base_ref }}
# Step 3a: Validate filenames in ct directory
- name: "Validate filenames in ct directory"
run: |
changed_files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '^ct/.*\.sh$')
ERROR_COUNT=0
for FILE in $changed_files; do
BASENAME=$(basename "$FILE")
if [[ "$BASENAME" =~ ^[a-z0-9._-]+$ ]]; then
echo "$FILE: Check for lowercase in filename passed."
else
echo "Error in $FILE. Change filename to lowercase."
ERROR_COUNT=$((ERROR_COUNT + 1))
fi
done
if [ "$ERROR_COUNT" -ne 0 ]; then
exit 1
else
echo "All filenames in ct directory passed the lowercase check."
fi
# Step 3b: Validate filenames in install directory
- name: "Validate filenames in install directory"
run: |
changed_files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '^install/.*\.sh$')
ERROR_COUNT=0
for FILE in $changed_files; do
BASENAME=$(basename "$FILE")
if [[ "$BASENAME" =~ ^[a-z0-9._-]+$ ]]; then
echo "$FILE: Check for lowercase in filename passed."
else
echo "Error in $FILE. Change filename to lowercase."
ERROR_COUNT=$((ERROR_COUNT + 1))
fi
done
if [ "$ERROR_COUNT" -ne 0 ]; then
exit 1
else
echo "All filenames in install directory passed the lowercase check."
fi
# Step 3c: Validate filenames in json directory
- name: "Validate filenames in json directory."
run: |
changed_files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '^json/.*\.json$')
ERROR_COUNT=0
for FILE in $changed_files; do
BASENAME=$(basename "$FILE")
if [[ "$BASENAME" =~ ^[a-z0-9._-]+$ ]]; then
echo "$FILE: Check for lowercase in filename passed."
else
echo "Error in $FILE. Change filename to lowercase."
ERROR_COUNT=$((ERROR_COUNT + 1))
fi
done
if [ "$ERROR_COUNT" -ne 0 ]; then
exit 1
else
echo "All filenames in json directory passed the lowercase check."
fi