Skip to content

Commit 934f6b5

Browse files
CopilotseesharprunCopilot
authored
Add CodeQL code scanning workflow (Python, JavaScript/TypeScript, C#, Go) (#15)
Adds CodeQL analysis to gate PRs and run on schedule across the languages present in the monorepo, using the `Analyze Samples` workflow (named to mirror the existing `Validate Samples` workflow). ## Workflow design - **Separate jobs per language** (`analyze-python`, `analyze-javascript`, `analyze-dotnet`, `analyze-go`) so each produces an independent status check that can be individually required in branch protection rules - Job display names follow the same pattern as the validation workflow: `Analyze Python Samples`, `Analyze JavaScript/TypeScript Samples`, `Analyze .NET Samples`, `Analyze Go Samples` - `if: github.repository == 'AzureCosmosDB/samples'` guard on the `Perform CodeQL Analysis` step (SARIF upload) ensures fork PRs complete the jobs successfully — satisfying required status checks — while the upload is skipped where `security-events: write` is unavailable - `workflow_dispatch` added for on-demand scans - `queries: security-and-quality` on all jobs — reference examples only use default security queries, missing code quality coverage - Workflow-level `concurrency` with `cancel-in-progress: true` prevents redundant queued runs on rapid pushes ## Per-language build modes | Language | Build mode | Notes | |---|---|---| | Python | `none` | Interpreted; no build needed | | JavaScript/TypeScript | `none` | Source-only analysis; compilation is handled by the validation workflow | | C# | `none` | Source-only analysis; compilation is handled by the validation workflow | | Go | `autobuild` | Works with module-per-sample layout | ## Repository setup required 1. **Branch protection** (Settings → Branches → `main`): add `Analyze Samples / Analyze Python Samples`, `Analyze Samples / Analyze JavaScript/TypeScript Samples`, `Analyze Samples / Analyze .NET Samples`, `Analyze Samples / Analyze Go Samples` as required status checks after the first workflow run 2. **Alert thresholds** (Settings → Code security → Code scanning): configure High/Critical to block PRs 3. **Private repos only**: GitHub Advanced Security must be enabled; public repos get this free ## Extending for future languages Add a new job when `java/` directories land — `java-kotlin` with `build-mode: none`. <!-- START COPILOT CODING AGENT TIPS --> --- 💬 Send tasks to Copilot coding agent from [Slack](https://gh.io/cca-slack-docs) and [Teams](https://gh.io/cca-teams-docs) to turn conversations into code. Copilot posts an update in your thread when it's finished. --------- Signed-off-by: Sidney Andrews <sidandrews@microsoft.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: seesharprun <5067401+seesharprun@users.noreply.github.com> Co-authored-by: Sidney Andrews <sidandrews@microsoft.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 585653e commit 934f6b5

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Analyze Samples
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
schedule:
9+
- cron: '30 4 * * 2'
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: codeql-${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
analyze-python:
18+
name: Analyze Python Samples
19+
runs-on: ubuntu-latest
20+
permissions:
21+
security-events: write
22+
packages: read
23+
actions: read
24+
contents: read
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v6
28+
- name: Initialize CodeQL
29+
uses: github/codeql-action/init@v3
30+
with:
31+
languages: python
32+
build-mode: none
33+
queries: security-and-quality
34+
- name: Perform CodeQL Analysis
35+
if: github.repository == 'AzureCosmosDB/samples'
36+
uses: github/codeql-action/analyze@v3
37+
with:
38+
category: "/language:python"
39+
40+
analyze-javascript:
41+
name: Analyze JavaScript/TypeScript Samples
42+
runs-on: ubuntu-latest
43+
permissions:
44+
security-events: write
45+
packages: read
46+
actions: read
47+
contents: read
48+
steps:
49+
- name: Checkout repository
50+
uses: actions/checkout@v6
51+
- name: Initialize CodeQL
52+
uses: github/codeql-action/init@v3
53+
with:
54+
languages: javascript-typescript
55+
build-mode: none
56+
queries: security-and-quality
57+
- name: Perform CodeQL Analysis
58+
if: github.repository == 'AzureCosmosDB/samples'
59+
uses: github/codeql-action/analyze@v3
60+
with:
61+
category: "/language:javascript-typescript"
62+
63+
analyze-dotnet:
64+
name: Analyze .NET Samples
65+
runs-on: ubuntu-latest
66+
permissions:
67+
security-events: write
68+
packages: read
69+
actions: read
70+
contents: read
71+
steps:
72+
- name: Checkout repository
73+
uses: actions/checkout@v6
74+
- name: Initialize CodeQL
75+
uses: github/codeql-action/init@v3
76+
with:
77+
languages: csharp
78+
build-mode: none
79+
queries: security-and-quality
80+
- name: Perform CodeQL Analysis
81+
if: github.repository == 'AzureCosmosDB/samples'
82+
uses: github/codeql-action/analyze@v3
83+
with:
84+
category: "/language:csharp"
85+
86+
analyze-go:
87+
name: Analyze Go Samples
88+
runs-on: ubuntu-latest
89+
permissions:
90+
security-events: write
91+
packages: read
92+
actions: read
93+
contents: read
94+
steps:
95+
- name: Checkout repository
96+
uses: actions/checkout@v6
97+
- name: Initialize CodeQL
98+
uses: github/codeql-action/init@v3
99+
with:
100+
languages: go
101+
build-mode: autobuild
102+
queries: security-and-quality
103+
- name: Perform CodeQL Analysis
104+
if: github.repository == 'AzureCosmosDB/samples'
105+
uses: github/codeql-action/analyze@v3
106+
with:
107+
category: "/language:go"

0 commit comments

Comments
 (0)