Skip to content

Commit 2753209

Browse files
authored
feat: add option to provide root for the analyze_code command (#63)
The `analyze_code` command now supports providing the root of the scan through the `root_dir` parameter. This enables partial scans of the codebase in the full mode. Corresponding `analyze_code_full` jobs also enables the same functionality.
1 parent 0c6569b commit 2753209

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

.circleci/test-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ workflows:
188188
filters: *filters
189189
- security/analyze_code_full:
190190
name: analyze_code_full
191+
root_dir: ./sample
191192
rules: p/cwe-top-25
192193
filters: *filters
193194
- scan_dependencies_prod_npm:

src/commands/analyze_code.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ description: >
33
command to do the analysis. For details on usage see https://semgrep.dev/docs/cli-reference.
44
55
parameters:
6+
root_dir:
7+
type: string
8+
default: "."
9+
description: >
10+
The root of the codebase to analyze. Defaults to . (working directory).
11+
Complements the full scan mode, by enabling partial scan of the codebase.
612
full_scan:
713
type: boolean
814
default: false
@@ -21,7 +27,7 @@ parameters:
2127
file, or Semgrep registry entry name.
2228
base_branch:
2329
type: string
24-
default: ''
30+
default: ""
2531
description: >
2632
The name of the base branch for this scan. Commonly a long-lived branch, e.g. "main" or "master".
2733
@@ -36,6 +42,7 @@ steps:
3642
command: <<include(scripts/export-git-branches.sh)>>
3743
- run:
3844
name: Analyze code <<#parameters.full_scan>>full<</parameters.full_scan>><<^parameters.full_scan>>diff<</parameters.full_scan>>
45+
working_directory: <<parameters.root_dir>>
3946
environment:
4047
PARAM_BOOL_FULL_SCAN: <<parameters.full_scan>>
4148
PARAM_BOOL_VERBOSE: <<parameters.verbose>>

src/jobs/analyze_code_full.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ description: >
44
executor: node
55

66
parameters:
7+
root_dir:
8+
type: string
9+
default: "."
10+
description: >
11+
The root of the codebase to analyze. Defaults to . (working directory).
712
verbose:
813
type: boolean
914
default: false
@@ -19,5 +24,6 @@ steps:
1924
- checkout
2025
- analyze_code:
2126
full_scan: true
27+
root_dir: <<parameters.root_dir>>
2228
verbose: <<parameters.verbose>>
2329
rules: <<parameters.rules>>

src/scripts/analyze-code.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
echo "Starting codebase analysis at root directory: ${PWD}"
4+
35
# The `experimental` flag is needed for Semgrep to work, otherwise
46
# for unknown reason it will fail with exit code 2. This behavior
57
# is only observed in CI environment.

0 commit comments

Comments
 (0)