Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

CodeQL: run weekly and on dispatch only (#14953)

Daniel Han14e0178e0055
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
index 46e15b0b967..764468ece42 100644
--- a/.github/workflows/codeql.yml
+++ b/.github/workflows/codeql.yml
@@ -1,99 +1,30 @@
# CodeQL code scanning (advanced setup; replaces the repository's default setup).
#
# Coverage matches default setup: the same four languages, the default query suite and the
-# remote threat model. Every push to main and the weekly schedule analyse all four, which keeps
-# main's baseline current for each language. GitHub warns against path filters on push for
-# CodeQL, since each analysis is compared with the previous commit's, so push has none.
-#
-# What changes is pull requests: a PR analyses only the languages whose files it touches. A
-# language the PR does not touch cannot gain or lose an alert, and its analysis on main stays
-# the reference. Anything the changes job cannot classify (the file list fails to load, more
-# than 3000 files, or this workflow itself changes) analyses all four.
+# remote threat model. It runs weekly and on manual dispatch only, not on pull requests or
+# pushes to main. On pull requests it queued twice per push (a language picker, then up to four
+# analyses) behind the shared runner queue, and on main every merge built and cached a new
+# overlay-base database. A weekly analysis of main keeps the alerts current at a fraction of the
+# runner slots; dispatch it by hand to check a change sooner.
name: CodeQL
on:
- push:
- branches: [main]
- pull_request:
- branches: [main]
schedule:
- cron: "17 4 * * 1"
workflow_dispatch:
-# One group per ref, main included. On main a running analysis always finishes
-# (cancel-in-progress is PR-only), and a merge burst coalesces to the tip: GitHub keeps at most
-# one pending run per group and replaces it with the newest push. That is deliberate here, unlike
-# the test workflows: each analysis scans the whole tree, so the tip's analysis covers every
-# commit it supersedes, and alerts are compared with the last analysis of the branch, not the
-# previous commit. What per-commit analysis cost instead: on main each run saves a new
-# overlay-base database to the Actions cache (about 1.3 GB per commit across python and
-# javascript), and at 100+ commits a day that churn was evicting every other cache in the repo.
+# One group per ref. A dispatch while the weekly run is going waits for it rather than
+# cancelling it: each analysis scans the whole tree, so the later run covers the same commits.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
- cancel-in-progress: ${{ github.event_name == 'pull_request' }}
+ cancel-in-progress: false
permissions:
contents: read
jobs:
- changes:
- name: Languages to analyse
- runs-on: ubuntu-latest
- timeout-minutes: 5
- permissions:
- contents: read
- pull-requests: read
- outputs:
- languages: ${{ steps.pick.outputs.languages }}
- steps:
- - name: Pick languages
- id: pick
- env:
- GH_TOKEN: ${{ github.token }}
- EVENT: ${{ github.event_name }}
- REPO: ${{ github.repository }}
- PR: ${{ github.event.pull_request.number }}
- run: |
- set -uo pipefail
- all='["actions","javascript-typescript","python","rust"]'
- if [ "$EVENT" != "pull_request" ]; then
- echo "languages=$all" >> "$GITHUB_OUTPUT"
- echo "$EVENT: analysing all languages"
- exit 0
- fi
- # The files API returns at most 3000 files; at that size, or on any error, analyse all.
- if ! files=$(gh api --paginate "repos/$REPO/pulls/$PR/files?per_page=100" --jq '.[] | .filename, (.previous_filename // empty)'); then
- echo "languages=$all" >> "$GITHUB_OUTPUT"
- echo "could not list the PR's files: analysing all languages"
- exit 0
- fi
- # grep reads a here-string, not a pipe: with pipefail, grep -q closing a pipe early
- # makes the writer's SIGPIPE turn a match into a miss on long file lists.
- count=$(grep -c . <<< "$files" || true)
- if [ "$count" -ge 3000 ] || grep -qxE '\.github/workflows/codeql\.ya?ml|\.github/codeql/.*' <<< "$files"; then
- echo "languages=$all" >> "$GITHUB_OUTPUT"
- echo "$count files or a CodeQL config change: analysing all languages"
- exit 0
- fi
- langs=()
- has() { grep -qiE "$1" <<< "$files"; }
- has '^\.github/(workflows|actions)/|(^|/)action\.ya?ml$' && langs+=(actions)
- has '\.(js|jsx|mjs|cjs|ts|tsx|mts|cts|vue|html?|svelte)$|(^|/)(package(-lock)?\.json|tsconfig[^/]*\.json|jsconfig\.json|pnpm-lock\.yaml|yarn\.lock|bun\.lockb?)$' && langs+=(javascript-typescript)
- has '\.pyi?$' && langs+=(python)
- has '\.rs$|(^|/)Cargo\.(toml|lock)$' && langs+=(rust)
- if [ "${#langs[@]}" -eq 0 ]; then
- json='[]'
- else
- json=$(printf '"%s",' "${langs[@]}")
- json="[${json%,}]"
- fi
- echo "languages=$json" >> "$GITHUB_OUTPUT"
- echo "$count changed files: analysing $json"
-
analyze:
name: Analyze (${{ matrix.language }})
- needs: changes
- if: needs.changes.outputs.languages != '[]'
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
@@ -104,7 +35,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- language: ${{ fromJSON(needs.changes.outputs.languages) }}
+ language: [actions, javascript-typescript, python, rust]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
@@ -127,16 +58,16 @@ jobs:
# match by the prefix up to the CodeQL version and take the newest entry, so every older
# generation under the same prefix answers nothing and only holds budget.
#
- # cache-janitor.yml applies the same keep-1 rule, but it runs on a schedule and queued for
- # hours behind merge bursts while each analysed push added about 1.3 GB, which is what pushed
- # the repo to its 50 GiB ceiling and made GitHub evict everything else. Pruning here bounds the
- # family at write time; the janitor stays as the backstop. A separate job so actions: write is
+ # cache-janitor.yml applies the same keep-1 rule on its own schedule. When CodeQL analysed
+ # every push to main, each one added about 1.3 GB and the janitor fell behind, which is what
+ # pushed the repo to its 50 GiB ceiling. Pruning here bounds the family at write time; the
+ # janitor stays as the backstop. A separate job so actions: write is
# granted to this one shell step and never to the CodeQL action.
prune-overlay-bases:
name: Prune superseded CodeQL overlay bases
needs: analyze
- # Not on pull requests: PR analyses restore an overlay base but never save one.
- if: ${{ !cancelled() && github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && needs.analyze.result != 'skipped' }}
+ # Only main saves overlay bases; a dispatch on another branch has nothing to prune.
+ if: ${{ !cancelled() && github.ref == 'refs/heads/main' && needs.analyze.result != 'skipped' }}
# A rarely requested hosted label, so this API-only job starts in minutes while the
# ubuntu-latest queue is hours deep. It needs only gh and coreutils, both on the image.
runs-on: ubuntu-24.04-arm
diff --git a/tests/security/test_codeql_language_picker.py b/tests/security/test_codeql_language_picker.py
deleted file mode 100644
index 74ff8fb2ac3..00000000000
--- a/tests/security/test_codeql_language_picker.py
+++ /dev/null
@@ -1,105 +0,0 @@
-# SPDX-License-Identifier: AGPL-3.0-only
-# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
-"""Push, schedule and dispatch must analyse all four CodeQL languages, not just those a PR touches."""
-
-from __future__ import annotations
-
-import json
-import os
-import shutil
-import subprocess
-import sys
-from pathlib import Path
-
-import pytest
-import yaml
-
-ROOT = Path(__file__).resolve().parents[2]
-WORKFLOW = ROOT / ".github" / "workflows" / "codeql.yml"
-ALL = ["actions", "javascript-typescript", "python", "rust"]
-
-pytestmark = pytest.mark.skipif(
- sys.platform == "win32" or shutil.which("bash") is None, reason = "needs bash"
-)
-
-
-def _script() -> str:
- doc = yaml.safe_load(WORKFLOW.read_text(encoding = "utf-8"))
- return doc["jobs"]["changes"]["steps"][0]["run"]
-
-
-def _pick(
- tmp_path: Path,
- files: list[str] | None,
- event: str = "pull_request",
-) -> list[str]:
- bin_dir = tmp_path / "bin"
- bin_dir.mkdir(exist_ok = True)
- listing = tmp_path / "files.txt"
- gh = bin_dir / "gh"
- if files is None:
- gh.write_text("#!/bin/bash\nexit 1\n")
- else:
- listing.write_text("".join(f + "\n" for f in files))
- gh.write_text(f"#!/bin/bash\ncat '{listing}'\n")
- gh.chmod(0o755)
- out = tmp_path / "out.txt"
- out.write_text("")
- env = dict(
- os.environ,
- PATH = f"{bin_dir}{os.pathsep}{os.environ['PATH']}",
- GITHUB_OUTPUT = str(out),
- EVENT = event,
- REPO = "unslothai/unsloth",
- PR = "1",
- )
- subprocess.run(["bash", "-c", _script()], env = env, check = True, capture_output = True)
- return json.loads(out.read_text().strip().split("=", 1)[1])
-
-
[email protected]("event", ["push", "schedule", "workflow_dispatch"])
-def test_non_pull_request_events_analyse_everything(tmp_path, event):
- assert _pick(tmp_path, ["README.md"], event) == ALL
-
-
- "files, expected",
- [
- (["unsloth/models/llama.py"], ["python"]),
- (["studio/backend/stubs.pyi"], ["python"]),
- (["studio/frontend/src/app.tsx"], ["javascript-typescript"]),
- (["studio/frontend/package.json"], ["javascript-typescript"]),
- (["studio/frontend/tsconfig.app.json"], ["javascript-typescript"]),
- (["studio/frontend/index.html"], ["javascript-typescript"]),
- (["studio/src-tauri/src/main.rs"], ["rust"]),
- (["studio/src-tauri/Cargo.lock"], ["rust"]),
- ([".github/workflows/lint-ci.yml"], ["actions"]),
- ([".github/actions/setup/action.yml"], ["actions"]),
- (["README.md", "docs/guide.md", "studio/frontend/public/logo.png"], []),
- (["a.py", "b.ts", "c.rs", ".github/workflows/x.yml"], ALL),
- # A rename lists both names; the old one alone still counts.
- (["docs/moved.txt", "unsloth/old_name.py"], ["python"]),
- ],
-)
-def test_pull_requests_analyse_the_languages_they_touch(tmp_path, files, expected):
- assert _pick(tmp_path, files) == expected
-
-
-def test_a_codeql_config_change_analyses_everything(tmp_path):
- assert _pick(tmp_path, [".github/workflows/codeql.yml"]) == ALL
- assert _pick(tmp_path, [".github/codeql/codeql-config.yml"]) == ALL
-
-
-def test_an_unreadable_file_list_analyses_everything(tmp_path):
- assert _pick(tmp_path, None) == ALL
-
-
-def test_the_api_file_limit_analyses_everything(tmp_path):
- assert _pick(tmp_path, [f"docs/{i}.md" for i in range(3000)]) == ALL
-
-
-def test_an_early_match_in_a_long_list_is_not_lost(tmp_path):
- """grep -q stops reading at its first match; fed from a pipe under pipefail, the
- writer's SIGPIPE used to turn that match into a miss."""
- files = ["first.py"] + [f"docs/{'x' * 200}/{i}.md" for i in range(2998)]
- assert _pick(tmp_path, files) == ["python"]
diff --git a/tests/studio/test_main_runs_survive_merge_bursts.py b/tests/studio/test_main_runs_survive_merge_bursts.py
index f34329ab47a..df07da13a33 100644
--- a/tests/studio/test_main_runs_survive_merge_bursts.py
+++ b/tests/studio/test_main_runs_survive_merge_bursts.py
@@ -42,10 +42,9 @@ WORKFLOWS = REPO / ".github" / "workflows"
# Kaggle spends an external GPU quota rather than runner minutes.
QUOTA_BOUND = frozenset({"kaggle-t4-notebook-ci.yml", "kaggle-t4-studio-gpu-ci.yml"})
-# Allowed to keep a group per commit on main. codeql.yml analyses each main commit for code
-# scanning alerts and manages its own cache retention; it may coalesce too, so it is exempt
-# from the rule rather than required to break it.
-PER_COMMIT_ALLOWED = frozenset({"codeql.yml"})
+# Allowed to keep a group per commit on main, each with its reason. None today: codeql.yml was
+# the one entry, and it no longer runs on pushes to main.
+PER_COMMIT_ALLOWED = frozenset()
# Phrasings that assert a main run is never cancelled or that main is grouped per commit.
# Either is false for a workflow sharing one group across main commits: its PENDING run is