|
| 1 | +name: Filename Guard |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + |
| 7 | +jobs: |
| 8 | + check-filenames: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v4 |
| 12 | + |
| 13 | + - name: Check for unsafe filenames |
| 14 | + run: | |
| 15 | + echo "🔍 Scanning repository filenames for Windows/macOS unsafe characters..." |
| 16 | +
|
| 17 | + FAIL=0 |
| 18 | + # Space before extension |
| 19 | + if git ls-files | grep -qE '\s+\.[A-Za-z0-9]+$'; then |
| 20 | + echo "❌ Found files with a space before extension:" |
| 21 | + git ls-files | grep -E '\s+\.[A-Za-z0-9]+$' |
| 22 | + FAIL=1 |
| 23 | + fi |
| 24 | +
|
| 25 | + # Leading spaces |
| 26 | + if git ls-files | grep -qE '(^|/)[[:space:]]'; then |
| 27 | + echo "❌ Found files with leading spaces in names:" |
| 28 | + git ls-files | grep -E '(^|/)[[:space:]]' |
| 29 | + FAIL=1 |
| 30 | + fi |
| 31 | +
|
| 32 | + # Trailing spaces or dots |
| 33 | + if git ls-files | grep -qE '[[:space:]\.]+$'; then |
| 34 | + echo "❌ Found files with trailing spaces or dots:" |
| 35 | + git ls-files | grep -E '[[:space:]\.]+$' |
| 36 | + FAIL=1 |
| 37 | + fi |
| 38 | +
|
| 39 | + # Backticks |
| 40 | + if git ls-files | grep -q '\`'; then |
| 41 | + echo "❌ Found files with backticks in names:" |
| 42 | + git ls-files | grep '\`' |
| 43 | + FAIL=1 |
| 44 | + fi |
| 45 | +
|
| 46 | + # Windows reserved names |
| 47 | + if git ls-files | grep -qE '(^|/)(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\..*)?$'; then |
| 48 | + echo "❌ Found Windows reserved filenames:" |
| 49 | + git ls-files | grep -E '(^|/)(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\..*)?$' |
| 50 | + FAIL=1 |
| 51 | + fi |
| 52 | +
|
| 53 | + # Illegal characters |
| 54 | + if git ls-files | grep -qE '[<>:"\\|?*]'; then |
| 55 | + echo "❌ Found files with illegal characters: < > : \" \\ | ? *" |
| 56 | + git ls-files | grep -E '[<>:"\\|?*]' |
| 57 | + FAIL=1 |
| 58 | + fi |
| 59 | +
|
| 60 | + # Final status |
| 61 | + if [ $FAIL -eq 1 ]; then |
| 62 | + echo "❌ Filename guard check failed. Please sanitize filenames before committing." |
| 63 | + exit 1 |
| 64 | + else |
| 65 | + echo "✅ All filenames are safe!" |
| 66 | + fi |
0 commit comments