Skip to content

Commit 4f6e0f8

Browse files
committed
feat: add CodeQL analysis workflow configuration
1 parent 215d7f0 commit 4f6e0f8

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

.github/workflows/codeql.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# 对于大多数项目,此工作流文件无需更改;只需提交到您的仓库即可。
2+
#
3+
# 您可以根据需要修改此文件,以覆盖分析的语言集,或提供自定义查询或构建逻辑。
4+
#
5+
# ******** 注意 ********
6+
# 我们已尝试检测您的仓库中的语言。请检查下面定义的 `language` 矩阵,确保包含了所有受支持的 CodeQL 语言。
7+
name: "CodeQL Advanced"
8+
on:
9+
push:
10+
branches: [ "main" ]
11+
pull_request:
12+
branches: [ "main" ]
13+
schedule:
14+
- cron: '23 5 * * 2'
15+
workflow_dispatch:
16+
jobs:
17+
analyze:
18+
name: Analyze (${{ matrix.language }})
19+
# Runner 的规格会影响 CodeQL 分析时间。详情请参阅:
20+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
21+
# - https://gh.io/supported-runners-and-hardware-resources
22+
# - https://gh.io/using-larger-runners (仅限 GitHub.com)
23+
# 建议使用更高规格的 Runner 或更大资源的机器以提升分析速度。
24+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
25+
permissions:
26+
# 所有工作流都需要
27+
security-events: write
28+
# 获取内部或私有 CodeQL 包时需要
29+
packages: read
30+
# 仅私有仓库工作流需要
31+
actions: read
32+
contents: read
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
include:
37+
- language: actions
38+
build-mode: none
39+
- language: javascript-typescript
40+
build-mode: none
41+
- language: python
42+
build-mode: none
43+
- language: java-kotlin
44+
build-mode: none
45+
# CodeQL 支持以下 'language' 关键字:'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
46+
# 使用 `c-cpp` 可分析 C、C++ 或两者的代码
47+
# 使用 'java-kotlin' 可分析 Java、Kotlin 或两者的代码
48+
# 使用 'javascript-typescript' 可分析 JavaScript、TypeScript 或两者的代码
49+
# 了解如何更改分析语言或自定义分析模式,请参阅:
50+
# https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning
51+
# 如果分析编译型语言,可修改 'build-mode' 以自定义分析方式,详见:
52+
# https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
53+
steps:
54+
- name: Checkout repository
55+
uses: actions/checkout@v4
56+
# 在运行 `github/codeql-action/init` 之前可添加任何设置步骤。
57+
# 包括安装编译器或运行环境(如 `actions/setup-node` 等)。通常仅手动构建时需要。
58+
# - name: Setup runtime (示例)
59+
# uses: actions/setup-example@v1
60+
# 初始化 CodeQL 工具以进行扫描。
61+
- name: Initialize CodeQL
62+
uses: github/codeql-action/init@v3
63+
with:
64+
languages: ${{ matrix.language }}
65+
build-mode: ${{ matrix.build-mode }}
66+
# 如需指定自定义查询,可在此处或配置文件中设置。
67+
# 默认情况下,此处列出的查询会覆盖配置文件中指定的查询。
68+
# 在列表前加 "+" 可同时使用此处和配置文件中的查询。
69+
# 更多 CodeQL 查询包详情请参阅:
70+
# 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
71+
# queries: security-extended,security-and-quality
72+
# 如果某种语言的 analyze 步骤失败,提示“无法自动构建您的代码”,请在上方矩阵中将该语言的 build-mode 设置为 "manual",并在此步骤中添加构建命令。
73+
# ℹ️ 可使用操作系统 shell 运行命令行程序。
74+
# 📚 详见 https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
75+
- if: matrix.build-mode == 'manual'
76+
shell: bash
77+
run: |
78+
echo '如果您为一种或多种语言使用了 "manual" 构建模式,请在此处替换为您的构建命令,例如:'
79+
echo ' make bootstrap'
80+
echo ' make release'
81+
exit 1
82+
- name: Perform CodeQL Analysis
83+
uses: github/codeql-action/analyze@v3
84+
with:
85+
category: "/language:${{matrix.language}}"
86+

0 commit comments

Comments
 (0)