From 3796c94bad989f82d16594b5202e8adb51b979a4 Mon Sep 17 00:00:00 2001 From: Xuan-Son Nguyen Date: Wed, 13 May 2026 10:59:37 +0200 Subject: [PATCH] ci: validate model naming convention (#22680) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ci: validate model naming convention * bring back dedicated ec workflow * add missing jobs --------- Co-authored-by: Sigbjørn Skjæret --- .github/workflows/code-style.yml | 51 ++++++++++++++++++++++++++++++ .github/workflows/editorconfig.yml | 5 --- 2 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/code-style.yml diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml new file mode 100644 index 000000000..c88396c0a --- /dev/null +++ b/.github/workflows/code-style.yml @@ -0,0 +1,51 @@ +name: Code Style Checker + +on: + workflow_dispatch: # allows manual triggering + push: + branches: + - master + pull_request: + branches: + - master + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }} + cancel-in-progress: true + +jobs: + model-naming: + runs-on: ubuntu-slim + steps: + - uses: actions/checkout@v6 + - name: Check model naming conventions + run: | + python3 - << 'EOF' + import re, os, sys + + pairs = re.findall( + r'case\s+(LLM_ARCH_\w+)\s*:\s*\n\s+return new (llama_model_\w+)\s*\(', + open("src/llama-model.cpp").read()) + + errors = [] + for arch, cls in pairs: + suffix = arch[len("LLM_ARCH_"):] + csuffix = cls[len("llama_model_"):] + fname = csuffix.replace("_", "-") + ".cpp" + + if not re.fullmatch(r'[A-Z][A-Z0-9_]*', suffix): + errors.append(f"{arch}: suffix not upper snake case, example: LLM_ARCH_MY_MODEL") + + if not re.fullmatch(r'[a-z][a-z0-9_]*', csuffix): + errors.append(f"{arch}: class suffix not lower snake case, example: llama_model_my_model") + + elif suffix.lower() != csuffix: + errors.append(f"{arch}: arch/class name mismatch, expected class 'llama_model_{suffix.lower()}' but got '{cls}'") + + elif not os.path.isfile(f"src/models/{fname}"): + errors.append(f"{arch}: expects model file name to be src/models/{fname}, but not found") + + if errors: + print('\n'.join(f" - {e}" for e in errors)); sys.exit(1) + print(f"OK: {len(pairs)} mappings validated.") + EOF diff --git a/.github/workflows/editorconfig.yml b/.github/workflows/editorconfig.yml index a2d4d0a3a..53f6a0ccf 100644 --- a/.github/workflows/editorconfig.yml +++ b/.github/workflows/editorconfig.yml @@ -2,11 +2,6 @@ name: EditorConfig Checker on: workflow_dispatch: # allows manual triggering - inputs: - create_release: - description: 'Create new release' - required: true - type: boolean push: branches: - master