summaryrefslogtreecommitdiffstats
path: root/.github/workflows/pre-commit.yml
blob: 87e7b66f1c15569810b6a0626c34b3d3a089d7ac (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
name: pre-commit

on:
  push:
  pull_request:

jobs:
  pre-commit:
    name: Detecting code style issues
    runs-on: ubuntu-latest
    steps:
    - name: "Check out repository"
      uses: actions/checkout@v2
      with:
        fetch-depth: 2

    - name: "Set up Python"
      uses: actions/setup-python@v2

    - name: Install clang-format
      run: sudo apt-get update && sudo apt-get install -y --no-install-recommends clang-format-10

    - name: "Detect code style issues (push)"
      uses: pre-commit/action@v2.0.0
      if: github.event_name == 'push'
      # There are too many files in the repo that have formatting issues. We'll
      # disable these checks for now when pushing directly (but still run these
      # on Pull Requests!).
      env:
        SKIP: end-of-file-fixer,trailing-whitespace,clang-format,eslint,no-commit-to-branch

    - name: "Detect code style issues (pull_request)"
      uses: pre-commit/action@v2.0.0
      if: github.event_name == 'pull_request'
      env:
        SKIP: no-commit-to-branch
      with:
        # HEAD is the not yet integrated PR merge commit +refs/pull/xxxx/merge
        # HEAD^1 is the PR target branch and HEAD^2 is the HEAD of the source branch
        extra_args: --from-ref HEAD^1 --to-ref HEAD

    - name: "Generate patch file"
      if: failure()
      run: |
        git diff-index -p HEAD > "${PATCH_FILE}"
        [ -s "${PATCH_FILE}" ] && echo "UPLOAD_PATCH_FILE=${PATCH_FILE}" >> "${GITHUB_ENV}"
      env:
        PATCH_FILE: pre-commit.patch

    - name: "Upload patch artifact"
      if: failure() && env.UPLOAD_PATCH_FILE != null
      uses: actions/upload-artifact@v2
      with:
        name: ${{ env.UPLOAD_PATCH_FILE }}
        path: ${{ env.UPLOAD_PATCH_FILE }}