| 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@v6 |
| 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 | |
| 108 | actionlint: |
| 109 | name: actionlint |
| 110 | needs: prep-review |
| 111 | if: needs.prep-review.outputs.actionlint == 'true' |
| 112 | runs-on: ubuntu-latest |
| 113 | steps: |
| 114 | - name: Git clone repository |
| 115 | uses: actions/checkout@v6 |
| 116 | with: |
| 117 | submodules: recursive |
| 118 | fetch-depth: 0 |
| 119 | - name: Run actionlint |
| 120 | uses: reviewdog/action-actionlint@v1 |
| 121 | with: |
| 122 | github_token: ${{ secrets.GITHUB_TOKEN }} |
| 123 | reporter: github-pr-check |
| 124 | |
| 125 | # clang-format: |
| 126 | # name: clang-format |
| 127 | # needs: prep-review |
| 128 | # if: needs.prep-review.outputs.clangformat == 'true' |
| 129 | # runs-on: ubuntu-latest |
| 130 | # steps: |
| 131 | # - name: Git clone repository |
| 132 | # uses: actions/checkout@v6 |
| 133 | # with: |
| 134 | # submodules: false |
| 135 | # fetch-depth: 0 |
| 136 | # - name: Check for label |
| 137 | # id: label |
| 138 | # run: | |
| 139 | # if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/clang-format') }}" = "true" ]; then |
| 140 | # echo 'check-all=true' >> "${GITHUB_OUTPUT}" |
| 141 | # else |
| 142 | # echo 'check-all=false' >> "${GITHUB_OUTPUT}" |
| 143 | # fi |
| 144 | # - name: Run clang-format |
| 145 | # run: | |
| 146 | # if [ "${{ steps.label.outputs.check-all }}" == 'true' ]; then |
| 147 | # find . -regex '.*\.\(c\|cpp\|cxx\|h\|hpp\|hxx\)$' -exec clang-format -i --style=file '{}' \; |
| 148 | # else |
| 149 | # git diff --name-only origin/${{ github.base_ref }} HEAD | grep -E '\.cpp$|\.cxx$|\.c$|\.hpp$|\.hxx$|\.h$' | \ |
| 150 | # xargs -n 1 -r clang-format -i --style=file |
| 151 | # fi |
| 152 | # git status --porcelain=v1 > /tmp/porcelain |
| 153 | # if [ -s /tmp/porcelain ]; then |
| 154 | # cat /tmp/porcelain |
| 155 | # exit 1 |
| 156 | # fi |
| 157 | |
| 158 | flake8: |
| 159 | name: flake8 |
| 160 | needs: prep-review |
| 161 | if: needs.prep-review.outputs.flake8 == 'true' |
| 162 | runs-on: ubuntu-latest |
| 163 | steps: |
| 164 | - name: Git clone repository |
| 165 | uses: actions/checkout@v6 |
| 166 | with: |
| 167 | submodules: recursive |
| 168 | fetch-depth: 0 |
| 169 | - name: Setup Python |
| 170 | uses: actions/setup-python@v6 |
| 171 | with: |
| 172 | python-version: "3.10" |
| 173 | - name: Run flake8 |
| 174 | uses: reviewdog/action-flake8@v3 |
| 175 | with: |
| 176 | github_token: ${{ secrets.GITHUB_TOKEN }} |
| 177 | reporter: github-pr-check |
| 178 | |
| 179 | golangci-lint: |
| 180 | name: golangci-lint |
| 181 | needs: prep-review |
| 182 | if: needs.prep-review.outputs.golangci-lint == 'true' |
| 183 | strategy: |
| 184 | matrix: |
| 185 | tree: |
| 186 | - src/go |
| 187 | runs-on: ubuntu-latest |
| 188 | steps: |
| 189 | - name: Checkout |
| 190 | uses: actions/checkout@v6 |
| 191 | - name: Run golangci-lint |
| 192 | uses: reviewdog/action-golangci-lint@v2 |
| 193 | with: |
| 194 | github_token: ${{ secrets.GITHUB_TOKEN }} |
| 195 | reporter: github-pr-check |
| 196 | golangci_lint_flags: '--timeout=10m' |
| 197 | workdir: ${{ matrix.tree }} |
| 198 | |
| 199 | hadolint: |
| 200 | name: hadolint |
| 201 | needs: prep-review |
| 202 | if: needs.prep-review.outputs.hadolint == 'true' |
| 203 | runs-on: ubuntu-latest |
| 204 | steps: |
| 205 | - name: Git clone repository |
| 206 | uses: actions/checkout@v6 |
| 207 | with: |
| 208 | fetch-depth: 0 |
| 209 | - name: Run hadolint |
| 210 | uses: reviewdog/action-hadolint@v1 |
| 211 | with: |
| 212 | github_token: ${{ secrets.GITHUB_TOKEN }} |
| 213 | reporter: github-pr-check |
| 214 | |
| 215 | shellcheck: |
| 216 | name: shellcheck |
| 217 | needs: prep-review |
| 218 | if: needs.prep-review.outputs.shellcheck == 'true' |
| 219 | runs-on: ubuntu-latest |
| 220 | steps: |
| 221 | - name: Git clone repository |
| 222 | uses: actions/checkout@v6 |
| 223 | with: |
| 224 | submodules: recursive |
| 225 | fetch-depth: 0 |
| 226 | - name: Run shellcheck |
| 227 | uses: reviewdog/action-shellcheck@v1 |
| 228 | with: |
| 229 | github_token: ${{ secrets.GITHUB_TOKEN }} |
| 230 | reporter: github-pr-check |
| 231 | path: "." |
| 232 | pattern: "*.sh*" |
| 233 | exclude: | |
| 234 | ./.git/* |
| 235 | packaging/makeself/makeself.sh |
| 236 | packaging/makeself/makeself-header.sh |
| 237 | ./fluent-bit/* |
| 238 | |
| 239 | yamllint: |
| 240 | name: yamllint |
| 241 | needs: prep-review |
| 242 | if: needs.prep-review.outputs.yamllint == 'true' |
| 243 | runs-on: ubuntu-latest |
| 244 | steps: |
| 245 | - name: Git clone repository |
| 246 | uses: actions/checkout@v6 |
| 247 | with: |
| 248 | submodules: recursive |
| 249 | fetch-depth: 0 |
| 250 | - name: Run yamllint |
| 251 | uses: reviewdog/action-yamllint@v1 |
| 252 | with: |
| 253 | github_token: ${{ secrets.GITHUB_TOKEN }} |
| 254 | reporter: github-pr-check |