-
-
Notifications
You must be signed in to change notification settings - Fork 186
103 lines (87 loc) · 3.19 KB
/
Copy pathcodeql.yml
File metadata and controls
103 lines (87 loc) · 3.19 KB
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
name: CodeQL
on:
push:
branches: [master]
pull_request:
branches: [master]
types: [assigned, opened, synchronize, reopened, edited, ready_for_review]
schedule:
- cron: '0 6 * * 1' # Every Monday at 06:00 UTC
concurrency:
group: codeql-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
security-events: write
jobs:
analyze:
name: analyze (${{ matrix.module }})
if: ${{ github.event.pull_request.draft == false }}
strategy:
fail-fast: false
matrix:
include:
- module: .
build_tags: ""
- module: server
build_tags: ""
- module: agent
build_tags: "docker"
- module: gateway
build_tags: ""
- module: openapi
build_tags: ""
- module: tests
build_tags: ""
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
with:
go-version-file: go.mod
- name: Initialize CodeQL
uses: github/codeql-action/init@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
with:
languages: go
build-mode: manual
db-location: ${{ github.workspace }}/.codeql/db-${{ matrix.module == '.' && 'root' || matrix.module }}
- name: Build ${{ matrix.module }} under CodeQL tracing
run: |
cd "${{ matrix.module }}"
if [ -n "${{ matrix.build_tags }}" ]; then
go build -tags "${{ matrix.build_tags }}" ./...
else
go build ./...
fi
- name: Assert CodeQL DB is non-empty
run: |
DB_DIR="${{ github.workspace }}/.codeql/db-${{ matrix.module == '.' && 'root' || matrix.module }}"
FILE_COUNT=$(find "${DB_DIR}" -name "*.trap.gz" -o -name "*.trap" 2>/dev/null | wc -l)
echo "Traced files in ${DB_DIR}: ${FILE_COUNT}"
if [ "${FILE_COUNT}" -eq 0 ]; then
echo "ERROR: CodeQL database for module '${{ matrix.module }}' is empty — no files were traced."
exit 1
fi
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
with:
category: codeql-go-${{ matrix.module == '.' && 'root' || matrix.module }}
upload: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}
output: codeql-results-${{ matrix.module == '.' && 'root' || matrix.module }}.sarif
# security-gate aggregates all CodeQL jobs for branch protection.
security-gate:
name: security-gate
needs: [analyze]
if: always()
runs-on: ubuntu-latest
steps:
- name: Check CodeQL results
run: |
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" || \
"${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
echo "One or more CodeQL analysis jobs failed or were cancelled."
exit 1
fi
echo "All CodeQL analysis jobs passed or were skipped."