Skip to content

Commit cd84bab

Browse files
[Infra] Require CodeQL for PRs (#6497)
1 parent 616e273 commit cd84bab

File tree

3 files changed

+90
-62
lines changed

3 files changed

+90
-62
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ jobs:
1616
lint-misspell-sanitycheck:
1717
uses: ./.github/workflows/sanitycheck.yml
1818

19+
code-ql:
20+
uses: ./.github/workflows/codeql-analysis-steps.yml
21+
permissions:
22+
actions: read
23+
contents: read
24+
security-events: write
25+
1926
detect-changes:
2027
runs-on: windows-latest
2128
outputs:
@@ -175,6 +182,7 @@ jobs:
175182
build-test:
176183
needs: [
177184
detect-changes,
185+
code-ql,
178186
lint-misspell-sanitycheck,
179187
lint-md,
180188
lint-dotnet-format,
@@ -192,5 +200,15 @@ jobs:
192200
if: always() && !cancelled()
193201
runs-on: ubuntu-22.04
194202
steps:
195-
- run: |
196-
if ( ${{ contains(needs.*.result, 'failure') }} == true ); then echo 'build failed'; exit 1; else echo 'build complete'; fi
203+
- name: Report CI status
204+
shell: bash
205+
env:
206+
CI_SUCCESS: ${{ !contains(needs.*.result, 'failure') }}
207+
run: |
208+
if [ "${CI_SUCCESS}" == "true" ]
209+
then
210+
echo 'Build complete'
211+
else
212+
echo 'Build failed'
213+
exit 1
214+
fi
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: codeql-analysis-steps
2+
3+
on:
4+
workflow_call:
5+
6+
permissions: {}
7+
8+
jobs:
9+
analyze:
10+
permissions:
11+
actions: read # for github/codeql-action/init to get workflow details
12+
contents: read # for actions/checkout to fetch code
13+
security-events: write # for github/codeql-action/analyze to upload SARIF results
14+
runs-on: windows-latest
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
language: ['actions', 'csharp']
20+
21+
steps:
22+
- name: Configure Pagefile
23+
if: matrix.language == 'csharp'
24+
uses: al-cheb/configure-pagefile-action@a3b6ebd6b634da88790d9c58d4b37a7f4a7b8708 # v1.4
25+
with:
26+
minimum-size: 8GB
27+
maximum-size: 32GB
28+
disk-root: "D:"
29+
30+
- name: Checkout repository
31+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
32+
with:
33+
filter: 'tree:0'
34+
persist-credentials: false
35+
show-progress: false
36+
37+
- name: Initialize CodeQL
38+
uses: github/codeql-action/init@192325c86100d080feab897ff886c34abd4c83a3 # v3.30.3
39+
with:
40+
build-mode: none
41+
languages: ${{ matrix.language }}
42+
43+
- name: Perform CodeQL Analysis
44+
uses: github/codeql-action/analyze@192325c86100d080feab897ff886c34abd4c83a3 # v3.30.3
45+
with:
46+
category: '/language:${{ matrix.language }}'
47+
48+
results:
49+
if: ${{ !cancelled() }}
50+
needs: [ analyze ]
51+
runs-on: ubuntu-latest
52+
53+
steps:
54+
- name: Report status
55+
shell: bash
56+
env:
57+
SCAN_SUCCESS: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
58+
run: |
59+
if [ "${SCAN_SUCCESS}" == "true" ]
60+
then
61+
echo 'CodeQL analysis successful'
62+
else
63+
echo 'CodeQL analysis failed'
64+
exit 1
65+
fi
Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,16 @@
11
name: "CodeQL"
22

33
on:
4-
push:
5-
branches: [ 'main' ]
6-
pull_request:
7-
branches: [ 'main' ]
84
schedule:
95
- cron: '0 0 * * *' # once in a day at 00:00
106
workflow_dispatch:
117

128
permissions: {}
139

1410
jobs:
15-
analyze:
11+
code-ql:
12+
uses: ./.github/workflows/codeql-analysis-steps.yml
1613
permissions:
17-
actions: read # for github/codeql-action/init to get workflow details
18-
contents: read # for actions/checkout to fetch code
19-
security-events: write # for github/codeql-action/analyze to upload SARIF results
20-
runs-on: windows-latest
21-
22-
strategy:
23-
fail-fast: false
24-
matrix:
25-
language: ['actions', 'csharp']
26-
27-
steps:
28-
- name: Configure Pagefile
29-
if: matrix.language == 'csharp'
30-
uses: al-cheb/configure-pagefile-action@a3b6ebd6b634da88790d9c58d4b37a7f4a7b8708 # v1.4
31-
with:
32-
minimum-size: 8GB
33-
maximum-size: 32GB
34-
disk-root: "D:"
35-
36-
- name: Checkout repository
37-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
38-
with:
39-
filter: 'tree:0'
40-
persist-credentials: false
41-
show-progress: false
42-
43-
- name: Initialize CodeQL
44-
uses: github/codeql-action/init@192325c86100d080feab897ff886c34abd4c83a3 # v3.30.3
45-
with:
46-
build-mode: none
47-
languages: ${{ matrix.language }}
48-
49-
- name: Perform CodeQL Analysis
50-
uses: github/codeql-action/analyze@192325c86100d080feab897ff886c34abd4c83a3 # v3.30.3
51-
with:
52-
category: '/language:${{ matrix.language }}'
53-
54-
codeql:
55-
if: ${{ !cancelled() }}
56-
needs: [ analyze ]
57-
runs-on: ubuntu-latest
58-
59-
steps:
60-
- name: Report status
61-
shell: bash
62-
env:
63-
SCAN_SUCCESS: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
64-
run: |
65-
if [ "${SCAN_SUCCESS}" == "true" ]
66-
then
67-
echo 'CodeQL analysis successful'
68-
else
69-
echo 'CodeQL analysis failed'
70-
exit 1
71-
fi
14+
actions: read
15+
contents: read
16+
security-events: write

0 commit comments

Comments
 (0)