Skip to content

Commit c13b396

Browse files
authored
chore: upgrade Semgrep to latest (#11)
Needed by #10, latest version fixes a bug with the `--validate` command (which causes the CI to fail). Version is also ancient thus needs upgrading
1 parent 649e7b8 commit c13b396

File tree

3 files changed

+54
-27
lines changed

3 files changed

+54
-27
lines changed

.github/workflows/action-run-semgrep.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ on:
3636
- p/python (public library)
3737
- ./rules/my-rule.yaml (single YAML file)
3838
- ./my-rules/ (directory of N YAML files)
39-
39+
4040
By default the rules will be added on top of this workflow's default rules
4141
(see the input `use_default_config` and the environment variable
4242
`DEFAULT_CONFIG` for more information).
@@ -80,10 +80,10 @@ jobs:
8080
scan:
8181
if: (github.actor != 'dependabot[bot]')
8282
name: semgrep/ci
83-
runs-on: ubuntu-22.04
83+
runs-on: ubuntu-24.04
8484
container:
8585
# Note: the non-root flavor doesn't work on GHA (e.g., 1.57.0-nonroot).
86-
image: returntocorp/semgrep@sha256:396f4ad7a655289e764ab2f92733e6195c166ff2f042e0d40505a5850432b9ac # 1.63.0
86+
image: returntocorp/semgrep:1.153.1@sha256:50b839b576d76426efd3e5cffda2db0d8c403f53aa76e91d42ccf51485ac336c
8787

8888
steps:
8989
# Clone the invoker's repository.
@@ -119,7 +119,7 @@ jobs:
119119
EXCLUDE_RULES: ${{ inputs.exclude_rules }}
120120
run: |
121121
set -u -o pipefail
122-
122+
123123
cmd_args=(
124124
# Do not check for version update as we are inside a CI.
125125
"--disable-version-check"
@@ -131,32 +131,32 @@ jobs:
131131
# the users to be explicit.
132132
"--no-git-ignore"
133133
)
134-
134+
135135
# Add extra logging if the runner was run with debug logging.
136136
test -z "${RUNNER_DEBUG+x}" || cmd_args+=( "--verbose" )
137-
137+
138138
if [ "$USE_DEFAULT_CONFIG" == true ]; then
139139
CONFIG_PATHS="$DEFAULT_CONFIG $CONFIG_PATHS"
140140
fi
141-
141+
142142
if [ "$USE_DEFAULT_EXCLUDE_RULES" == true ]; then
143143
EXCLUDE_RULES="$DEFAULT_EXCLUDE_RULE_IDS $EXCLUDE_RULES"
144144
fi
145-
145+
146146
# Gather the config input whitespace-separate value
147147
# into a list of `--config=<value>` arguments.
148148
read -d '' -r -a configs < <(echo "$CONFIG_PATHS") || true
149149
for cfg in "${configs[@]}"; do
150150
cmd_args+=( "--config=$cfg" )
151151
done
152-
152+
153153
# Gather the excluded rules ID into a list
154154
# of `--exclude-rule=<value>` arguments.
155155
read -d '' -r -a exclude_rules < <(echo "$EXCLUDE_RULES") || true
156156
for excluded_rule_id in "${exclude_rules[@]}"; do
157157
cmd_args+=( "--exclude-rule=$excluded_rule_id" )
158158
done
159-
159+
160160
semgrep ci "${cmd_args[@]}"
161161
162162
- uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # 4.3.0
@@ -176,7 +176,7 @@ jobs:
176176
needs:
177177
- scan
178178
name: SARIF to PR Annotations
179-
runs-on: ubuntu-22.04
179+
runs-on: ubuntu-24.04
180180
container:
181181
# Note: distroless flavor doesn't work on GHA.
182182
image: ghcr.io/nyankiyoshi/less-advanced-security@sha256:689f73bed448ce40ca4ed01f6585f22665c0c302ed0e882d1fc78016c12f2880 # 0.5.0

.github/workflows/test-rules.yaml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
name: Test Semgrep Rules
22
on:
33
push:
4+
branches: [main]
45
pull_request:
56

7+
permissions: {}
8+
69
jobs:
710
main:
8-
runs-on: ubuntu-22.04
11+
runs-on: ubuntu-24.04
912

10-
# Note: the non-root flavor doesn't work on GHA (e.g., 1.56.0-nonroot).
11-
container: returntocorp/semgrep@sha256:396f4ad7a655289e764ab2f92733e6195c166ff2f042e0d40505a5850432b9ac # 1.63.0
13+
permissions:
14+
contents: read
1215

1316
steps:
1417
- name: Checkout
@@ -17,22 +20,12 @@ jobs:
1720
# Checks for syntax errors and runs 'p/semgrep-rule-lints'.
1821
- name: Validate Rules
1922
shell: bash
20-
run: |
21-
config_args=()
22-
23-
# As of semgrep 1.58.0, hidden directories are no longer excluded
24-
# when passing "--validate ./" thus we need to manually exclude hidden
25-
# directories.
26-
while IFS= read -r -d '' dir; do
27-
config_args+=( "--config=$dir" )
28-
done < <(find . -maxdepth 1 -mindepth 1 -type d -not -path '*/\.*' -print0)
29-
30-
semgrep scan --validate "${config_args[@]}"
23+
run: make validate
3124

3225
- name: Test Rules
33-
run: semgrep --test ./
26+
run: make test
3427

3528
# This runs the rules from https://github.com/semgrep/semgrep-rules/tree/835867f89e4ba07f8bb4a6a1619507408e63e9b0/yaml/semgrep
3629
# to ensure best practices are followed. The CI will only fail on error.
3730
- name: Run Semgrep Rules Recommendation Checks
38-
run: semgrep --config=r/yaml.semgrep --severity ERROR ./
31+
run: make checks

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
semgrep_image ?= returntocorp/semgrep:1.153.1@sha256:50b839b576d76426efd3e5cffda2db0d8c403f53aa76e91d42ccf51485ac336c
2+
semgrep_container = \
3+
docker run \
4+
--rm \
5+
-v "$(PWD)":/src:ro \
6+
-w /src \
7+
$(semgrep_image) \
8+
semgrep
9+
10+
# List of all rules in our project
11+
configs = \
12+
--config=./yaml/ \
13+
--config=./typescript/
14+
15+
all: validate test checks
16+
17+
# Check rules are valid
18+
validate:
19+
$(semgrep_container) \
20+
--validate \
21+
$(configs)
22+
23+
# Run test files
24+
test:
25+
$(semgrep_container) \
26+
--test \
27+
./
28+
29+
# Run official recommendation checks
30+
checks:
31+
$(semgrep_container) \
32+
--config=r/yaml.semgrep \
33+
--severity=ERROR \
34+
./

0 commit comments

Comments
 (0)