codeql.yml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. steps:
  25. - name: Clone repository
  26. uses: actions/checkout@v4
  27. with:
  28. submodules: recursive
  29. fetch-depth: 0
  30. - name: Check if we should always run
  31. id: always
  32. run: |
  33. if [ "${{ github.event_name }}" = "pull_request" ]; then
  34. if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/codeql') }}" = "true" ]; then
  35. echo "run=true" >> "${GITHUB_OUTPUT}"
  36. echo '::notice::Found ci/codeql label, unconditionally running all CodeQL checks.'
  37. else
  38. echo "run=false" >> "${GITHUB_OUTPUT}"
  39. fi
  40. else
  41. echo "run=true" >> "${GITHUB_OUTPUT}"
  42. fi
  43. - name: Check for C/C++ changes
  44. id: cpp
  45. run: |
  46. if [ "${{ steps.always.outputs.run }}" = "false" ]; then
  47. if git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq '.*\.[ch](xx|\+\+)?' ; then
  48. echo "run=true" >> "${GITHUB_OUTPUT}"
  49. echo '::notice::C/C++ code has changed, need to run CodeQL.'
  50. else
  51. echo "run=false" >> "${GITHUB_OUTPUT}"
  52. fi
  53. else
  54. echo "run=true" >> "${GITHUB_OUTPUT}"
  55. fi
  56. - name: Check for python changes
  57. id: python
  58. run: |
  59. if [ "${{ steps.always.outputs.run }}" = "false" ]; then
  60. if git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq 'collectors/python.d.plugin/.*\.py' ; then
  61. echo "run=true" >> "${GITHUB_OUTPUT}"
  62. echo '::notice::Python code has changed, need to run CodeQL.'
  63. else
  64. echo "run=false" >> "${GITHUB_OUTPUT}"
  65. fi
  66. else
  67. echo "run=true" >> "${GITHUB_OUTPUT}"
  68. fi
  69. analyze-cpp:
  70. name: Analyze C/C++
  71. runs-on: ubuntu-latest
  72. needs: prepare
  73. if: needs.prepare.outputs.cpp == 'true'
  74. permissions:
  75. security-events: write
  76. steps:
  77. - name: Git clone repository
  78. uses: actions/checkout@v4
  79. with:
  80. submodules: recursive
  81. fetch-depth: 0
  82. - name: Initialize CodeQL
  83. uses: github/codeql-action/init@v3
  84. with:
  85. languages: cpp
  86. config-file: ./.github/codeql/c-cpp-config.yml
  87. - name: Prepare environment
  88. run: ./packaging/installer/install-required-packages.sh --dont-wait --non-interactive netdata
  89. - name: Build netdata
  90. run: ./netdata-installer.sh --dont-start-it --disable-telemetry --dont-wait --install-prefix /tmp/install --one-time-build
  91. - name: Run CodeQL
  92. uses: github/codeql-action/analyze@v3
  93. with:
  94. category: "/language:cpp"
  95. analyze-python:
  96. name: Analyze Python
  97. runs-on: ubuntu-latest
  98. needs: prepare
  99. if: needs.prepare.outputs.python == 'true'
  100. permissions:
  101. security-events: write
  102. steps:
  103. - name: Git clone repository
  104. uses: actions/checkout@v4
  105. with:
  106. submodules: recursive
  107. fetch-depth: 0
  108. - name: Initialize CodeQL
  109. uses: github/codeql-action/init@v3
  110. with:
  111. config-file: ./.github/codeql/python-config.yml
  112. languages: python
  113. - name: Run CodeQL
  114. uses: github/codeql-action/analyze@v3
  115. with:
  116. category: "/language:python"