|
| 1 | +name: Code Style Checker |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: # allows manual triggering |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - master |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + model-naming: |
| 18 | + runs-on: ubuntu-slim |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v6 |
| 21 | + - name: Check model naming conventions |
| 22 | + run: | |
| 23 | + python3 - << 'EOF' |
| 24 | + import re, os, sys |
| 25 | +
|
| 26 | + pairs = re.findall( |
| 27 | + r'case\s+(LLM_ARCH_\w+)\s*:\s*\n\s+return new (llama_model_\w+)\s*\(', |
| 28 | + open("src/llama-model.cpp").read()) |
| 29 | +
|
| 30 | + errors = [] |
| 31 | + for arch, cls in pairs: |
| 32 | + suffix = arch[len("LLM_ARCH_"):] |
| 33 | + csuffix = cls[len("llama_model_"):] |
| 34 | + fname = csuffix.replace("_", "-") + ".cpp" |
| 35 | +
|
| 36 | + if not re.fullmatch(r'[A-Z][A-Z0-9_]*', suffix): |
| 37 | + errors.append(f"{arch}: suffix not upper snake case, example: LLM_ARCH_MY_MODEL") |
| 38 | +
|
| 39 | + if not re.fullmatch(r'[a-z][a-z0-9_]*', csuffix): |
| 40 | + errors.append(f"{arch}: class suffix not lower snake case, example: llama_model_my_model") |
| 41 | +
|
| 42 | + elif suffix.lower() != csuffix: |
| 43 | + errors.append(f"{arch}: arch/class name mismatch, expected class 'llama_model_{suffix.lower()}' but got '{cls}'") |
| 44 | +
|
| 45 | + elif not os.path.isfile(f"src/models/{fname}"): |
| 46 | + errors.append(f"{arch}: expects model file name to be src/models/{fname}, but not found") |
| 47 | +
|
| 48 | + if errors: |
| 49 | + print('\n'.join(f" - {e}" for e in errors)); sys.exit(1) |
| 50 | + print(f"OK: {len(pairs)} mappings validated.") |
| 51 | + EOF |
0 commit comments