]> git.ipfire.org Git - thirdparty/git.git/blob - .github/workflows/check-whitespace.yml
ci (check-whitespace): move to actions/checkout@v3
[thirdparty/git.git] / .github / workflows / check-whitespace.yml
1 name: check-whitespace
2
3 # Get the repository with all commits to ensure that we can analyze
4 # all of the commits contributed via the Pull Request.
5 # Process `git log --check` output to extract just the check errors.
6 # Exit with failure upon white-space issues.
7
8 on:
9 pull_request:
10 types: [opened, synchronize]
11
12 jobs:
13 check-whitespace:
14 runs-on: ubuntu-latest
15 steps:
16 - uses: actions/checkout@v3
17 with:
18 fetch-depth: 0
19
20 - name: git log --check
21 id: check_out
22 run: |
23 baseSha=${{github.event.pull_request.base.sha}}
24 problems=()
25 commit=
26 commitText=
27 commitTextmd=
28 goodparent=
29 while read dash sha etc
30 do
31 case "${dash}" in
32 "---")
33 if test -z "${commit}"
34 then
35 goodparent=${sha}
36 fi
37 commit="${sha}"
38 commitText="${sha} ${etc}"
39 commitTextmd="[${sha}](https://github.com/${{ github.repository }}/commit/${sha}) ${etc}"
40 ;;
41 "")
42 ;;
43 *)
44 if test -n "${commit}"
45 then
46 problems+=("1) --- ${commitTextmd}")
47 echo ""
48 echo "--- ${commitText}"
49 commit=
50 fi
51 case "${dash}" in
52 *:[1-9]*:) # contains file and line number information
53 dashend=${dash#*:}
54 problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${{github.event.pull_request.head.ref}}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
55 ;;
56 *)
57 problems+=("\`${dash} ${sha} ${etc}\`")
58 ;;
59 esac
60 echo "${dash} ${sha} ${etc}"
61 ;;
62 esac
63 done <<< $(git log --check --pretty=format:"---% h% s" ${baseSha}..)
64
65 if test ${#problems[*]} -gt 0
66 then
67 if test -z "${commit}"
68 then
69 goodparent=${baseSha: 0:7}
70 fi
71 echo "🛑 Please review the Summary output for further information."
72 echo "### :x: A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
73 echo "" >>$GITHUB_STEP_SUMMARY
74 echo "Run these commands to correct the problem:" >>$GITHUB_STEP_SUMMARY
75 echo "1. \`git rebase --whitespace=fix ${goodparent}\`" >>$GITHUB_STEP_SUMMARY
76 echo "1. \`git push --force\`" >>$GITHUB_STEP_SUMMARY
77 echo " " >>$GITHUB_STEP_SUMMARY
78 echo "Errors:" >>$GITHUB_STEP_SUMMARY
79 for i in "${problems[@]}"
80 do
81 echo "${i}" >>$GITHUB_STEP_SUMMARY
82 done
83
84 exit 2
85 fi