codeql.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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@v3
  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@v3
  79. with:
  80. submodules: recursive
  81. fetch-depth: 0
  82. - name: Initialize CodeQL
  83. uses: github/codeql-action/init@v2
  84. with:
  85. languages: cpp
  86. - name: Prepare environment
  87. run: ./packaging/installer/install-required-packages.sh --dont-wait --non-interactive netdata
  88. - name: Build netdata
  89. run: ./netdata-installer.sh --dont-start-it --disable-telemetry --dont-wait --install-prefix /tmp/install --one-time-build
  90. - name: Run CodeQL
  91. uses: github/codeql-action/analyze@v2
  92. with:
  93. category: "/language:cpp"
  94. analyze-python:
  95. name: Analyze Python
  96. runs-on: ubuntu-latest
  97. needs: prepare
  98. if: needs.prepare.outputs.python == 'true'
  99. permissions:
  100. security-events: write
  101. steps:
  102. - name: Git clone repository
  103. uses: actions/checkout@v3
  104. with:
  105. submodules: recursive
  106. fetch-depth: 0
  107. - name: Initialize CodeQL
  108. uses: github/codeql-action/init@v2
  109. with:
  110. config-file: ./.github/codeql/python-config.yml
  111. languages: python
  112. - name: Run CodeQL
  113. uses: github/codeql-action/analyze@v2
  114. with:
  115. category: "/language:python"