Sub topic 3
Choosing default setup or advanced setup
This chapter assumes you know basic Git and GitHub usage, can read YAML, and understand GitHub Actions workflows, jobs, steps and triggers. It also assumes you have read the previous chapters on what code scanning is and how CodeQL builds a database and runs queries.
Two ways to turn on CodeQL
GitHub offers two ways to run CodeQL code scanning on a repository.
- Default setup is configured from the repository settings. GitHub picks the languages, query suite and triggers for you. There is no workflow file to maintain.
- Advanced setup is a workflow file that you commit, usually
.github/workflows/codeql.yml. You control every step.
Both run the same CodeQL engine and produce the same kind of alerts. The difference is how much of the configuration you own.
What default setup does
You enable default setup under Settings, then Advanced Security (or Code security, depending on your plan), then Code scanning. GitHub detects the supported languages in the repository and proposes a configuration. You can adjust the language list and the query suite, and then enable it.
Default setup then does the following:
- Scans on pushes to the default branch and on pull requests that target it.
- Runs a scheduled scan.
- Uses a build mode that fits each language, so compiled languages often need no build commands from you.
- Updates itself when languages are added to or removed from the repository.
GitHub runs it as a managed workflow. It appears in the Actions tab, but you cannot edit it.
What advanced setup gives you
With advanced setup, you write the workflow yourself. The example below is a complete workflow that scans two languages on pushes and pull requests to main, and on a weekly schedule.
name: CodeQL
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '17 3 * * 1'
jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
actions: read
strategy:
fail-fast: false
matrix:
include:
- language: javascript-typescript
build-mode: none
- language: python
build-mode: none
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
- name: Perform CodeQL analysis
uses: github/codeql-action/analyze@v4
with:
category: "/language:${{ matrix.language }}"Because the file lives in your repository, you can:
- Change the triggers, for example to scan release branches.
- Set a manual build mode and run your own build commands.
- Add a configuration file, custom queries or query packs.
- Run on self-hosted runners or in a specific environment.
- Upload SARIF files from other tools in the same workflow.
The cost is maintenance. You update action versions, fix the YAML when something breaks, and add new languages by hand.
Comparing the two
| Concern | Default setup | Advanced setup |
|---|---|---|
| Configuration location | Repository settings | Workflow file in the repository |
| Effort to start | A few clicks | Write and review YAML |
| Language detection | Automatic | You list each language |
| Custom queries and config file | Not supported | Supported |
| Custom build commands | Not supported | Supported |
| Triggers | Fixed by GitHub | Any trigger you define |
| Upkeep | GitHub maintains it | You maintain it |
A decision process
Start with default setup unless you have a reason not to. Move to advanced setup when you need something default setup cannot provide.
Common errors and gotchas
- Two setups at once. If you enable default setup while a CodeQL workflow file already exists, the results can conflict or duplicate. Disable one before enabling the other. GitHub may warn you about this when you enable default setup.
- Switching to advanced setup. To adopt advanced setup, first disable default setup in the repository settings, then commit your workflow file. Otherwise both will run.
- Missing permissions. An advanced workflow without
security-events: writefails when it tries to upload results. - Forgotten maintenance. A workflow that pins an old action version may stop working or miss new features. Review it periodically.
- Pull requests from forks. The token for these runs is restricted, so uploading results can fail or be skipped. Check how your workflow behaves for fork pull requests.
Exercise
A team's repository uses a compiled language with an unusual build process, and they want to add their own custom queries. Which setup should they choose, and what must they do before adding their workflow file if default setup is already on?
Show answer
They should choose advanced setup, because it supports custom build commands and custom queries. Before committing the workflow file, they should disable default setup in the repository settings so that the two do not both run and produce duplicate or conflicting results.