-
-
Notifications
You must be signed in to change notification settings - Fork 7
100 lines (89 loc) · 3.69 KB
/
secret-scan.yml
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Secret Scan
on:
push:
branches:
- main
pull_request:
jobs:
trufflehog:
name: Trufflehog
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: TruffleHog OSS
uses: trufflesecurity/trufflehog@main
with:
extra_args: --debug --only-verified
semgrep:
name: Semgrep Code Quality Scan
runs-on: ubuntu-latest
timeout-minutes: 60
container:
# A Docker image with Semgrep installed. Do not change this.
image: semgrep/semgrep
# Skip any PR created by dependabot to avoid permission issues:
if: (github.actor != 'dependabot[bot]')
steps:
- uses: actions/checkout@v4
- run: semgrep scan --config auto --oss-only --output=results.txt
- run: cat results.txt
- uses: actions/github-script@v7
if: github.event_name == 'pull_request'
with:
script: |
let results = '';
await exec.exec('cat', ['results.txt'], {
listeners: {
stdout: (data) => {
results += data.toString();
}
}
});
// List previous issue comments
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
// If there are any comments created by `github-actions[bot]`
// and have the body containing `semgrep`, we should update
// the comment, instead of creating a new one.
const previousComment = comments.data.find(comment => {
return comment.user.login === 'github-actions[bot]' && comment.body.includes('github-actions-semgrep-identifier');
});
const updatedDate = new Date()
.toLocaleString('en-US', {dateStyle: "long", timeStyle: "long", hour12: false, timeZone: "UTC"});
if (previousComment) {
// If there are previous comment and the current result is clean,
// then update the comment to a congratulation response.
if (!results.trim()) {
await github.rest.issues.updateComment({
comment_id: previousComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: `<!-- github-actions-semgrep-identifier --> 🎉 Congratulations! No Semgrep issues found in this PR. (last updated: ${updatedDate})`,
});
return;
}
await github.rest.issues.updateComment({
comment_id: previousComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: `<!-- github-actions-semgrep-identifier --> Here are the results of the [Semgrep](https://semgrep.dev/docs/getting-started/quickstart-oss/) scan (last updated: ${updatedDate}):\n\`\`\`\n${results}\n\`\`\``,
});
return;
}
// If results is empty, do nothing
if (!results.trim()) {
return;
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `<!-- github-actions-semgrep-identifier --> Here are the results of the [Semgrep](https://semgrep.dev/docs/getting-started/quickstart-oss/) scan:\n\`\`\`\n${results.trim()}\n\`\`\``,
});