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

  actionlint:
    name: actionlint
    needs: prep-review
    if: needs.prep-review.outputs.actionlint == 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Git clone repository
        uses: actions/checkout@v3
        with:
          submodules: recursive
          fetch-depth: 0
      - name: Run actionlint
        uses: reviewdog/action-actionlint@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          reporter: github-pr-check

  clang-format:
    name: clang-format
    needs: prep-review
    if: needs.prep-review.outputs.clangformat == 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Git clone repository
        uses: actions/checkout@v3
        with:
          submodules: false
          fetch-depth: 0
      - name: Check for label
        id: label
        run: |
          if [ "${{ contains(github.event.pull_request.labels.*.name, 'run-ci/clang-format') }}" = "true" ]; then
            echo 'check-all=true' >> "${GITHUB_OUTPUT}"
          else
            echo 'check-all=false' >> "${GITHUB_OUTPUT}"
          fi
      - name: Run clang-format
        run: |
          if [ "${{ steps.label.outputs.check-all }}" == 'true' ]; then
            find . -regex '.*\.\(c\|cpp\|cxx\|h\|hpp\|hxx\)$' -exec clang-format -i --style=file '{}' \;
          else
            git diff --name-only origin/${{ github.base_ref }} HEAD | grep -E '\.cpp$|\.cxx$|\.c$|\.hpp$|\.hxx$|\.h$' | \
            xargs -n 1 -r clang-format -i --style=file
          fi
          git status --porcelain=v1 > /tmp/porcelain
          if [ -s /tmp/porcelain ]; then
            cat /tmp/porcelain
            exit 1
          fi

  eslint:
    name: eslint
    needs: prep-review
    if: needs.prep-review.outputs.eslint == 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Git clone repository
        uses: actions/checkout@v3
        with:
          submodules: recursive
          fetch-depth: 0
      - name: Install eslint
        run: npm install eslint -D
      - name: Run eslint
        uses: reviewdog/action-eslint@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          reporter: github-pr-check
          eslint_flags: '.'

  flake8:
    name: flake8
    needs: prep-review
    if: needs.prep-review.outputs.flake8 == 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Git clone repository
        uses: actions/checkout@v3
        with:
          submodules: recursive
          fetch-depth: 0
      - name: Setup Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.10"
      - name: Run flake8
        uses: reviewdog/action-flake8@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          reporter: github-pr-check

  hadolint:
    name: hadolint
    needs: prep-review
    if: needs.prep-review.outputs.hadolint == 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Git clone repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - name: Run hadolint
        uses: reviewdog/action-hadolint@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          reporter: github-pr-check

  shellcheck:
    name: shellcheck
    needs: prep-review
    if: needs.prep-review.outputs.shellcheck == 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Git clone repository
        uses: actions/checkout@v3
        with:
          submodules: recursive
          fetch-depth: 0
      - name: Run shellcheck
        uses: reviewdog/action-shellcheck@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          reporter: github-pr-check
          path: "."
          pattern: "*.sh*"
          exclude: |
            ./.git/*
            packaging/makeself/makeself.sh
            packaging/makeself/makeself-header.sh

  yamllint:
    name: yamllint
    needs: prep-review
    if: needs.prep-review.outputs.yamllint == 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Git clone repository
        uses: actions/checkout@v3
        with:
          submodules: recursive
          fetch-depth: 0
      - name: Run yamllint
        uses: reviewdog/action-yamllint@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          reporter: github-pr-check