Repository navigation
168 lines (155 loc) · 8.84 KB
/
Copy pathcodeql.yml
File metadata and controls
168 lines (155 loc) · 8.84 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
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
name: CodeQL Advanced
on:
push:
branches: ["main"]
pull_request:
types: [opened, reopened, ready_for_review, synchronize, labeled, unlabeled]
schedule:
- cron: "24 19 * * 3"
# Cancel superseded runs when a pull request is updated. Non-PR events keep
# unique groups, so main pushes and scheduled scans are never cancelled.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
# Least privilege: the analyze job escalates to security-events: write via its
# own job-level permissions block.
permissions:
contents: read
jobs:
classify:
name: classify (codeql)
# Classifies the pull request change range before any validation
# runs. Only an explicit documentation-only allowlist match can
# skip expensive jobs, and only for pull_request events; a failed
# or missing classification fails safe to full validation. The
# validation-gate job below audits this decision on every run.
runs-on: ubuntu-latest
outputs:
category: ${{ steps.classify.outputs.category }}
reason: ${{ steps.classify.outputs.reason }}
reason-code: ${{ steps.classify.outputs.reason-code }}
changed-files: ${{ steps.classify.outputs.changed-files }}
allowlist-fingerprint: ${{ steps.classify.outputs.allowlist-fingerprint }}
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Classification resolves the merge base from history.
fetch-depth: 0
# This job never pushes — don't persist the GITHUB_TOKEN.
persist-credentials: false
- name: Classify changed files
id: classify
uses: ./.github/actions/classify-changes
with:
event-name: ${{ github.event_name }}
head-sha: ${{ github.sha }}
force-full-label: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci:full-validation') }}
force-full-variable: ${{ vars.ZOO_CODE_REQUIRE_FULL_VALIDATION == 'true' }}
analyze:
name: Analyze (${{ matrix.language }})
needs: classify
# Fail-safe: only a successful documentation-only classification on
# a pull request skips this job. Merge-queue, push, and scheduled
# analysis always runs.
if: ${{ !cancelled() && (needs.classify.result != 'success' || github.event_name != 'pull_request' || needs.classify.outputs.category != 'docs-only') }}
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write
# required to fetch internal or private CodeQL packs
packages: read
# only required for workflows in private repositories
actions: read
contents: read
strategy:
fail-fast: false
matrix:
include:
- language: javascript-typescript
build-mode: none
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
with:
category: "/language:${{matrix.language}}"
validation-gate:
name: validation-gate (codeql)
# Always-running required gate for change-based validation. It
# rejects a missing or failed classification, validation jobs that
# did not run when full validation was required, jobs that ran when
# a documentation-only skip was expected, and a classifier replay
# that disagrees with the recorded classification. It also records
# the classification, the skipped work, runner minutes, and the
# required-check completion time in the job summary.
if: always()
needs:
- classify
- analyze
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# The gate replays the classifier against the same range.
fetch-depth: 0
# This job never pushes — don't persist the GITHUB_TOKEN.
persist-credentials: false
- name: Run validation gate
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEEDS_JSON: ${{ toJSON(needs) }}
EVENT_NAME: ${{ github.event_name }}
PR_DRAFT: ${{ github.event.pull_request.draft }}
RUN_ID: ${{ github.run_id }}
HEAD_SHA: ${{ github.sha }}
FORCE_FULL_LABEL: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci:full-validation') }}
FORCE_FULL_VARIABLE: ${{ vars.ZOO_CODE_REQUIRE_FULL_VALIDATION == 'true' }}
WATCHED_JOBS: analyze:always:gated
run: |
BASE_SHA="$(git rev-parse "${HEAD_SHA}^1")"
node scripts/change-gate.mjs ci --base "$BASE_SHA" --head "$HEAD_SHA"