78 lines
2.1 KiB
YAML
78 lines
2.1 KiB
YAML
name: CI
|
|
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches:
|
|
- main
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
validate:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
|
|
- name: Validate repository metadata
|
|
run: |
|
|
python - <<'PY'
|
|
import json
|
|
import pathlib
|
|
import sys
|
|
|
|
root = pathlib.Path('.')
|
|
errors = []
|
|
|
|
package_path = root / 'package.json'
|
|
try:
|
|
package = json.loads(package_path.read_text(encoding='utf-8'))
|
|
except Exception as exc:
|
|
errors.append(f"package.json is not valid JSON: {exc}")
|
|
else:
|
|
for key in ('name', 'version', 'main', 'package_version'):
|
|
if key not in package or package[key] in (None, ''):
|
|
errors.append(f"package.json is missing required key: {key}")
|
|
|
|
required_docs = [
|
|
'README.md',
|
|
'README_CN.md',
|
|
'LICENSE',
|
|
'CHANGELOG.md',
|
|
'CONTRIBUTING.md',
|
|
]
|
|
for relative in required_docs:
|
|
if not (root / relative).exists():
|
|
errors.append(f"Missing required repository file: {relative}")
|
|
|
|
forbidden_paths = []
|
|
for path in root.rglob('*'):
|
|
if '.git' in path.parts:
|
|
continue
|
|
if path.name == '.DS_Store' or '.idea' in path.parts or 'library' in path.parts or 'Library' in path.parts:
|
|
forbidden_paths.append(str(path))
|
|
|
|
if forbidden_paths:
|
|
errors.append('Repository contains local junk files:\n- ' + '\n- '.join(sorted(forbidden_paths)))
|
|
|
|
if errors:
|
|
print('Validation failed:\n')
|
|
for error in errors:
|
|
print(f'- {error}')
|
|
sys.exit(1)
|
|
|
|
print('Repository validation passed.')
|
|
PY
|
|
|
|
- name: Run syntax checks
|
|
run: npm run check
|
|
|
|
- name: Run tests
|
|
run: npm test
|