codeql.yml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. ---
  2. # Run CodeQL to analyze C/C++ and Python code.
  3. name: CodeQL
  4. on:
  5. pull_request:
  6. types: [opened, reopened, labeled, synchronize]
  7. branches: [master]
  8. push:
  9. branches: [master]
  10. schedule:
  11. - cron: "27 2 * * 1"
  12. env:
  13. DISABLE_TELEMETRY: 1
  14. concurrency:
  15. group: codeql-${{ github.ref }}
  16. cancel-in-progress: true
  17. jobs:
  18. prepare:
  19. name: Prepare Jobs
  20. runs-on: ubuntu-latest
  21. outputs:
  22. cpp: ${{ steps.cpp.outputs.run }}
  23. python: ${{ steps.python.outputs.run }}
  24. go: ${{ steps.go.outputs.run }}
  25. steps:
  26. - name: Clone repository
  27. uses: actions/checkout@v4
  28. with:
  29. submodules: recursive
  30. fetch-depth: 0
  31. - name: Check if we should always run
  32. id: always
  33. run: |
  34. if [ "${{ github.event_name }}" = "pull_request" ]; then
  35. if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/codeql') }}" = "true" ]; then
  36. echo "run=true" >> "${GITHUB_OUTPUT}"
  37. echo '::notice::Found ci/codeql label, unconditionally running all CodeQL checks.'
  38. else
  39. echo "run=false" >> "${GITHUB_OUTPUT}"
  40. fi
  41. else
  42. echo "run=true" >> "${GITHUB_OUTPUT}"
  43. fi
  44. - name: Check for C/C++ changes
  45. id: cpp
  46. run: |
  47. if [ "${{ steps.always.outputs.run }}" = "false" ]; then
  48. if git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq '.*\.[ch](xx|\+\+)?' ; then
  49. echo "run=true" >> "${GITHUB_OUTPUT}"
  50. echo '::notice::C/C++ code has changed, need to run CodeQL.'
  51. else
  52. echo "run=false" >> "${GITHUB_OUTPUT}"
  53. fi
  54. else
  55. echo "run=true" >> "${GITHUB_OUTPUT}"
  56. fi
  57. - name: Check for python changes
  58. id: python
  59. run: |
  60. if [ "${{ steps.always.outputs.run }}" = "false" ]; then
  61. if git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq 'src/collectors/python.d.plugin/.*\.py' ; then
  62. echo "run=true" >> "${GITHUB_OUTPUT}"
  63. echo '::notice::Python code has changed, need to run CodeQL.'
  64. else
  65. echo "run=false" >> "${GITHUB_OUTPUT}"
  66. fi
  67. else
  68. echo "run=true" >> "${GITHUB_OUTPUT}"
  69. fi
  70. - name: Check for Go changes
  71. id: go
  72. run: |
  73. if [ "${{ steps.always.outputs.run }}" = "false" ]; then
  74. if git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq 'src/go/*\.go' ; then
  75. echo "run=true" >> "${GITHUB_OUTPUT}"
  76. echo '::notice::Go code has changed, need to run CodeQL.'
  77. else
  78. echo "run=false" >> "${GITHUB_OUTPUT}"
  79. fi
  80. else
  81. echo "run=true" >> "${GITHUB_OUTPUT}"
  82. fi
  83. analyze-cpp:
  84. name: Analyze C/C++
  85. runs-on: ubuntu-latest
  86. needs: prepare
  87. if: needs.prepare.outputs.cpp == 'true'
  88. permissions:
  89. security-events: write
  90. steps:
  91. - name: Git clone repository
  92. uses: actions/checkout@v4
  93. with:
  94. submodules: recursive
  95. fetch-depth: 0
  96. - name: Initialize CodeQL
  97. uses: github/codeql-action/init@v3
  98. with:
  99. languages: cpp
  100. config-file: ./.github/codeql/c-cpp-config.yml
  101. - name: Prepare environment
  102. run: ./packaging/installer/install-required-packages.sh --dont-wait --non-interactive netdata
  103. - name: Build netdata
  104. run: ./netdata-installer.sh --dont-start-it --disable-telemetry --dont-wait --install-prefix /tmp/install --one-time-build
  105. - name: Run CodeQL
  106. uses: github/codeql-action/analyze@v3
  107. with:
  108. category: "/language:cpp"
  109. analyze-python:
  110. name: Analyze Python
  111. runs-on: ubuntu-latest
  112. needs: prepare
  113. if: needs.prepare.outputs.python == 'true'
  114. permissions:
  115. security-events: write
  116. steps:
  117. - name: Git clone repository
  118. uses: actions/checkout@v4
  119. with:
  120. submodules: recursive
  121. fetch-depth: 0
  122. - name: Initialize CodeQL
  123. uses: github/codeql-action/init@v3
  124. with:
  125. config-file: ./.github/codeql/python-config.yml
  126. languages: python
  127. - name: Run CodeQL
  128. uses: github/codeql-action/analyze@v3
  129. with:
  130. category: "/language:python"
  131. analyze-go:
  132. name: Analyze Go
  133. runs-on: ubuntu-latest
  134. needs: prepare
  135. if: needs.prepare.outputs.go == 'true'
  136. strategy:
  137. matrix:
  138. tree:
  139. - src/go
  140. permissions:
  141. security-events: write
  142. steps:
  143. - name: Git clone repository
  144. uses: actions/checkout@v4
  145. with:
  146. submodules: recursive
  147. fetch-depth: 0
  148. - name: Initialize CodeQL
  149. uses: github/codeql-action/init@v3
  150. with:
  151. languages: go
  152. - name: Autobuild
  153. uses: github/codeql-action/autobuild@v3
  154. with:
  155. working-directory: ${{ matrix.tree }}
  156. - name: Run CodeQL
  157. uses: github/codeql-action/analyze@v3
  158. with:
  159. category: "/language:go"