Skip to content

Commit

Permalink
Add check for file name validity
Browse files Browse the repository at this point in the history
  • Loading branch information
marians committed Dec 13, 2024
1 parent 3528121 commit c89bb55
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,31 @@ jobs:
exit 1
fi
- name: Check file names
shell: python {0}
continue-on-error: true
run: |
# Walk content folder, check file names to use only allowed characters
from pathlib import Path
import re
allowed_chars = re.compile(r'^[a-z0-9-]+$')
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.suffix.lower() !== '.md':
continue
if not allowed_chars.match(full_path.stem):
errors.append(f"- File name {full_path}' contains invalid characters. Only lowercase letters, digits, and hyphens are allowed.\n")
if len(errors) > 0:
print("The following file names use invalid characters. Only lowercase letters, digits, and hyphens are allowed.\n\n")
for error in errors:
print(error)
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 c89bb55

Please sign in to comment.