@matheusbsbs / matheus-bagliano / commits / 32c83afc2c
Fork 0

ci: github action - add check for whitespace errors

Not all developers are aware of `git diff --check` to warn about whitespace issues. Running a check when a pull request is opened or updated can save time for reviewers and the submitter. A GitHub workflow will run when a pull request is created or the contents are updated to check the patch series. A pull request provides the necessary information (number of commits) to only check the patch series. To ensure the developer is aware of any issues, a comment will be added to the pull request with the check errors. Signed-off-by: Chris. Webster <chris@webstech.net> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Chris. Webster committed Sep 22, 2020 at 07:28 UTC 32c83afc2c69aa51b82aa223f2099389f1f0be0a
1 file changed +69
.github/workflows/check-whitespace.yml new
+69
@@ -0,0 +1,69 @@
1 +name: check-whitespace
2 +
3 +# Get the repo with the commits(+1) in the series.
4 +# Process `git log --check` output to extract just the check errors.
5 +# Add a comment to the pull request with the check errors.
6 +
7 +on:
8 + pull_request:
9 + types: [opened, synchronize]
10 +
11 +jobs:
12 + check-whitespace:
13 + runs-on: ubuntu-latest
14 + steps:
15 + - name: Set commit count
16 + shell: bash
17 + run: echo "::set-env name=COMMIT_DEPTH::$((1+$COMMITS))"
18 + env:
19 + COMMITS: ${{ github.event.pull_request.commits }}
20 +
21 + - uses: actions/checkout@v2
22 + with:
23 + fetch-depth: ${{ env.COMMIT_DEPTH }}
24 +
25 + - name: git log --check
26 + id: check_out
27 + run: |
28 + log=
29 + commit=
30 + while read dash etc
31 + do
32 + case "${dash}" in
33 + "---")
34 + commit="${etc}"
35 + ;;
36 + "")
37 + ;;
38 + *)
39 + if test -n "${commit}"
40 + then
41 + log="${log}\n${commit}"
42 + echo ""
43 + echo "--- ${commit}"
44 + fi
45 + commit=
46 + log="${log}\n${dash} ${etc}"
47 + echo "${dash} ${etc}"
48 + ;;
49 + esac
50 + done <<< $(git log --check --pretty=format:"---% h% s" -${{github.event.pull_request.commits}})
51 +
52 + if test -n "${log}"
53 + then
54 + echo "::set-output name=checkout::"${log}""
55 + exit 2
56 + fi
57 +
58 + - name: Add Check Output as Comment
59 + uses: actions/github-script@v3
60 + id: add-comment
61 + with:
62 + script: |
63 + github.issues.createComment({
64 + issue_number: context.issue.number,
65 + owner: context.repo.owner,
66 + repo: context.repo.repo,
67 + body: "Whitespace errors found in workflow ${{ github.workflow }}:\n\n${{ steps.check_out.outputs.checkout }}"
68 + })
69 + if: ${{ failure() }}