mirror of
https://github.com/NatsumeLS/Gakumas-Translation-Data-EN.git
synced 2026-02-04 09:04:54 +00:00
chore: Add resource validation workflow and script
This commit is contained in:
11
.github/workflows/dispatch.yml
vendored
11
.github/workflows/dispatch.yml
vendored
@@ -11,12 +11,21 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Validate
|
- name: Setup Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.12'
|
||||||
|
|
||||||
|
- name: Validate JSON and YAML
|
||||||
id: json-yaml-validate
|
id: json-yaml-validate
|
||||||
uses: GrantBirki/json-yaml-validate@v3
|
uses: GrantBirki/json-yaml-validate@v3
|
||||||
with:
|
with:
|
||||||
use_gitignore: false
|
use_gitignore: false
|
||||||
|
|
||||||
|
- name: Validate Resource
|
||||||
|
id: resource-validate
|
||||||
|
run: python ./scripts/resource_validator.py ./local-files/resource
|
||||||
|
|
||||||
dispatch:
|
dispatch:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
50
scripts/resource_validator.py
Normal file
50
scripts/resource_validator.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
def check_syntax(file_path):
|
||||||
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||||||
|
lines = file.readlines()
|
||||||
|
|
||||||
|
errors = []
|
||||||
|
for line_number, line in enumerate(lines, 1):
|
||||||
|
if not re.match(r'^\[.*\]$', line.strip()) and line.strip():
|
||||||
|
errors.append(f"Error: ❌ Syntax error in {file_path} on line {line_number}")
|
||||||
|
|
||||||
|
return errors
|
||||||
|
|
||||||
|
def check_directory(directory):
|
||||||
|
all_errors = []
|
||||||
|
valid_files_count = 0
|
||||||
|
invalid_files_count = 0
|
||||||
|
|
||||||
|
for root, _, files in os.walk(directory):
|
||||||
|
for file in files:
|
||||||
|
if file.endswith(".txt"):
|
||||||
|
file_path = os.path.join(root, file)
|
||||||
|
errors = check_syntax(file_path)
|
||||||
|
if errors:
|
||||||
|
all_errors.extend(errors)
|
||||||
|
invalid_files_count += 1
|
||||||
|
else:
|
||||||
|
valid_files_count += 1
|
||||||
|
|
||||||
|
return all_errors, valid_files_count, invalid_files_count
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print("Usage: python resource_validator.py <directory_path>")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
directory_path = sys.argv[1]
|
||||||
|
errors, valid_files_count, invalid_files_count = check_directory(directory_path)
|
||||||
|
|
||||||
|
if errors:
|
||||||
|
for error in errors:
|
||||||
|
print(error)
|
||||||
|
print(f"\nError: ❌ {invalid_files_count} files have syntax errors.")
|
||||||
|
else:
|
||||||
|
print("✅ No syntax errors found.")
|
||||||
|
|
||||||
|
print(f"✅ {valid_files_count} files are valid.")
|
||||||
|
sys.exit(1 if errors else 0)
|
||||||
Reference in New Issue
Block a user