Ver Fonte

新增 CodeQL 静态代码分析流水线

在项目中新增了 CodeQL 流水线配置文件,启用了对多种编程语言的静态代码分析功能,包括 Go 和 GitHub Actions,并设置了定期扫描任务以提升代码安全性。
SongZihuan há 5 dias atrás
pai
commit
a0b03b74ba
1 ficheiros alterados com 101 adições e 0 exclusões
  1. 101 0
      .github/workflows/codeql.yml

+ 101 - 0
.github/workflows/codeql.yml

@@ -0,0 +1,101 @@
+# 对于大多数项目,此工作流文件无需更改;您只需将其提交到您的代码库即可。
+#
+# 您可能希望修改此文件以覆盖已分析的语言集,或提供自定义查询或构建逻辑。
+#
+# ******** 注意 ********
+# 我们已尝试检测您代码库中的语言。请检查
+# 下面定义的“语言”矩阵,以确认您拥有正确且受支持的 CodeQL 语言集。
+#
+name: "CodeQL Advanced"
+
+on:
+  push:
+    branches:
+      - master
+      - main
+  pull_request:
+    branches: [ "master" ]
+  schedule:
+    - cron: '32 11 * * 5'
+
+jobs:
+  analyze:
+    name: Analyze (${{ matrix.language }})
+    # Runner 的大小会影响 CodeQL 分析时间。了解更多信息,请参阅:
+    # - 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)
+    # 考虑使用更大的 Runner 或资源更丰富的机器,以尽可能缩短分析时间。
+    runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
+    permissions:
+      # 所有工作流程都需要
+      security-events: write
+
+      # 需要获取内部或私有 CodeQL 包
+      packages: read
+
+      # 仅适用于私有存储库中的工作流程
+      actions: read
+      contents: read
+
+    strategy:
+      fail-fast: false
+      matrix:
+        include:
+          - language: actions
+            build-mode: none
+          - language: go
+            build-mode: autobuild
+    # CodeQL 支持以下“language”关键字值:'actions'、'c-cpp'、'csharp'、'go'、'java-kotlin'、'javascript-typescript'、'python'、'ruby'、'swift'
+    # 使用 `c-cpp` 分析用 C、C++ 或两者编写的代码
+    # 使用 `java-kotlin` 分析用 Java、Kotlin 或两者编写的代码
+    # 使用 `javascript-typescript` 分析用 JavaScript、TypeScript 或两者编写的代码
+    # 要了解更多关于更改分析语言或自定义分析构建模式的信息,
+    # 请参阅 https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning。
+    # 如果您正在分析编译型语言,您可以修改该语言的“构建模式”来自定义代码库的分析方式,请参阅 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@v4
+
+      # 在运行 `github/codeql-action/init` 操作之前添加所有设置步骤。
+      # 这包括安装编译器或运行时(`actions/setup-node`
+      # 或其他)等步骤。这通常仅在手动构建时才需要。
+      # - name: Setup runtime (example)
+      #   uses: actions/setup-example@v1
+
+      # 初始化 CodeQL 工具以进行扫描。
+      - name: Initialize CodeQL
+        uses: github/codeql-action/init@v3
+        with:
+          languages: ${{ matrix.language }}
+          build-mode: ${{ matrix.build-mode }}
+          # 如果您希望指定自定义查询,可以在此处或在配置文件中进行。
+          # 默认情况下,此处列出的查询将覆盖配置文件中指定的任何查询。
+          # 在此处的列表前添加“+”前缀,即可使用这些查询以及配置文件中的查询。
+
+          # 有关 CodeQL 查询包的更多详细信息,请参阅: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
+          # 查询:security-extended、security-and-quality
+
+      # 如果您正在分析的某种语言的分析步骤失败,
+      # “我们无法自动构建您的代码”,请修改上面的矩阵
+      # 将该语言的构建模式设置为“手动”。然后修改此步骤
+      # 以构建您的代码。
+      # ℹ️ 使用操作系统 shell 运行的命令行程序。
+      # 📚 请参阅 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
+        # 如果您正在分析的一种或多种语言使用了“手动”构建模式,请将其替换为构建代码的命令,例如:
+        #   make bootstrap
+        #   make release
+
+      - name: Perform CodeQL Analysis
+        uses: github/codeql-action/analyze@v3
+        with:
+          category: "/language:${{matrix.language}}"