-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgl-codequality.yml
More file actions
52 lines (44 loc) · 2.5 KB
/
Copy pathgl-codequality.yml
File metadata and controls
52 lines (44 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# This job runs the CodeQL static analysis engine and integrates its findings
# into the GitLab Code Quality report.
codeql_scan:
stage: test # Often runs in the 'test' or a dedicated 'code_quality' stage
image: ubuntu:20.04 # A base image to run the commands
variables:
# Define the language to be scanned. CodeQL supports many languages.
CODEQL_LANGUAGE: "php"
# Pin the version of the CodeQL CLI for consistent runs
CODEQL_VERSION: "8.3.0"
before_script:
# This section sets up the environment by downloading the CodeQL CLI
- apt-get update && apt-get install -y wget unzip
- wget "https://github.com/github/codeql-cli-binaries/releases/download/v${CODEQL_VERSION}/codeql-linux64.zip"
- unzip codeql-linux64.zip
- mv codeql codeql-cli
script:
# Step 1: Create a CodeQL database from the source code.
# This command analyzes your code and builds a structured representation of it.
- echo "Creating CodeQL database..."
- ./codeql-cli/codeql database create codeql-db --language=$CODEQL_LANGUAGE --source-root=.
# Step 2: Run the analysis by executing queries against the database.
# The output is a SARIF file, which is an industry standard for static analysis results.
- echo "Analyzing database..."
- ./codeql-cli/codeql database analyze codeql-db --format=sarif-latest --output=codeql-results.sarif "github/codeql/${CODEQL_LANGUAGE}-queries"
# Step 3: Convert the SARIF output to the GitLab Code Quality format.
# This is a crucial step. It requires a converter tool (this might be a custom script
# or a dedicated open-source tool). Let's assume a tool named 'sarif-to-gitlab'.
- echo "Converting SARIF to GitLab format..."
# The actual command might differ, but this is the concept.
# You would need to ensure this converter tool is available in your image or download it.
- ./sarif-to-gitlab -i codeql-results.sarif -o gl-code-quality-report.json
artifacts:
# This tells GitLab to save the generated report. The 'reports:code_quality' keyword
# is what enables the integration with the Merge Request widget.
reports:
code_quality: gl-code-quality-report.json
# Optionally, save the original SARIF file for deeper inspection later.
paths:
- codeql-results.sarif
when: always # Collect artifacts even if the job fails (e.g., if vulnerabilities are found)
rules:
# Run this job only on merge requests to provide feedback before merging.
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'