Co-authored-by: ArtemFilin1990 <221041513+ArtemFilin1990@users.noreply.github.com>
243 lines
6.7 KiB
YAML
243 lines
6.7 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: ["**"]
|
|
pull_request:
|
|
branches: ["**"]
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.11"
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
python -m pip install -r requirements.txt
|
|
|
|
- name: Normalize datasets
|
|
run: python scripts/update_repo.py --no-report
|
|
|
|
- name: Check for duplicate keys in nomenclature
|
|
run: |
|
|
echo "Checking nomenclature.csv for duplicate keys..."
|
|
python -c "
|
|
import csv
|
|
from pathlib import Path
|
|
csv_file = Path('data/nomenclature.csv')
|
|
with csv_file.open(encoding='utf-8') as f:
|
|
reader = csv.DictReader(f)
|
|
seen = set()
|
|
duplicates = []
|
|
for line_num, row in enumerate(reader, start=2):
|
|
key = (row['Brand'], row['Product Name'])
|
|
if key in seen:
|
|
duplicates.append((key, line_num))
|
|
seen.add(key)
|
|
if duplicates:
|
|
print(f'ERROR: Found {len(duplicates)} duplicate keys:')
|
|
for key, line_num in duplicates[:10]:
|
|
print(f' - {key} at line {line_num}')
|
|
exit(1)
|
|
else:
|
|
print('✓ No duplicate keys found')
|
|
"
|
|
|
|
- name: Run validations
|
|
run: python scripts/validate/run_validations.py
|
|
|
|
- name: Run tests
|
|
run: python -m pytest -q
|
|
|
|
validate-structure:
|
|
name: Validate Repository Structure
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Check required directories exist
|
|
run: |
|
|
echo "Checking repository structure..."
|
|
required_dirs=(
|
|
"docs/bearings/designations"
|
|
"docs/bearings/analogues"
|
|
"docs/bearings/brands"
|
|
"docs/bearings/standards"
|
|
"docs/bearings/classification"
|
|
"docs/bearings/catalog"
|
|
"docs/bearings/faq"
|
|
"docs/bearings/training"
|
|
"sources"
|
|
)
|
|
|
|
for dir in "${required_dirs[@]}"; do
|
|
if [ ! -d "$dir" ]; then
|
|
echo "❌ Missing required directory: $dir"
|
|
exit 1
|
|
else
|
|
echo "✅ Found: $dir"
|
|
fi
|
|
done
|
|
|
|
- name: Check required files exist
|
|
run: |
|
|
echo "Checking required files..."
|
|
required_files=(
|
|
"README.md"
|
|
"LICENSE"
|
|
"CONTRIBUTING.md"
|
|
".gitignore"
|
|
"AGENT.md"
|
|
)
|
|
|
|
for file in "${required_files[@]}"; do
|
|
if [ ! -f "$file" ]; then
|
|
echo "❌ Missing required file: $file"
|
|
exit 1
|
|
else
|
|
echo "✅ Found: $file"
|
|
fi
|
|
done
|
|
|
|
validate-links:
|
|
name: Validate Markdown Links
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Check for broken internal links
|
|
run: |
|
|
echo "Checking for broken relative links in markdown files..."
|
|
exit_code=0
|
|
|
|
# Find all markdown files
|
|
while IFS= read -r file; do
|
|
echo "Checking $file..."
|
|
|
|
# Extract markdown links [text](path)
|
|
grep -oP '\]\(\K[^)]+' "$file" 2>/dev/null | while IFS= read -r link; do
|
|
# Skip external links (http/https)
|
|
if [[ "$link" =~ ^https?:// ]]; then
|
|
continue
|
|
fi
|
|
|
|
# Skip anchors only
|
|
if [[ "$link" =~ ^# ]]; then
|
|
continue
|
|
fi
|
|
|
|
# Remove anchor from link
|
|
link_path="${link%%#*}"
|
|
|
|
# Skip empty paths
|
|
if [ -z "$link_path" ]; then
|
|
continue
|
|
fi
|
|
|
|
# Get directory of current file
|
|
file_dir=$(dirname "$file")
|
|
|
|
# Resolve relative path
|
|
if [[ "$link_path" = /* ]]; then
|
|
target_path="${link_path#/}"
|
|
else
|
|
target_path="$file_dir/$link_path"
|
|
fi
|
|
|
|
# Normalize path
|
|
target_path=$(realpath -m "$target_path" 2>/dev/null || echo "$target_path")
|
|
|
|
# Check if target exists
|
|
if [ ! -e "$target_path" ] && [ ! -e "${target_path}.md" ]; then
|
|
echo " ⚠️ Potential broken link in $file: $link -> $target_path"
|
|
fi
|
|
done
|
|
done < <(find . -name "*.md" -type f)
|
|
|
|
validate-format:
|
|
name: Validate File Formatting
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Check for source citations in technical files
|
|
run: |
|
|
echo "Checking for source citations in documentation files..."
|
|
|
|
# Check technical documentation files for source references
|
|
find docs/bearings -name "*.md" -type f | while IFS= read -r file; do
|
|
# Skip README files and index files
|
|
if [[ "$file" =~ README\.md$ ]]; then
|
|
continue
|
|
fi
|
|
|
|
# Check if file contains source references
|
|
if ! grep -qiE '(ГОСТ|ISO|DIN|Источник:|Source:|aprom\.by|catalog)' "$file" 2>/dev/null; then
|
|
echo " ⚠️ File may be missing source citations: $file"
|
|
fi
|
|
done
|
|
|
|
echo "✅ Source citation check complete"
|
|
|
|
python-tests:
|
|
name: Python Script Tests
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: '3.11'
|
|
|
|
- name: Validate Python scripts
|
|
run: |
|
|
echo "Validating Python scripts..."
|
|
|
|
# Check if Python scripts exist and are valid
|
|
python_files=$(find sources -name "*.py" -type f)
|
|
|
|
for file in $python_files; do
|
|
echo "Checking $file..."
|
|
python -m py_compile "$file"
|
|
echo "✅ $file is valid"
|
|
done
|
|
|
|
json-validation:
|
|
name: Validate JSON Files
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Validate JSON syntax
|
|
run: |
|
|
echo "Validating JSON files..."
|
|
|
|
json_files=$(find . -name "*.json" -type f)
|
|
|
|
for file in $json_files; do
|
|
echo "Checking $file..."
|
|
if python3 -m json.tool "$file" > /dev/null 2>&1; then
|
|
echo "✅ $file is valid JSON"
|
|
else
|
|
echo "❌ $file has invalid JSON syntax"
|
|
exit 1
|
|
fi
|
|
done
|