codeql.yml 4.8 KB

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