review.yml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. flake8: ${{ steps.flake8.outputs.run }}
  20. golangci-lint: ${{ steps.golangci-lint.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@v4
  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 flake8
  53. id: flake8
  54. run: |
  55. if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/flake8') }}" = "true" ]; then
  56. echo "run=true" >> "${GITHUB_OUTPUT}"
  57. elif git diff --name-only origin/${{ github.base_ref }} HEAD | grep -Eq '.*\.py' ; then
  58. echo "run=true" >> "${GITHUB_OUTPUT}"
  59. echo 'Python files have changed, need to run flake8.'
  60. else
  61. echo "run=false" >> "${GITHUB_OUTPUT}"
  62. fi
  63. - name: Check files for golangci-lint
  64. id: golangci-lint
  65. run: |
  66. if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/golangci-lint') }}" = "true" ]; then
  67. echo "run=true" >> "${GITHUB_OUTPUT}"
  68. elif git diff --name-only origin/"${{ github.base_ref }}" HEAD -- | grep -Eq '.*\.go'; then
  69. echo "run=true" >> "${GITHUB_OUTPUT}"
  70. echo 'Go code has changed, need to run golangci-lint.'
  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@v4
  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@v4
  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. flake8:
  156. name: flake8
  157. needs: prep-review
  158. if: needs.prep-review.outputs.flake8 == 'true'
  159. runs-on: ubuntu-latest
  160. steps:
  161. - name: Git clone repository
  162. uses: actions/checkout@v4
  163. with:
  164. submodules: recursive
  165. fetch-depth: 0
  166. - name: Setup Python
  167. uses: actions/setup-python@v5
  168. with:
  169. python-version: "3.10"
  170. - name: Run flake8
  171. uses: reviewdog/action-flake8@v3
  172. with:
  173. github_token: ${{ secrets.GITHUB_TOKEN }}
  174. reporter: github-pr-check
  175. golangci-lint:
  176. name: golangci-lint
  177. needs: prep-review
  178. if: needs.prep-review.outputs.golangci-lint == 'true'
  179. strategy:
  180. matrix:
  181. tree:
  182. - src/go
  183. runs-on: ubuntu-latest
  184. steps:
  185. - name: Checkout
  186. uses: actions/checkout@v4
  187. - name: Run golangci-lint
  188. uses: reviewdog/action-golangci-lint@v2
  189. with:
  190. github_token: ${{ secrets.GITHUB_TOKEN }}
  191. reporter: github-pr-check
  192. golangci_lint_flags: '--timeout=10m'
  193. workdir: ${{ matrix.tree }}
  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@v4
  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@v4
  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. ./fluent-bit/*
  232. yamllint:
  233. name: yamllint
  234. needs: prep-review
  235. if: needs.prep-review.outputs.yamllint == 'true'
  236. runs-on: ubuntu-latest
  237. steps:
  238. - name: Git clone repository
  239. uses: actions/checkout@v4
  240. with:
  241. submodules: recursive
  242. fetch-depth: 0
  243. - name: Run yamllint
  244. uses: reviewdog/action-yamllint@v1
  245. with:
  246. github_token: ${{ secrets.GITHUB_TOKEN }}
  247. reporter: github-pr-check