-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (68 loc) · 2.36 KB
/
codeql.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
name: "CodeQL Analysis"
# runs on every push to the main branch, every pull request, and once a week
on:
push:
branches: ["main", "master"]
pull_request:
branches: ["main", "master"]
schedule:
- cron: "0 0 * * 3,0" # Runs every Wednesday & Sunday at midnight UTC
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
security-events: write
actions: read
contents: read
packages: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: javascript
queries: security-extended,security-and-quality
config-file: .github/codeql-config.yml # Path to the CodeQL configuration file
- name: Run ESLint
run: npm run lint -- --max-warnings=0
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:javascript"
- name: Add PR Comment with Results
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const ref = context.payload.pull_request ? context.payload.pull_request.head.sha : context.sha;
const scanResults = await github.rest.codeScanning.listAlertsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
ref: ref
});
let comment = '🌀 **codeql analysis results**\n\n';
if (scanResults.data.length === 0) {
comment += '✅ no issues found!\n';
} else {
comment += '🚨 found the following issues:\n\n';
scanResults.data.forEach(alert => {
comment += `- [${alert.rule.description}](${alert.html_url}) (${alert.rule.severity})\n`;
});
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});