|
| 1 | +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow |
| 2 | + |
| 3 | +name: pre-commit |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read # to fetch code (actions/checkout) |
| 10 | + |
| 11 | +jobs: |
| 12 | + pre-commit: |
| 13 | + name: Detecting code style issues |
| 14 | + runs-on: ubuntu-latest |
| 15 | + # The Dockerfile for this container can be found at: |
| 16 | + # https://github.com/Holzhaus/mixxx-ci-docker |
| 17 | + container: holzhaus/mixxx-ci:20220930@sha256:c219b780280a21566111e8bd3df7a0d495922aca96a927aa1fef12b2095fa5d8 |
| 18 | + steps: |
| 19 | + - name: "Check out repository" |
| 20 | + uses: actions/checkout@v4.1.5 |
| 21 | + with: |
| 22 | + # Unfortunately we need the whole history and can't use a shallow clone |
| 23 | + # because the Appstream Metadata hook parses the history to find the |
| 24 | + # latest changelog modification date. Otherwise, `fetch-depth: 2` would |
| 25 | + # suffice. |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: "Add GitHub workspace as a safe directory" |
| 29 | + # Without this, git commands will fail due to mismatching permissions in |
| 30 | + # the container. See actions/runner#2033 for details. |
| 31 | + # |
| 32 | + # The actions/checkout action should already take care of this thanks to |
| 33 | + # commit actions/checkout@55fd82fc42c0cdd6f1f480dd23f60636a42f6f5c, but |
| 34 | + # it seems like that's not working properly. |
| 35 | + run: | |
| 36 | + git config --global --add safe.directory "${GITHUB_WORKSPACE}" |
| 37 | + git config --global --list |
| 38 | +
|
| 39 | + - name: "Detect code style issues (push)" |
| 40 | + uses: pre-commit/action@v3.0.1 |
| 41 | + if: github.event_name == 'push' |
| 42 | + # There are too many files in the repo that have formatting issues. We'll |
| 43 | + # disable these checks for now when pushing directly (but still run these |
| 44 | + # on Pull Requests!). |
| 45 | + env: |
| 46 | + SKIP: clang-format,eslint,no-commit-to-branch |
| 47 | + |
| 48 | + - name: "Detect code style issues (pull_request)" |
| 49 | + uses: pre-commit/action@v3.0.1 |
| 50 | + if: github.event_name == 'pull_request' |
| 51 | + env: |
| 52 | + SKIP: no-commit-to-branch |
| 53 | + with: |
| 54 | + # HEAD is the not yet integrated PR merge commit +refs/pull/xxxx/merge |
| 55 | + # HEAD^1 is the PR target branch and HEAD^2 is the HEAD of the source branch |
| 56 | + extra_args: --from-ref HEAD^1 --to-ref HEAD |
| 57 | + |
| 58 | + - name: "Generate patch file" |
| 59 | + if: failure() |
| 60 | + run: | |
| 61 | + git diff-index -p HEAD > "${PATCH_FILE}" |
| 62 | + [ -s "${PATCH_FILE}" ] && echo "UPLOAD_PATCH_FILE=${PATCH_FILE}" >> "${GITHUB_ENV}" |
| 63 | + shell: bash |
| 64 | + env: |
| 65 | + PATCH_FILE: pre-commit.patch |
| 66 | + |
| 67 | + - name: "Upload patch artifact" |
| 68 | + if: failure() && env.UPLOAD_PATCH_FILE != null |
| 69 | + uses: actions/upload-artifact@v4.3.3 |
| 70 | + with: |
| 71 | + name: ${{ env.UPLOAD_PATCH_FILE }} |
| 72 | + path: ${{ env.UPLOAD_PATCH_FILE }} |
| 73 | + |
| 74 | + - name: "Upload pre-commit.log" |
| 75 | + if: failure() && env.UPLOAD_PATCH_FILE == null |
| 76 | + uses: actions/upload-artifact@v4.3.3 |
| 77 | + with: |
| 78 | + name: pre-commit.log |
| 79 | + path: /github/home/.cache/pre-commit/pre-commit.log |
0 commit comments