Skip to content

Commit

Permalink
Check content dir for for file and folder name validity (#2427)
Browse files Browse the repository at this point in the history
  • Loading branch information
marians authored Dec 16, 2024
1 parent c14918c commit c5bfcb7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,46 @@ jobs:
exit 1
fi
- name: Check file and folder names in content
shell: python {0}
run: |
# Walk content folder, check file names to use only allowed characters
from pathlib import Path
import re
import os
import sys
allowed_chars = re.compile(r'^[a-z0-9-\.+]+$')
allowed_chars_static = re.compile(r'^[a-z0-9-\._]+$') # images etc. may use the underscore
content_dir = 'src/content'
errors = []
for root, dirs, files in os.walk(content_dir):
for file in files:
full_path = Path(root, file)
if full_path.name == '_index.md':
continue
if full_path.name == '_template.md.tpl':
continue
if full_path.suffix.lower() == '.md':
if not allowed_chars.match(full_path.stem):
errors.append(f"- FILE {full_path}")
else:
# static files
if not allowed_chars_static.match(full_path.name):
errors.append(f"- FILE {full_path}")
for dir in dirs:
if not allowed_chars.match(dir):
errors.append(f"- DIR {Path(root, dir)}")
if len(errors) > 0:
sys.stderr.write("The following file/folder names use invalid characters. Only lowercase letters, digits, hyphens and period are allowed.\n")
for error in errors:
sys.stderr.write(error + "\n")
sys.exit(1)
- name: Check for moved or deleted files
run: |
git --no-pager diff --name-status --diff-filter=RD "refs/heads/${GITHUB_BASE_REF}" -- . | tee files.txt
Expand Down

0 comments on commit c5bfcb7

Please sign in to comment.