run-codeql 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- run_codeql-1.0.0/.github/workflows/ci.yml +35 -0
- run_codeql-1.0.0/.github/workflows/release.yml +40 -0
- run_codeql-1.0.0/.gitignore +14 -0
- run_codeql-1.0.0/LICENSE +21 -0
- run_codeql-1.0.0/Makefile +40 -0
- run_codeql-1.0.0/PKG-INFO +275 -0
- run_codeql-1.0.0/README.md +225 -0
- run_codeql-1.0.0/pyproject.toml +68 -0
- run_codeql-1.0.0/run_codeql/__init__.py +1 -0
- run_codeql-1.0.0/run_codeql/__main__.py +3 -0
- run_codeql-1.0.0/run_codeql/cli.py +224 -0
- run_codeql-1.0.0/run_codeql/download.py +158 -0
- run_codeql-1.0.0/run_codeql/logging_utils.py +28 -0
- run_codeql-1.0.0/run_codeql/sarif.py +138 -0
- run_codeql-1.0.0/run_codeql/scanner.py +144 -0
- run_codeql-1.0.0/run_codeql/settings.py +78 -0
- run_codeql-1.0.0/tests/fixtures/empty-code-quality.sarif +14 -0
- run_codeql-1.0.0/tests/fixtures/python-code-quality.sarif +77 -0
- run_codeql-1.0.0/tests/test_cleanup_reports.py +39 -0
- run_codeql-1.0.0/tests/test_cli.py +104 -0
- run_codeql-1.0.0/tests/test_cli_filters.py +264 -0
- run_codeql-1.0.0/tests/test_detect_langs.py +79 -0
- run_codeql-1.0.0/tests/test_download_integrity.py +30 -0
- run_codeql-1.0.0/tests/test_safe_extract.py +35 -0
- run_codeql-1.0.0/tests/test_sarif_filters.py +255 -0
- run_codeql-1.0.0/tests/test_summarize_sarif.py +59 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: ["**"]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: ["**"]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
name: Lint
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.12"
|
|
18
|
+
- run: pip install black ruff
|
|
19
|
+
- run: black --check run_codeql tests
|
|
20
|
+
- run: ruff check run_codeql tests
|
|
21
|
+
|
|
22
|
+
test:
|
|
23
|
+
name: Test (Python ${{ matrix.python-version }})
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
strategy:
|
|
26
|
+
fail-fast: false
|
|
27
|
+
matrix:
|
|
28
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/checkout@v4
|
|
31
|
+
- uses: actions/setup-python@v5
|
|
32
|
+
with:
|
|
33
|
+
python-version: ${{ matrix.python-version }}
|
|
34
|
+
- run: pip install -e ".[dev]"
|
|
35
|
+
- run: pytest tests/ -v
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: write
|
|
9
|
+
id-token: write # required for PyPI trusted publishing
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
release:
|
|
13
|
+
name: Semantic Release
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
concurrency: release
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
with:
|
|
19
|
+
fetch-depth: 0
|
|
20
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
21
|
+
|
|
22
|
+
- uses: actions/setup-python@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.12"
|
|
25
|
+
|
|
26
|
+
- run: pip install python-semantic-release build twine
|
|
27
|
+
|
|
28
|
+
- name: Semantic Release
|
|
29
|
+
id: release
|
|
30
|
+
env:
|
|
31
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
32
|
+
run: semantic-release version --push
|
|
33
|
+
|
|
34
|
+
- name: Build distribution
|
|
35
|
+
if: steps.release.outputs.released == 'true'
|
|
36
|
+
run: python -m build
|
|
37
|
+
|
|
38
|
+
- name: Publish to PyPI
|
|
39
|
+
if: steps.release.outputs.released == 'true'
|
|
40
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
run_codeql-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Derek Norrbom
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
.PHONY: help test lint fmt fmt-check typecheck check fix install
|
|
2
|
+
|
|
3
|
+
PYTHON := python
|
|
4
|
+
SRC := run_codeql tests
|
|
5
|
+
|
|
6
|
+
help:
|
|
7
|
+
@echo "Usage: make <target>"
|
|
8
|
+
@echo ""
|
|
9
|
+
@echo " test Run the test suite"
|
|
10
|
+
@echo " cov Run tests with coverage report"
|
|
11
|
+
@echo " lint Run ruff (check only)"
|
|
12
|
+
@echo " fmt Auto-format with black and ruff --fix"
|
|
13
|
+
@echo " fmt-check Check formatting without modifying files"
|
|
14
|
+
@echo " fix lint + fmt combined (auto-fix everything)"
|
|
15
|
+
@echo " check fmt-check + lint (CI-safe, no modifications)"
|
|
16
|
+
@echo " install Install package in editable mode with dev deps"
|
|
17
|
+
|
|
18
|
+
test:
|
|
19
|
+
$(PYTHON) -m pytest tests/
|
|
20
|
+
|
|
21
|
+
cov:
|
|
22
|
+
$(PYTHON) -m pytest tests/ --cov=run_codeql --cov-report=term-missing
|
|
23
|
+
|
|
24
|
+
lint:
|
|
25
|
+
ruff check $(SRC)
|
|
26
|
+
|
|
27
|
+
fmt:
|
|
28
|
+
black $(SRC)
|
|
29
|
+
ruff check --fix $(SRC)
|
|
30
|
+
|
|
31
|
+
fmt-check:
|
|
32
|
+
black --check $(SRC)
|
|
33
|
+
ruff check $(SRC)
|
|
34
|
+
|
|
35
|
+
fix: fmt lint
|
|
36
|
+
|
|
37
|
+
check: fmt-check lint
|
|
38
|
+
|
|
39
|
+
install:
|
|
40
|
+
pip install -e ".[dev]"
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: run-codeql
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Run CodeQL code-quality analysis locally, mirroring the GitHub 'Code Quality' check
|
|
5
|
+
Project-URL: Homepage, https://github.com/dereknorrbom/run-codeql
|
|
6
|
+
Project-URL: Repository, https://github.com/dereknorrbom/run-codeql
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/dereknorrbom/run-codeql/issues
|
|
8
|
+
Author-email: Derek Norrbom <dereknorrbom@gmail.com>
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 Derek Norrbom
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: code-quality,codeql,linting,security,static-analysis
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Environment :: Console
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: OS Independent
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Topic :: Security
|
|
42
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
43
|
+
Requires-Python: >=3.10
|
|
44
|
+
Provides-Extra: dev
|
|
45
|
+
Requires-Dist: black; extra == 'dev'
|
|
46
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
47
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
48
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
|
|
51
|
+
# run-codeql
|
|
52
|
+
|
|
53
|
+
A pip-installable CLI tool that runs [CodeQL](https://codeql.github.com/) code-quality analysis locally, mirroring the GitHub "Code Quality" check. Install once, run from any repository.
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
pip install run-codeql
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
This installs two commands: `run-codeql` and the shorthand `rcql`.
|
|
62
|
+
|
|
63
|
+
## Requirements
|
|
64
|
+
|
|
65
|
+
- Python 3.10+
|
|
66
|
+
- CodeQL CLI — auto-downloaded to `~/.codeql-tools/` on first run if not already on `PATH` (SHA-256 verified, with retry/timeout policy)
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
Run from the root of any repository:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
rcql # auto-detect languages, run full scan
|
|
74
|
+
rcql --lang python # scan only Python
|
|
75
|
+
rcql --lang python,actions # scan multiple specific languages
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Options
|
|
79
|
+
|
|
80
|
+
| Flag | Description |
|
|
81
|
+
|------|-------------|
|
|
82
|
+
| `--lang` | Comma-separated languages to scan (default: auto-detected) |
|
|
83
|
+
| `--report-only` | Skip scanning; summarize existing SARIF reports from the last run |
|
|
84
|
+
| `--verbose`, `-v` | Print each finding with rule ID, location, and message |
|
|
85
|
+
| `--quiet`, `-q` | Suppress log output; print only final summaries (for agent/scripted use) |
|
|
86
|
+
| `--files` | Comma-separated file paths or fnmatch patterns to restrict findings to (e.g. `src/foo.py` or `src/*.py`) |
|
|
87
|
+
| `--rule` | Comma-separated rule IDs or fnmatch patterns to restrict findings to (e.g. `py/unused-import` or `py/*`) |
|
|
88
|
+
| `--limit N` | Return at most N findings (after `--files`/`--rule` filtering) |
|
|
89
|
+
| `--offset N` | Skip the first N findings before applying `--limit` (for pagination) |
|
|
90
|
+
| `--keep-db` | Reuse existing databases instead of recreating them |
|
|
91
|
+
| `--keep-reports` | Do not delete prior SARIF reports before running |
|
|
92
|
+
| `--no-fail` | Exit 0 even if findings or scan errors exist |
|
|
93
|
+
|
|
94
|
+
Download behavior can be tuned with environment variables:
|
|
95
|
+
`RCQL_DOWNLOAD_TIMEOUT_SECONDS`, `RCQL_DOWNLOAD_RETRY_ATTEMPTS`, and `RCQL_DOWNLOAD_RETRY_SLEEP_SECONDS`.
|
|
96
|
+
|
|
97
|
+
Report cleanup behavior before scans:
|
|
98
|
+
- with `--lang`, only the matching `<lang>-code-quality.sarif` reports are replaced
|
|
99
|
+
- without `--lang`, all prior SARIF reports are cleared first
|
|
100
|
+
- with `--keep-reports`, no reports are deleted
|
|
101
|
+
|
|
102
|
+
### Language auto-detection
|
|
103
|
+
|
|
104
|
+
When `--lang` is not specified, the tool scans the repo for source files and detects which CodeQL languages to run. Common dependency directories are skipped (`node_modules`, `vendor`, `target`, `.venv`, etc.).
|
|
105
|
+
|
|
106
|
+
Supported languages: `python`, `rust`, `javascript-typescript`, `go`, `java`, `csharp`, `cpp`, `ruby`, `swift`, `actions`
|
|
107
|
+
|
|
108
|
+
GitHub Actions workflows (`.github/workflows/*.yml` and `.github/workflows/*.yaml`) are detected automatically and trigger the `actions` scanner.
|
|
109
|
+
|
|
110
|
+
### Outputs
|
|
111
|
+
|
|
112
|
+
- Databases: `.codeql/db-<lang>/`
|
|
113
|
+
- SARIF reports: `.codeql/reports/<lang>-code-quality.sarif`
|
|
114
|
+
|
|
115
|
+
A `.codeql/.gitignore` with `*` is created automatically on first run so these artifacts are not committed.
|
|
116
|
+
|
|
117
|
+
By default, `rcql` exits non-zero if any findings are present or any language scan fails. Use `--no-fail` to force a zero exit code for informational/reporting workflows.
|
|
118
|
+
|
|
119
|
+
## Common workflows
|
|
120
|
+
|
|
121
|
+
### Full scan
|
|
122
|
+
|
|
123
|
+
```sh
|
|
124
|
+
cd ~/projects/my-repo
|
|
125
|
+
rcql
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Quick re-summary after a previous scan
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
rcql --report-only
|
|
132
|
+
rcql --report-only --verbose
|
|
133
|
+
rcql --report-only --lang rust
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Agent-friendly output
|
|
137
|
+
|
|
138
|
+
Produces clean, structured output suitable for an AI agent — no log noise, findings include rule ID, file location, and message:
|
|
139
|
+
|
|
140
|
+
```sh
|
|
141
|
+
rcql -q -v --report-only
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Example output:
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
[python] SARIF: /path/to/.codeql/reports/python-code-quality.sarif
|
|
148
|
+
error: 1
|
|
149
|
+
warning: 2
|
|
150
|
+
Total: 3
|
|
151
|
+
|
|
152
|
+
[error] py/sql-injection
|
|
153
|
+
SQL injection
|
|
154
|
+
src/db.py:42
|
|
155
|
+
This query depends on user-provided value.
|
|
156
|
+
|
|
157
|
+
[warning] py/unused-import
|
|
158
|
+
Unused import
|
|
159
|
+
src/utils.py:3
|
|
160
|
+
Import of 'os' is not used.
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Filtering findings for large codebases
|
|
164
|
+
|
|
165
|
+
When a scan returns hundreds or thousands of findings, use `--files`, `--rule`, `--limit`, and `--offset` to slice the results. These flags work with both `--report-only` and live scans.
|
|
166
|
+
|
|
167
|
+
**Filter to a specific file:**
|
|
168
|
+
|
|
169
|
+
```sh
|
|
170
|
+
rcql -q -v --report-only --files src/models/user.py
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Filter using a glob pattern:**
|
|
174
|
+
|
|
175
|
+
```sh
|
|
176
|
+
rcql -q -v --report-only --files 'src/api/*.py'
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Filter to a specific rule:**
|
|
180
|
+
|
|
181
|
+
```sh
|
|
182
|
+
rcql -q -v --report-only --rule py/unused-import
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**Filter to an entire rule category:**
|
|
186
|
+
|
|
187
|
+
```sh
|
|
188
|
+
rcql -q -v --report-only --rule 'py/*'
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Combine file and rule filters:**
|
|
192
|
+
|
|
193
|
+
```sh
|
|
194
|
+
rcql -q -v --report-only --files src/models/user.py --rule py/unused-import
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Paginate through a large result set:**
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
# First 20 findings
|
|
201
|
+
rcql -q -v --report-only --limit 20
|
|
202
|
+
|
|
203
|
+
# Next 20
|
|
204
|
+
rcql -q -v --report-only --limit 20 --offset 20
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
When any filter or pagination flag is active, the summary line changes from `Total: N` to `Shown: X (matched: Y)` so you can see both how many were returned and how many matched in total.
|
|
208
|
+
|
|
209
|
+
Language blocks with zero matching findings are automatically suppressed when `--files` or `--rule` is active, so only relevant output is shown.
|
|
210
|
+
|
|
211
|
+
### Single-language scan
|
|
212
|
+
|
|
213
|
+
```sh
|
|
214
|
+
rcql --lang actions --no-fail
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Parallel execution
|
|
218
|
+
|
|
219
|
+
When scanning multiple languages, all scans run in parallel with CPU threads divided evenly across languages. Log timestamps make this visible.
|
|
220
|
+
|
|
221
|
+
## Upgrading CodeQL
|
|
222
|
+
|
|
223
|
+
The CodeQL version is pinned in the package. The checksum for each release is fetched live from GitHub at download time, so no manual SHA updates are needed. To use a newer CodeQL version, update `CODEQL_VERSION` in `run_codeql/settings.py` and delete `~/.codeql-tools/` to trigger a fresh download on next run.
|
|
224
|
+
|
|
225
|
+
## Development
|
|
226
|
+
|
|
227
|
+
```sh
|
|
228
|
+
git clone https://github.com/YOUR_USERNAME/run-codeql
|
|
229
|
+
cd run-codeql
|
|
230
|
+
pip install -e ".[dev]"
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Make targets
|
|
234
|
+
|
|
235
|
+
| Target | Description |
|
|
236
|
+
|--------|-------------|
|
|
237
|
+
| `make test` | Run the test suite |
|
|
238
|
+
| `make cov` | Run tests with coverage report |
|
|
239
|
+
| `make lint` | Run ruff (check only) |
|
|
240
|
+
| `make fmt` | Auto-format with black and ruff --fix |
|
|
241
|
+
| `make fmt-check` | Check formatting without modifying files |
|
|
242
|
+
| `make check` | fmt-check + lint (CI-safe, no modifications) |
|
|
243
|
+
| `make fix` | lint + fmt combined (auto-fix everything) |
|
|
244
|
+
| `make install` | Install in editable mode with dev deps |
|
|
245
|
+
|
|
246
|
+
### Running tests
|
|
247
|
+
|
|
248
|
+
```sh
|
|
249
|
+
make test # run all 100+ tests
|
|
250
|
+
make cov # with per-line coverage report
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Tests cover SARIF filtering, language detection, download integrity, extraction safety, and CLI behavior using fixture SARIF files. No CodeQL installation is required to run the tests.
|
|
254
|
+
|
|
255
|
+
### Package layout
|
|
256
|
+
|
|
257
|
+
| File | Purpose |
|
|
258
|
+
|------|---------|
|
|
259
|
+
| `run_codeql/cli.py` | Argument parsing and orchestration |
|
|
260
|
+
| `run_codeql/download.py` | CodeQL download, retry, checksum, extraction |
|
|
261
|
+
| `run_codeql/scanner.py` | Language detection and per-language scan execution |
|
|
262
|
+
| `run_codeql/sarif.py` | SARIF parsing, filtering, and summary rendering |
|
|
263
|
+
| `run_codeql/settings.py` | Constants and environment-tunable defaults |
|
|
264
|
+
|
|
265
|
+
## Contributing
|
|
266
|
+
|
|
267
|
+
Contributions are welcome. Please:
|
|
268
|
+
|
|
269
|
+
1. Fork the repo and create a feature branch
|
|
270
|
+
2. Run `make check` and `make test` before submitting
|
|
271
|
+
3. Open a pull request with a clear description of the change
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# run-codeql
|
|
2
|
+
|
|
3
|
+
A pip-installable CLI tool that runs [CodeQL](https://codeql.github.com/) code-quality analysis locally, mirroring the GitHub "Code Quality" check. Install once, run from any repository.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pip install run-codeql
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This installs two commands: `run-codeql` and the shorthand `rcql`.
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- Python 3.10+
|
|
16
|
+
- CodeQL CLI — auto-downloaded to `~/.codeql-tools/` on first run if not already on `PATH` (SHA-256 verified, with retry/timeout policy)
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
Run from the root of any repository:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
rcql # auto-detect languages, run full scan
|
|
24
|
+
rcql --lang python # scan only Python
|
|
25
|
+
rcql --lang python,actions # scan multiple specific languages
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Options
|
|
29
|
+
|
|
30
|
+
| Flag | Description |
|
|
31
|
+
|------|-------------|
|
|
32
|
+
| `--lang` | Comma-separated languages to scan (default: auto-detected) |
|
|
33
|
+
| `--report-only` | Skip scanning; summarize existing SARIF reports from the last run |
|
|
34
|
+
| `--verbose`, `-v` | Print each finding with rule ID, location, and message |
|
|
35
|
+
| `--quiet`, `-q` | Suppress log output; print only final summaries (for agent/scripted use) |
|
|
36
|
+
| `--files` | Comma-separated file paths or fnmatch patterns to restrict findings to (e.g. `src/foo.py` or `src/*.py`) |
|
|
37
|
+
| `--rule` | Comma-separated rule IDs or fnmatch patterns to restrict findings to (e.g. `py/unused-import` or `py/*`) |
|
|
38
|
+
| `--limit N` | Return at most N findings (after `--files`/`--rule` filtering) |
|
|
39
|
+
| `--offset N` | Skip the first N findings before applying `--limit` (for pagination) |
|
|
40
|
+
| `--keep-db` | Reuse existing databases instead of recreating them |
|
|
41
|
+
| `--keep-reports` | Do not delete prior SARIF reports before running |
|
|
42
|
+
| `--no-fail` | Exit 0 even if findings or scan errors exist |
|
|
43
|
+
|
|
44
|
+
Download behavior can be tuned with environment variables:
|
|
45
|
+
`RCQL_DOWNLOAD_TIMEOUT_SECONDS`, `RCQL_DOWNLOAD_RETRY_ATTEMPTS`, and `RCQL_DOWNLOAD_RETRY_SLEEP_SECONDS`.
|
|
46
|
+
|
|
47
|
+
Report cleanup behavior before scans:
|
|
48
|
+
- with `--lang`, only the matching `<lang>-code-quality.sarif` reports are replaced
|
|
49
|
+
- without `--lang`, all prior SARIF reports are cleared first
|
|
50
|
+
- with `--keep-reports`, no reports are deleted
|
|
51
|
+
|
|
52
|
+
### Language auto-detection
|
|
53
|
+
|
|
54
|
+
When `--lang` is not specified, the tool scans the repo for source files and detects which CodeQL languages to run. Common dependency directories are skipped (`node_modules`, `vendor`, `target`, `.venv`, etc.).
|
|
55
|
+
|
|
56
|
+
Supported languages: `python`, `rust`, `javascript-typescript`, `go`, `java`, `csharp`, `cpp`, `ruby`, `swift`, `actions`
|
|
57
|
+
|
|
58
|
+
GitHub Actions workflows (`.github/workflows/*.yml` and `.github/workflows/*.yaml`) are detected automatically and trigger the `actions` scanner.
|
|
59
|
+
|
|
60
|
+
### Outputs
|
|
61
|
+
|
|
62
|
+
- Databases: `.codeql/db-<lang>/`
|
|
63
|
+
- SARIF reports: `.codeql/reports/<lang>-code-quality.sarif`
|
|
64
|
+
|
|
65
|
+
A `.codeql/.gitignore` with `*` is created automatically on first run so these artifacts are not committed.
|
|
66
|
+
|
|
67
|
+
By default, `rcql` exits non-zero if any findings are present or any language scan fails. Use `--no-fail` to force a zero exit code for informational/reporting workflows.
|
|
68
|
+
|
|
69
|
+
## Common workflows
|
|
70
|
+
|
|
71
|
+
### Full scan
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
cd ~/projects/my-repo
|
|
75
|
+
rcql
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Quick re-summary after a previous scan
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
rcql --report-only
|
|
82
|
+
rcql --report-only --verbose
|
|
83
|
+
rcql --report-only --lang rust
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Agent-friendly output
|
|
87
|
+
|
|
88
|
+
Produces clean, structured output suitable for an AI agent — no log noise, findings include rule ID, file location, and message:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
rcql -q -v --report-only
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Example output:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
[python] SARIF: /path/to/.codeql/reports/python-code-quality.sarif
|
|
98
|
+
error: 1
|
|
99
|
+
warning: 2
|
|
100
|
+
Total: 3
|
|
101
|
+
|
|
102
|
+
[error] py/sql-injection
|
|
103
|
+
SQL injection
|
|
104
|
+
src/db.py:42
|
|
105
|
+
This query depends on user-provided value.
|
|
106
|
+
|
|
107
|
+
[warning] py/unused-import
|
|
108
|
+
Unused import
|
|
109
|
+
src/utils.py:3
|
|
110
|
+
Import of 'os' is not used.
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Filtering findings for large codebases
|
|
114
|
+
|
|
115
|
+
When a scan returns hundreds or thousands of findings, use `--files`, `--rule`, `--limit`, and `--offset` to slice the results. These flags work with both `--report-only` and live scans.
|
|
116
|
+
|
|
117
|
+
**Filter to a specific file:**
|
|
118
|
+
|
|
119
|
+
```sh
|
|
120
|
+
rcql -q -v --report-only --files src/models/user.py
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Filter using a glob pattern:**
|
|
124
|
+
|
|
125
|
+
```sh
|
|
126
|
+
rcql -q -v --report-only --files 'src/api/*.py'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Filter to a specific rule:**
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
rcql -q -v --report-only --rule py/unused-import
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Filter to an entire rule category:**
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
rcql -q -v --report-only --rule 'py/*'
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Combine file and rule filters:**
|
|
142
|
+
|
|
143
|
+
```sh
|
|
144
|
+
rcql -q -v --report-only --files src/models/user.py --rule py/unused-import
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Paginate through a large result set:**
|
|
148
|
+
|
|
149
|
+
```sh
|
|
150
|
+
# First 20 findings
|
|
151
|
+
rcql -q -v --report-only --limit 20
|
|
152
|
+
|
|
153
|
+
# Next 20
|
|
154
|
+
rcql -q -v --report-only --limit 20 --offset 20
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
When any filter or pagination flag is active, the summary line changes from `Total: N` to `Shown: X (matched: Y)` so you can see both how many were returned and how many matched in total.
|
|
158
|
+
|
|
159
|
+
Language blocks with zero matching findings are automatically suppressed when `--files` or `--rule` is active, so only relevant output is shown.
|
|
160
|
+
|
|
161
|
+
### Single-language scan
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
rcql --lang actions --no-fail
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Parallel execution
|
|
168
|
+
|
|
169
|
+
When scanning multiple languages, all scans run in parallel with CPU threads divided evenly across languages. Log timestamps make this visible.
|
|
170
|
+
|
|
171
|
+
## Upgrading CodeQL
|
|
172
|
+
|
|
173
|
+
The CodeQL version is pinned in the package. The checksum for each release is fetched live from GitHub at download time, so no manual SHA updates are needed. To use a newer CodeQL version, update `CODEQL_VERSION` in `run_codeql/settings.py` and delete `~/.codeql-tools/` to trigger a fresh download on next run.
|
|
174
|
+
|
|
175
|
+
## Development
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
git clone https://github.com/YOUR_USERNAME/run-codeql
|
|
179
|
+
cd run-codeql
|
|
180
|
+
pip install -e ".[dev]"
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Make targets
|
|
184
|
+
|
|
185
|
+
| Target | Description |
|
|
186
|
+
|--------|-------------|
|
|
187
|
+
| `make test` | Run the test suite |
|
|
188
|
+
| `make cov` | Run tests with coverage report |
|
|
189
|
+
| `make lint` | Run ruff (check only) |
|
|
190
|
+
| `make fmt` | Auto-format with black and ruff --fix |
|
|
191
|
+
| `make fmt-check` | Check formatting without modifying files |
|
|
192
|
+
| `make check` | fmt-check + lint (CI-safe, no modifications) |
|
|
193
|
+
| `make fix` | lint + fmt combined (auto-fix everything) |
|
|
194
|
+
| `make install` | Install in editable mode with dev deps |
|
|
195
|
+
|
|
196
|
+
### Running tests
|
|
197
|
+
|
|
198
|
+
```sh
|
|
199
|
+
make test # run all 100+ tests
|
|
200
|
+
make cov # with per-line coverage report
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Tests cover SARIF filtering, language detection, download integrity, extraction safety, and CLI behavior using fixture SARIF files. No CodeQL installation is required to run the tests.
|
|
204
|
+
|
|
205
|
+
### Package layout
|
|
206
|
+
|
|
207
|
+
| File | Purpose |
|
|
208
|
+
|------|---------|
|
|
209
|
+
| `run_codeql/cli.py` | Argument parsing and orchestration |
|
|
210
|
+
| `run_codeql/download.py` | CodeQL download, retry, checksum, extraction |
|
|
211
|
+
| `run_codeql/scanner.py` | Language detection and per-language scan execution |
|
|
212
|
+
| `run_codeql/sarif.py` | SARIF parsing, filtering, and summary rendering |
|
|
213
|
+
| `run_codeql/settings.py` | Constants and environment-tunable defaults |
|
|
214
|
+
|
|
215
|
+
## Contributing
|
|
216
|
+
|
|
217
|
+
Contributions are welcome. Please:
|
|
218
|
+
|
|
219
|
+
1. Fork the repo and create a feature branch
|
|
220
|
+
2. Run `make check` and `make test` before submitting
|
|
221
|
+
3. Open a pull request with a clear description of the change
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
MIT
|