Loading...
Loading...
Comprehensive guide for setting up and configuring CodeQL code scanning via GitHub Actions workflows and the CodeQL CLI. This skill should be used when users need help with code scanning configuration, CodeQL workflow files, CodeQL CLI commands, SARIF output, security analysis setup, or troubleshooting CodeQL analysis.
npx skill4agent add github/awesome-copilot codeqlcodeql.ymlcodeql database createdatabase analyzegithub upload-results| Language | Identifier | Alternatives |
|---|---|---|
| C/C++ | | |
| C# | | — |
| Go | | — |
| Java/Kotlin | | |
| JavaScript/TypeScript | | |
| Python | | — |
| Ruby | | — |
| Rust | | — |
| Swift | | — |
| GitHub Actions | | — |
Alternative identifiers are equivalent to the standard identifier (e.g.,does not exclude TypeScript analysis).javascript
none.github/workflows/codeql.ymlon:
push:
branches: [main, protected]
pull_request:
branches: [main]
schedule:
- cron: '30 6 * * 1' # Weekly Monday 6:30 UTCpushpull_requestschedulemerge_groupon:
pull_request:
paths-ignore:
- '**/*.md'
- '**/*.txt'controls whether the workflow runs, not which files are analyzed.paths-ignore
permissions:
security-events: write # Required to upload SARIF results
contents: read # Required to checkout code
actions: read # Required for private repos using codeql-actionjobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- language: javascript-typescript
build-mode: none
- language: python
build-mode: nonebuild-modenoneautobuildmanualFor detailed per-language autobuild behavior and runner requirements, search.references/compiled-languages.md
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
queries: security-extended
dependency-caching: true
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
with:
category: "/language:${{ matrix.language }}"security-extendedsecurity-and-qualitypacks:codeql/javascript-queries:AlertSuppression.qldependency-caching: trueinitcategorycategorycategory: "/language:${{ matrix.language }}/component:frontend".github/codeql/codeql-config.ymlpaths:
- apps/
- services/
paths-ignore:
- node_modules/
- '**/test/**'- uses: github/codeql-action/init@v4
with:
config-file: .github/codeql/codeql-config.ymlautobuild- language: c-cpp
build-mode: manualinitanalyze- if: matrix.build-mode == 'manual'
name: Build
run: |
make bootstrap
make release# Download from https://github.com/github/codeql-action/releases
# Extract and add to PATH
export PATH="$HOME/codeql:$PATH"
# Verify installation
codeql resolve packs
codeql resolve languagesAlways use the CodeQL bundle, not a standalone CLI download. The bundle ensures query compatibility and provides precompiled queries for better performance.
# Single language
codeql database create codeql-db \
--language=javascript-typescript \
--source-root=src
# Multiple languages (cluster mode)
codeql database create codeql-dbs \
--db-cluster \
--language=java,python \
--command=./build.sh \
--source-root=src--commandcodeql database analyze codeql-db \
javascript-code-scanning.qls \
--format=sarif-latest \
--sarif-category=javascript \
--output=results.sarif<language>-code-scanning.qls<language>-security-extended.qls<language>-security-and-quality.qlscodeql github upload-results \
--repository=owner/repo \
--ref=refs/heads/main \
--commit=<commit-sha> \
--sarif=results.sarifGITHUB_TOKENsecurity-events: writecodeql execute cli-serverFor detailed CLI command reference, search.references/cli-commands.md
ErrorWarningNoteCriticalHighMediumLowerrorcriticalhighFor detailed alert management guidance, search.references/alert-management.md
- uses: github/codeql-action/init@v4
with:
packs: |
my-org/my-security-queries@1.0.0
codeql/javascript-queries:AlertSuppression.ql# Initialize a new pack
codeql pack init my-org/my-queries
# Install dependencies
codeql pack install
# Publish to GitHub Container Registry
codeql pack publish.github/codeql/codeql-config.ymlpaths:
- apps/
- services/
paths-ignore:
- '**/test/**'
- node_modules/
queries:
- uses: security-extended
packs:
javascript-typescript:
- my-org/my-custom-queries--verbosity=progress++--logdir=codeql-logs| Problem | Solution |
|---|---|
| Workflow not triggering | Verify |
| Add |
| Autobuild failure | Switch to |
| No source code seen | Verify |
| C# compiler failure | Check for |
| Fewer lines scanned than expected | Switch from |
| Kotlin in no-build mode | Disable and re-enable default setup to switch to |
| Cache miss every run | Verify |
| Out of disk/memory | Use larger runners; reduce analysis scope via |
| SARIF upload fails | Ensure token has |
| SARIF results exceed limits | Split across multiple uploads with different |
| Two CodeQL workflows | Disable default setup if using advanced setup, or remove old workflow file |
| Slow analysis | Enable dependency caching; use |
For comprehensive troubleshooting with detailed solutions, search.references/troubleshooting.md
| Codebase Size | RAM | CPU |
|---|---|---|
| Small (<100K LOC) | 8 GB+ | 2 cores |
| Medium (100K–1M LOC) | 16 GB+ | 4–8 cores |
| Large (>1M LOC) | 64 GB+ | 8 cores |
uses: github/codeql-action/init@v4 # Recommended
uses: github/codeql-action/autobuild@v4
uses: github/codeql-action/analyze@v4references/workflow-configuration.mdtriggerschedulepaths-ignoredb-locationmodel packsalert severitymerge protectionconcurrencyconfig filereferences/cli-commands.mddatabase createdatabase analyzeupload-resultsresolve packscli-serverinstallationCI integrationreferences/sarif-output.mdsarifLogresultlocationregioncodeFlowfingerprintsuppressionupload limitsthird-partyprecisionsecurity-severityreferences/compiled-languages.mdC/C++C#JavaGoRustSwiftautobuildbuild-modehardwaredependency cachingreferences/troubleshooting.mdno source codeout of diskout of memory403C# compileranalysis too longfewer linesKotlinextraction errorsdebug loggingSARIF uploadSARIF limitsreferences/alert-management.mdseveritysecurity severityCVSSCopilot AutofixdismisstriagePR alertsdata flowmerge protectionREST API