Skip to content

Commit bca7793

Browse files
Merge pull request #162 from skyflowapi/Revanthathreya-patch-4
SC-5146:Update semgrep.yml
2 parents 4426bc4 + 7a5a262 commit bca7793

File tree

1 file changed

+46
-17
lines changed

1 file changed

+46
-17
lines changed

.github/workflows/semgrep.yml

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,64 @@
1-
name: Semgrep
1+
name: Semgrep Scan
22

3-
# Run workflow each time code is pushed to your repository.
43
on:
5-
push:
6-
branches:
7-
- main
84
pull_request:
95
branches:
106
- main
7+
118
jobs:
129
build:
1310
runs-on: ubuntu-latest
11+
permissions:
12+
pull-requests: write # Give write permission to PRs
13+
issues: write
1414
steps:
1515
- name: Checkout code
1616
uses: actions/checkout@v3
1717

18-
- name: Install Semgrep
19-
run: pip install semgrep
18+
- name: Install Semgrep and jq
19+
run: |
20+
sudo apt install python3-venv jq
21+
python3 -m venv .venv
22+
.venv/bin/pip install semgrep
2023
2124
- name: Run Semgrep
2225
run: |
23-
semgrep --config .semgreprules/customRule.yml --config auto --severity ERROR --sarif . > results.sarif
26+
source .venv/bin/activate
27+
semgrep --config auto --severity ERROR --json-output=results.json --no-error
28+
cat results.json | jq .results > pretty-results.json
2429
25-
- name: Upload SARIF file
26-
uses: github/codeql-action/upload-sarif@v3
30+
- name: Display Raw Semgrep JSON Output
31+
run: |
32+
echo "Displaying raw Semgrep results..."
33+
cat pretty-results.json
34+
35+
- name: Add comment on PR if findings are found
36+
uses: actions/github-script@v6
2737
with:
28-
# Path to SARIF file relative to the root of the repository
29-
sarif_file: results.sarif
38+
script: |
39+
// Ensure the context has a pull_request
40+
if (context.payload.pull_request) {
41+
const prNumber = context.payload.pull_request.number;
42+
const fs = require('fs');
43+
const results = JSON.parse(fs.readFileSync('pretty-results.json', 'utf8'));
44+
const highFindings = results.filter(result => result.extra && result.extra.severity === 'ERROR');
3045
31-
- name: Upload results
32-
uses: actions/upload-artifact@v4
33-
with:
34-
name: semgrep-results
35-
path: results.sarif
46+
// Comment if findings exist
47+
if (highFindings.length > 0) {
48+
const comment = `**Semgrep Findings:** Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging.`;
49+
await github.rest.issues.createComment({
50+
...context.repo,
51+
issue_number: prNumber,
52+
body: comment
53+
});
54+
} else {
55+
const noIssuesComment = "**Semgrep findings:** No issues found, Good to merge.";
56+
await github.rest.issues.createComment({
57+
...context.repo,
58+
issue_number: prNumber,
59+
body: noIssuesComment
60+
});
61+
}
62+
} else {
63+
console.log("This workflow wasn't triggered by a pull request, so no comment will be added.");
64+
}

0 commit comments

Comments
 (0)