Test case #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check Lowercase Filenames | |
on: | |
pull_request: | |
paths: | |
- 'ct/*.sh' | |
- 'install/*.sh' | |
- 'json/*.json' | |
jobs: | |
check_lowercase: | |
runs-on: lxc | |
steps: | |
# Step 1: Checkout the code | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
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 3: Validate filenames are lowercase | |
- name: Validate filenames are lowercase | |
run: | | |
# Get the list of changed files | |
changed_files=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E '^(ct|install)/') | |
ERROR_COUNT=0 | |
# Process each file safely using newline as delimiter | |
echo "$changed_files" | while IFS= read -r FILE; 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 | |
# Fail the workflow if any errors are found | |
if [ "$ERROR_COUNT" -ne 0 ]; then | |
echo "$ERROR_COUNT script(s) have invalid filenames." | |
exit 1 | |
else | |
echo "All filenames passed the lowercase check." | |
fi |