forked from photoview/photoview
-
Notifications
You must be signed in to change notification settings - Fork 0
438 lines (385 loc) · 15.3 KB
/
codeql-analysis.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
name: "Code Analysis"
on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '0 1 * * 4'
jobs:
create-matrix:
runs-on: ubuntu-latest
steps:
- name: Get languages from repo
id: set-matrix
uses: advanced-security/set-codeql-language-matrix@v1
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
endpoint: ${{ github.event.repository.languages_url }}
outputs:
matrix: ${{ steps.set-matrix.outputs.languages }}
analyze:
name: Analyze
needs: create-matrix
if: ${{ needs.create-matrix.outputs.matrix != '[]' }} && github.repository == 'kkovaletp/photoview'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: ${{ fromJSON(needs.create-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# Run further tests
queries: security-extended, security-and-quality
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
anchore:
name: Anchore scan code dependencies
if: github.repository == 'kkovaletp/photoview'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate report
id: scan
uses: anchore/scan-action@v5
with:
path: "."
fail-build: false
add-cpes-if-none: true
- name: Upload report
uses: github/codeql-action/upload-sarif@v3
if: ${{ steps.scan.conclusion == 'success' || steps.scan.conclusion == 'failure' }}
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
- name: Scan PR source code
id: scan-fixed
uses: anchore/scan-action@v5
if: always() && github.event_name == 'pull_request'
with:
path: "."
fail-build: false
add-cpes-if-none: true
output-format: json
severity-cutoff: high
only-fixed: true
- name: Prepare JSON
if: ${{ ( steps.scan-fixed.conclusion == 'success' || steps.scan-fixed.conclusion == 'failure' ) && github.event_name == 'pull_request' }}
run: |
jq '{
"|": .matches | map({
"language": .artifact.language,
"id": .vulnerability.id,
"severity": .vulnerability.severity,
"name": .artifact.name,
"version": .artifact.version,
"fix-versions": .vulnerability.fix.versions[0],
"path": .artifact.locations[0].path,
"description": .vulnerability.description
})
}' ${{ steps.scan-fixed.outputs.json }} > vulns.json
cat vulns.json | jq
- name: JSON to Table
uses: Teebra/[email protected]
if: github.event_name == 'pull_request'
with:
json-file: vulns.json
- name: Update Pull Request
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.COMMENT_TOKEN }}
script: |
const fs = require('fs');
let scanResults = fs.readFileSync('output.html', 'utf8');
let output = '';
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const botComment = comments.data.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('Anchore'));
output += '#### Anchore Grype scan results:\n';
output += 'Anchore Grype detected vulnerabilities in project dependencies, for which fixed versions are available.\n';
output += 'Please find more details in the "Checks" tab of this PR > "Code scanning results" > "Grype".\n';
if (scanResults) {
output += '\n' + scanResults + '\n';
if (botComment) {
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
});
}
} else {
if (botComment) {
await github.rest.issues.deleteComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo
});
}
}
hadolint:
name: Hadolint Dockerfile
if: github.repository == 'kkovaletp/photoview'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Lint Dockerfile
id: hadolint
uses: hadolint/[email protected]
with:
dockerfile: Dockerfile
config: ${{ github.workspace }}/.hadolint.yaml
format: tty
failure-threshold: error
- name: Update Pull Request
uses: actions/github-script@v7
if: ${{ ( steps.hadolint.conclusion == 'success' || steps.hadolint.conclusion == 'failure' ) && github.event_name == 'pull_request' }}
with:
script: |
let hadolintResults = process.env.HADOLINT_RESULTS;
let output = '';
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const botComment = comments.data.find(
comment => comment.user.login === 'github-actions[bot]'
&& comment.body.includes('Hadolint')
);
if (hadolintResults) {
output += '#### Hadolint issues:\n';
output += 'Hadolint detected issues during execution.\n';
output += '\n```\n' + hadolintResults + '\n```\n';
output += '\nFind more info about detected issues and recommendations for fixes in the ';
output += '[Rules table](https://github.com/hadolint/hadolint?tab=readme-ov-file#rules).';
if (botComment) {
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
});
}
} else {
if (botComment) {
await github.rest.issues.deleteComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo
});
}
}
- name: Generate report
uses: hadolint/[email protected]
id: hadolint-report
if: always()
with:
dockerfile: Dockerfile
config: ${{ github.workspace }}/.hadolint.yaml
output-file: hadolint.sarif
format: sarif
failure-threshold: ignore
- name: Upload report
uses: github/codeql-action/upload-sarif@v3
if: ${{ steps.hadolint-report.conclusion == 'success' || steps.hadolint-report.conclusion == 'failure' }}
with:
sarif_file: hadolint.sarif
coverity:
name: Coverity Scan
runs-on: ubuntu-22.04
if: github.repository == 'kkovaletp/photoview' && github.event_name != 'pull_request'
env:
COV_PROJECT: kkovaletp%2Fphotoview
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Fetch branches
shell: bash
run: git fetch --all
- name: Set up Go
uses: actions/setup-go@v5
id: go
with:
go-version: '~1.21.13' # Temporary hardcode Go version, as Coverity doesn't support latest Go
cache: false
# Temporary w/a until newer GO version is not supported by Coverity
- name: Modify go.mod for CI
run: |
sed -i 's/^go [0-9]\+\.[0-9]\+\(\.[0-9]\+\)\?/go 1.21/' api/go.mod
- name: Cache Go dependencies
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get C dependencies
shell: bash
run: |
sudo add-apt-repository ppa:strukturag/libheif
sudo add-apt-repository ppa:strukturag/libde265
sudo apt-get update
sudo apt-get install -y libdlib-dev libblas-dev libatlas-base-dev liblapack-dev libjpeg-turbo8-dev libheif-dev
- name: Get GO dependencies
shell: bash
working-directory: api
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
# Coverity steps are based on the https://github.com/vapier/coverity-scan-action/blob/main/action.yml
# and the https://github.com/vapier/coverity-scan-action/pull/3/files
# The Coverity site says the tool is usually updated twice yearly, so the
# md5 of download can be used to determine whether there's been an update.
- name: Lookup Coverity Build Tool hash
id: coverity-cache-lookup
shell: bash
run: |
echo "hash=$(curl https://scan.coverity.com/download/other/linux64 \
--data "token=${{ secrets.COVERITY_SCAN_TOKEN }}&project=${{ env.COV_PROJECT }}&md5=1")" >> $GITHUB_OUTPUT
# Try to cache the tool to avoid downloading 1GB+ archive on every run.
# Cache miss will add ~30s to create, but cache hit will save minutes.
- name: Cache Coverity Analysis Tool
id: cov-analysis-cache
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/cov-analysis
key: cov-analysis-linux64-${{ steps.coverity-cache-lookup.outputs.hash }}
# Download and unpack the binaries, configure to use our GO compiler
- name: Install Coverity Analysis Tool
if: steps.cov-analysis-cache.outputs.cache-hit != 'true'
shell: bash
run: |
curl https://scan.coverity.com/download/other/linux64 \
--no-progress-meter \
--output cov-analysis.tar.gz \
--data "token=${{ secrets.COVERITY_SCAN_TOKEN }}&project=${{ env.COV_PROJECT }}"
mkdir ./cov-analysis
tar -xzf ./cov-analysis.tar.gz --strip 1 -C ./cov-analysis
rm ./cov-analysis.tar.gz
export PATH="${{ github.workspace }}/cov-analysis/bin:${PATH}"
cov-configure --comptype go --compiler $(which go)
# Register Coverity executables in system PATH
- name: Add Coverity Analysis Tool to PATH
shell: bash
run: |
echo "${{ github.workspace }}/cov-analysis/bin" >> $GITHUB_PATH
# Build and capture API code
# At this moment Coverity doesn't support GO 1.22, so ignoring build failures
- name: Build API with cov-build
shell: bash
working-directory: api
run: |
cov-build --dir ${{ github.workspace }}/cov-int \
--return-emit-failures \
--fs-capture-search ./ go build -v . || (\
cat ${{ github.workspace }}/cov-int/build-log.txt && \
exit 1 \
)
- name: Setup Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
cache-dependency-path: ui/package-lock.json
- name: Install UI dependencies
shell: bash
working-directory: ui
run: npm ci --omit=dev --ignore-scripts
# Build and capture UI code
- name: Build UI with cov-build
shell: bash
working-directory: ui
run: |
cov-build --dir ${{ github.workspace }}/cov-int \
--return-emit-failures \
--fs-capture-search ./ npm run build -- --base=/ || (\
cat ${{ github.workspace }}/cov-int/build-log.txt && \
exit 1 \
)
# Run FS capture for the rest of the files in the project
- name: Scan whole project with fs-capture
shell: bash
run: |
cov-build --dir ${{ github.workspace }}/cov-int \
--return-emit-failures --no-command \
--fs-capture-search ./ || (\
cat ${{ github.workspace }}/cov-int/build-log.txt && \
exit 1 \
)
# Remove unnecessary captures from the Coverity results before sending them for analysis
# Extract 'git blame' info for captured files
- name: Prepare collected results
shell: bash
run: |
cov-manage-emit --dir ${{ github.workspace }}/cov-int \
--verbose 2 \
--tu-pattern "file('/.vscode/')" \
--tu-pattern "file('_test.go')" \
--tu-pattern "file('/node_modules/')" \
--tu-pattern "file('/testing/')" \
--tu-pattern "file('.test.tsx')" \
--tu-pattern "file('/cov-analysis/')" \
--tu-pattern "file('/cov-int/')" \
--tu-pattern "file('/home/runner/go/pkg/')" \
list
cov-manage-emit --dir ${{ github.workspace }}/cov-int \
--verbose 2 \
--tu-pattern "file('/.vscode/')" \
--tu-pattern "file('_test.go')" \
--tu-pattern "file('/node_modules/')" \
--tu-pattern "file('/testing/')" \
--tu-pattern "file('.test.tsx')" \
--tu-pattern "file('/cov-analysis/')" \
--tu-pattern "file('/cov-int/')" \
--tu-pattern "file('/home/runner/go/pkg/')" \
delete
cov-import-scm --scm git \
--dir ${{ github.workspace }}/cov-int \
--ms-delay 10 --verbose 0
# Archive and send all the results to the Coverity server
- name: Submit results to Coverity Scan
shell: bash
run: |
tar -czvf ./cov-int.tgz ./cov-int
curl \
--form token="${{ secrets.COVERITY_SCAN_TOKEN }}" \
--form email="${{ secrets.COVERITY_SCAN_EMAIL }}" \
--form [email protected] \
--form version="${{ github.sha }}" \
--form description="coverity-scan-action ${{ github.repository }} / ${{ github.ref }}" \
"https://scan.coverity.com/builds?project=${{ env.COV_PROJECT }}"