|
1 | | -# SPDX-License-Identifier: PMPL-1.0-or-later |
2 | | -# CodeQL Security Analysis |
3 | | -# Scans for security vulnerabilities and coding errors |
4 | | -# https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning |
5 | | - |
6 | | -permissions: |
7 | | - contents: read |
8 | | - |
9 | | -name: "CodeQL Security Analysis" |
| 1 | +# SPDX-License-Identifier: PMPL-1.0 |
| 2 | +name: CodeQL Security Analysis |
10 | 3 |
|
11 | 4 | on: |
12 | 5 | push: |
13 | | - branches: [ "main", "master", "develop" ] |
| 6 | + branches: [main, master] |
14 | 7 | pull_request: |
15 | | - branches: [ "main", "master", "develop" ] |
| 8 | + branches: [main, master] |
16 | 9 | schedule: |
17 | | - # Run weekly on Sunday at 3:23 AM UTC |
18 | | - - cron: '23 3 * * 0' |
19 | | - workflow_dispatch: |
| 10 | + - cron: '0 6 * * 1' |
20 | 11 |
|
| 12 | +# Estate guardrail: cancel superseded runs so re-pushes / rebased PR |
| 13 | +# updates do not pile up queued runs against the shared account-wide |
| 14 | +# Actions concurrency pool. Applied only to read-only check workflows |
| 15 | +# (no publish/mutation), so cancelling a superseded run is always safe. |
21 | 16 | concurrency: |
22 | | - group: codeql-${{ github.ref }} |
| 17 | + group: ${{ github.workflow }}-${{ github.ref }} |
23 | 18 | cancel-in-progress: true |
24 | 19 |
|
25 | | -jobs: |
26 | | - # First, detect which languages are in the repository |
27 | | - detect-languages: |
28 | | - name: Detect Languages |
29 | | - runs-on: ubuntu-latest |
30 | | - outputs: |
31 | | - matrix: ${{ steps.detect.outputs.matrix }} |
32 | | - steps: |
33 | | - - name: Checkout |
34 | | - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
35 | | - |
36 | | - - name: Detect languages |
37 | | - id: detect |
38 | | - run: | |
39 | | - LANGUAGES=() |
40 | | -
|
41 | | - # Check for JavaScript/TypeScript |
42 | | - if find . -name "*.js" -o -name "*.ts" -o -name "*.jsx" -o -name "*.tsx" | grep -q .; then |
43 | | - LANGUAGES+=('{"language": "javascript-typescript", "build-mode": "none"}') |
44 | | - fi |
45 | | -
|
46 | | - # Check for Python |
47 | | - if find . -name "*.py" | grep -q .; then |
48 | | - LANGUAGES+=('{"language": "python", "build-mode": "none"}') |
49 | | - fi |
50 | | -
|
51 | | - # Check for Go |
52 | | - if find . -name "*.go" | grep -q .; then |
53 | | - LANGUAGES+=('{"language": "go", "build-mode": "autobuild"}') |
54 | | - fi |
55 | | -
|
56 | | - # Check for Ruby |
57 | | - if find . -name "*.rb" | grep -q .; then |
58 | | - LANGUAGES+=('{"language": "ruby", "build-mode": "none"}') |
59 | | - fi |
60 | | -
|
61 | | - # Check for Java/Kotlin |
62 | | - if find . -name "*.java" -o -name "*.kt" | grep -q .; then |
63 | | - LANGUAGES+=('{"language": "java-kotlin", "build-mode": "autobuild"}') |
64 | | - fi |
65 | | -
|
66 | | - # Check for C/C++ |
67 | | - if find . -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" | grep -q .; then |
68 | | - LANGUAGES+=('{"language": "c-cpp", "build-mode": "autobuild"}') |
69 | | - fi |
70 | | -
|
71 | | - # Check for C# |
72 | | - if find . -name "*.cs" | grep -q .; then |
73 | | - LANGUAGES+=('{"language": "csharp", "build-mode": "autobuild"}') |
74 | | - fi |
75 | | -
|
76 | | - # Check for Swift |
77 | | - if find . -name "*.swift" | grep -q .; then |
78 | | - LANGUAGES+=('{"language": "swift", "build-mode": "autobuild"}') |
79 | | - fi |
80 | | -
|
81 | | - # Always include actions analysis for GitHub workflows |
82 | | - LANGUAGES+=('{"language": "actions", "build-mode": "none"}') |
83 | | -
|
84 | | - # Build JSON matrix |
85 | | - if [ ${#LANGUAGES[@]} -gt 0 ]; then |
86 | | - MATRIX=$(printf '%s |
87 | | -' "${LANGUAGES[@]}" | jq -s '{include: .}') |
88 | | - else |
89 | | - MATRIX='{"include": [{"language": "actions", "build-mode": "none"}]}' |
90 | | - fi |
91 | | - |
92 | | - echo "matrix=$MATRIX" >> $GITHUB_OUTPUT |
93 | | - echo "Detected languages: $MATRIX" |
| 20 | +permissions: |
| 21 | + contents: read |
94 | 22 |
|
| 23 | +jobs: |
95 | 24 | analyze: |
96 | | - name: Analyze (${{ matrix.language }}) |
97 | | - needs: detect-languages |
98 | | - runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} |
99 | | - timeout-minutes: 360 |
| 25 | + runs-on: ubuntu-latest |
100 | 26 | permissions: |
101 | | - security-events: write |
102 | | - packages: read |
103 | | - actions: read |
104 | 27 | contents: read |
105 | | - |
| 28 | + security-events: write |
106 | 29 | strategy: |
107 | 30 | fail-fast: false |
108 | | - matrix: ${{ fromJson(needs.detect-languages.outputs.matrix) }} |
| 31 | + matrix: |
| 32 | + include: |
| 33 | + - language: javascript-typescript |
| 34 | + build-mode: none |
109 | 35 |
|
110 | 36 | steps: |
111 | | - - name: Checkout repository |
112 | | - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
113 | | - |
114 | | - # Setup for different languages |
115 | | - - name: Setup Node.js |
116 | | - if: matrix.language == 'javascript-typescript' |
117 | | - uses: actions/setup-node@49933ea5288caeca8642195f2b846b8bbe245a93 # v4 |
118 | | - with: |
119 | | - node-version: '20' |
120 | | - |
121 | | - - name: Setup Python |
122 | | - if: matrix.language == 'python' |
123 | | - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 |
124 | | - with: |
125 | | - python-version: '3.12' |
126 | | - |
127 | | - - name: Setup Go |
128 | | - if: matrix.language == 'go' |
129 | | - uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5 |
130 | | - with: |
131 | | - go-version: '1.22' |
132 | | - |
133 | | - - name: Setup Java |
134 | | - if: matrix.language == 'java-kotlin' |
135 | | - uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9 # v4 |
136 | | - with: |
137 | | - distribution: 'temurin' |
138 | | - java-version: '21' |
139 | | - |
140 | | - - name: Setup .NET |
141 | | - if: matrix.language == 'csharp' |
142 | | - uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4 |
143 | | - with: |
144 | | - dotnet-version: '8.0.x' |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
145 | 39 |
|
146 | | - # Initialize CodeQL |
147 | 40 | - name: Initialize CodeQL |
148 | | - uses: github/codeql-action/init@b2f9ef845756500b97acbdaf5c1dd4e9c1d15734 # v3 |
| 41 | + uses: github/codeql-action/init@c6f931105cb2c34c8f901cc885ba1e2e259cf745 # v3 |
149 | 42 | with: |
150 | 43 | languages: ${{ matrix.language }} |
151 | 44 | build-mode: ${{ matrix.build-mode }} |
152 | | - # Enable security-extended for more thorough analysis |
153 | | - queries: security-extended,security-and-quality |
154 | | - |
155 | | - # Manual build for compiled languages if autobuild fails |
156 | | - - name: Build (Manual) |
157 | | - if: matrix.build-mode == 'manual' |
158 | | - shell: bash |
159 | | - run: | |
160 | | - chmod +x ci-scripts/*.sh 2>/dev/null || true |
161 | | - if [ -f "ci-scripts/build.sh" ]; then |
162 | | - ci-scripts/build.sh |
163 | | - else |
164 | | - echo "No build script found, attempting standard builds..." |
165 | | - # Go |
166 | | - if [ -f "go.mod" ]; then |
167 | | - go build ./... |
168 | | - fi |
169 | | - # Java/Maven |
170 | | - if [ -f "pom.xml" ]; then |
171 | | - mvn package -DskipTests -B |
172 | | - fi |
173 | | - # Java/Gradle |
174 | | - if [ -f "build.gradle" ] || [ -f "build.gradle.kts" ]; then |
175 | | - ./gradlew build -x test 2>/dev/null || gradle build -x test |
176 | | - fi |
177 | | - # .NET |
178 | | - if ls *.csproj 1>/dev/null 2>&1; then |
179 | | - dotnet build |
180 | | - fi |
181 | | - # C/C++ |
182 | | - if [ -f "CMakeLists.txt" ]; then |
183 | | - mkdir -p build && cd build && cmake .. && make |
184 | | - elif [ -f "Makefile" ]; then |
185 | | - make |
186 | | - fi |
187 | | - fi |
188 | 45 |
|
189 | | - # Perform CodeQL Analysis |
190 | 46 | - name: Perform CodeQL Analysis |
191 | | - uses: github/codeql-action/analyze@b2f9ef845756500b97acbdaf5c1dd4e9c1d15734 # v3 |
| 47 | + uses: github/codeql-action/analyze@c6f931105cb2c34c8f901cc885ba1e2e259cf745 # v3 |
192 | 48 | with: |
193 | 49 | category: "/language:${{ matrix.language }}" |
194 | | - # Upload SARIF results |
195 | | - upload: always |
196 | | - |
197 | | - # Summary job |
198 | | - security-summary: |
199 | | - name: Security Summary |
200 | | - needs: analyze |
201 | | - runs-on: ubuntu-latest |
202 | | - if: always() |
203 | | - steps: |
204 | | - - name: Check analysis results |
205 | | - run: | |
206 | | - echo "## CodeQL Security Analysis Summary" >> $GITHUB_STEP_SUMMARY |
207 | | - echo "" >> $GITHUB_STEP_SUMMARY |
208 | | - echo "Security scanning completed. Review the Security tab for detailed findings." >> $GITHUB_STEP_SUMMARY |
209 | | - echo "" >> $GITHUB_STEP_SUMMARY |
210 | | - echo "### Analyzed Components" >> $GITHUB_STEP_SUMMARY |
211 | | - echo "- GitHub Actions workflows" >> $GITHUB_STEP_SUMMARY |
212 | | - echo "- Source code (detected languages)" >> $GITHUB_STEP_SUMMARY |
213 | | - echo "" >> $GITHUB_STEP_SUMMARY |
214 | | - echo "For more details, see:" >> $GITHUB_STEP_SUMMARY |
215 | | - echo "- [Security Advisories](../../security/advisories)" >> $GITHUB_STEP_SUMMARY |
216 | | - echo "- [Code Scanning Alerts](../../security/code-scanning)" >> $GITHUB_STEP_SUMMARY |
0 commit comments