review.yml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. ---
  2. # Runs various linter checks against PR with suggested changes to improve quality
  3. name: Review
  4. on:
  5. pull_request:
  6. types: [opened, reopened, labeled, synchronize]
  7. env:
  8. DISABLE_TELEMETRY: 1
  9. concurrency:
  10. group: review-${{ github.ref }}
  11. cancel-in-progress: true
  12. jobs:
  13. prep-review:
  14. name: Prepare Review Jobs
  15. runs-on: ubuntu-latest
  16. outputs:
  17. actionlint: ${{ steps.actionlint.outputs.run }}
  18. clangformat: ${{ steps.clangformat.outputs.run }}
  19. eslint: ${{ steps.eslint.outputs.run }}
  20. flake8: ${{ steps.flake8.outputs.run }}
  21. hadolint: ${{ steps.hadolint.outputs.run }}
  22. shellcheck: ${{ steps.shellcheck.outputs.run }}
  23. yamllint: ${{ steps.yamllint.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 files for actionlint
  31. id: actionlint
  32. run: |
  33. if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/actionlint') }}" = "true" ]; then
  34. echo "run=true" >> "${GITHUB_OUTPUT}"
  35. elif git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq '\.github/workflows/.*' ; then
  36. echo "run=true" >> "${GITHUB_OUTPUT}"
  37. echo 'GitHub Actions workflows have changed, need to run actionlint.'
  38. else
  39. echo "run=false" >> "${GITHUB_OUTPUT}"
  40. fi
  41. # - name: Check files for clang-format
  42. # id: clangformat
  43. # run: |
  44. # if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/clang-format') }}" = "true" ]; then
  45. # echo "run=true" >> "${GITHUB_OUTPUT}"
  46. # elif git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq '\.cpp$|\.cxx$|\.c$|\.hpp$|\.hxx$|\.h$' ; then
  47. # echo "run=true" >> "${GITHUB_OUTPUT}"
  48. # echo 'C/C++ code has changed, need to run clang-format.'
  49. # else
  50. # echo "run=false" >> "${GITHUB_OUTPUT}"
  51. # fi
  52. - name: Check files for eslint
  53. id: eslint
  54. run: |
  55. if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/eslint') }}" = "true" ]; then
  56. echo "run=true" >> "${GITHUB_OUTPUT}"
  57. elif git diff --name-only origin/${{ github.base_ref }} HEAD | grep -v "web/gui/v1" | grep -v "web/gui/v2" | grep -v "integrations/" | grep -Eq '.*\.js' ; then
  58. echo "run=true" >> "${GITHUB_OUTPUT}"
  59. echo 'JS files have changed, need to run ESLint.'
  60. else
  61. echo "run=false" >> "${GITHUB_OUTPUT}"
  62. fi
  63. - name: Check files for flake8
  64. id: flake8
  65. run: |
  66. if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/flake8') }}" = "true" ]; then
  67. echo "run=true" >> "${GITHUB_OUTPUT}"
  68. elif git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq '.*\.py' ; then
  69. echo "run=true" >> "${GITHUB_OUTPUT}"
  70. echo 'Python files have changed, need to run flake8.'
  71. else
  72. echo "run=false" >> "${GITHUB_OUTPUT}"
  73. fi
  74. - name: Check files for hadolint
  75. id: hadolint
  76. run: |
  77. if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/hadolint') }}" = "true" ]; then
  78. echo "run=true" >> "${GITHUB_OUTPUT}"
  79. elif git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq '.*Dockerfile.*' ; then
  80. echo "run=true" >> "${GITHUB_OUTPUT}"
  81. echo 'Dockerfiles have changed, need to run Hadolint.'
  82. else
  83. echo "run=false" >> "${GITHUB_OUTPUT}"
  84. fi
  85. - name: Check files for shellcheck
  86. id: shellcheck
  87. run: |
  88. if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/shellcheck') }}" = "true" ]; then
  89. echo "run=true" >> "${GITHUB_OUTPUT}"
  90. elif git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq '.*\.sh.*' ; then
  91. echo "run=true" >> "${GITHUB_OUTPUT}"
  92. echo 'Shell scripts have changed, need to run shellcheck.'
  93. else
  94. echo "run=false" >> "${GITHUB_OUTPUT}"
  95. fi
  96. - name: Check files for yamllint
  97. id: yamllint
  98. run: |
  99. if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/yamllint') }}" = "true" ]; then
  100. echo "run=true" >> "${GITHUB_OUTPUT}"
  101. elif git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq '.*\.ya?ml|python\.d/.*\.conf' ; then
  102. echo "run=true" >> "${GITHUB_OUTPUT}"
  103. echo 'YAML files have changed, need to run yamllint.'
  104. else
  105. echo "run=false" >> "${GITHUB_OUTPUT}"
  106. fi
  107. actionlint:
  108. name: actionlint
  109. needs: prep-review
  110. if: needs.prep-review.outputs.actionlint == 'true'
  111. runs-on: ubuntu-latest
  112. steps:
  113. - name: Git clone repository
  114. uses: actions/checkout@v3
  115. with:
  116. submodules: recursive
  117. fetch-depth: 0
  118. - name: Run actionlint
  119. uses: reviewdog/action-actionlint@v1
  120. with:
  121. github_token: ${{ secrets.GITHUB_TOKEN }}
  122. reporter: github-pr-check
  123. clang-format:
  124. name: clang-format
  125. needs: prep-review
  126. if: needs.prep-review.outputs.clangformat == 'true'
  127. runs-on: ubuntu-latest
  128. steps:
  129. - name: Git clone repository
  130. uses: actions/checkout@v3
  131. with:
  132. submodules: false
  133. fetch-depth: 0
  134. - name: Check for label
  135. id: label
  136. run: |
  137. if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/clang-format') }}" = "true" ]; then
  138. echo 'check-all=true' >> "${GITHUB_OUTPUT}"
  139. else
  140. echo 'check-all=false' >> "${GITHUB_OUTPUT}"
  141. fi
  142. - name: Run clang-format
  143. run: |
  144. if [ "${{ steps.label.outputs.check-all }}" == 'true' ]; then
  145. find . -regex '.*\.\(c\|cpp\|cxx\|h\|hpp\|hxx\)$' -exec clang-format -i --style=file '{}' \;
  146. else
  147. git diff --name-only origin/${{ github.base_ref }} HEAD | grep -E '\.cpp$|\.cxx$|\.c$|\.hpp$|\.hxx$|\.h$' | \
  148. xargs -n 1 -r clang-format -i --style=file
  149. fi
  150. git status --porcelain=v1 > /tmp/porcelain
  151. if [ -s /tmp/porcelain ]; then
  152. cat /tmp/porcelain
  153. exit 1
  154. fi
  155. eslint:
  156. name: eslint
  157. needs: prep-review
  158. if: needs.prep-review.outputs.eslint == 'true'
  159. runs-on: ubuntu-latest
  160. steps:
  161. - name: Git clone repository
  162. uses: actions/checkout@v3
  163. with:
  164. submodules: recursive
  165. fetch-depth: 0
  166. - name: Install eslint
  167. run: npm install eslint -D
  168. - name: Run eslint
  169. uses: reviewdog/action-eslint@v1
  170. with:
  171. github_token: ${{ secrets.GITHUB_TOKEN }}
  172. reporter: github-pr-check
  173. eslint_flags: '.'
  174. flake8:
  175. name: flake8
  176. needs: prep-review
  177. if: needs.prep-review.outputs.flake8 == 'true'
  178. runs-on: ubuntu-latest
  179. steps:
  180. - name: Git clone repository
  181. uses: actions/checkout@v3
  182. with:
  183. submodules: recursive
  184. fetch-depth: 0
  185. - name: Setup Python
  186. uses: actions/setup-python@v4
  187. with:
  188. python-version: "3.10"
  189. - name: Run flake8
  190. uses: reviewdog/action-flake8@v3
  191. with:
  192. github_token: ${{ secrets.GITHUB_TOKEN }}
  193. reporter: github-pr-check
  194. hadolint:
  195. name: hadolint
  196. needs: prep-review
  197. if: needs.prep-review.outputs.hadolint == 'true'
  198. runs-on: ubuntu-latest
  199. steps:
  200. - name: Git clone repository
  201. uses: actions/checkout@v3
  202. with:
  203. fetch-depth: 0
  204. - name: Run hadolint
  205. uses: reviewdog/action-hadolint@v1
  206. with:
  207. github_token: ${{ secrets.GITHUB_TOKEN }}
  208. reporter: github-pr-check
  209. shellcheck:
  210. name: shellcheck
  211. needs: prep-review
  212. if: needs.prep-review.outputs.shellcheck == 'true'
  213. runs-on: ubuntu-latest
  214. steps:
  215. - name: Git clone repository
  216. uses: actions/checkout@v3
  217. with:
  218. submodules: recursive
  219. fetch-depth: 0
  220. - name: Run shellcheck
  221. uses: reviewdog/action-shellcheck@v1
  222. with:
  223. github_token: ${{ secrets.GITHUB_TOKEN }}
  224. reporter: github-pr-check
  225. path: "."
  226. pattern: "*.sh*"
  227. exclude: |
  228. ./.git/*
  229. packaging/makeself/makeself.sh
  230. packaging/makeself/makeself-header.sh
  231. yamllint:
  232. name: yamllint
  233. needs: prep-review
  234. if: needs.prep-review.outputs.yamllint == 'true'
  235. runs-on: ubuntu-latest
  236. steps:
  237. - name: Git clone repository
  238. uses: actions/checkout@v3
  239. with:
  240. submodules: recursive
  241. fetch-depth: 0
  242. - name: Run yamllint
  243. uses: reviewdog/action-yamllint@v1
  244. with:
  245. github_token: ${{ secrets.GITHUB_TOKEN }}
  246. reporter: github-pr-check