vimdiff: make script and tests work with zsh
[alt-git.git] / .github / workflows / check-whitespace.yml
bloba241a63428bd20e0c28a61ab6de56cbb39966c42
1 name: check-whitespace
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.
8 on:
9   pull_request:
10     types: [opened, synchronize]
12 # Avoid unnecessary builds. Unlike the main CI jobs, these are not
13 # ci-configurable (but could be).
14 concurrency:
15   group: ${{ github.workflow }}-${{ github.ref }}
16   cancel-in-progress: true
18 jobs:
19   check-whitespace:
20     runs-on: ubuntu-latest
21     steps:
22     - uses: actions/checkout@v4
23       with:
24         fetch-depth: 0
26     - name: git log --check
27       id: check_out
28       run: |
29         baseSha=${{github.event.pull_request.base.sha}}
30         problems=()
31         commit=
32         commitText=
33         commitTextmd=
34         goodparent=
35         while read dash sha etc
36         do
37           case "${dash}" in
38           "---")
39             if test -z "${commit}"
40             then
41               goodparent=${sha}
42             fi
43             commit="${sha}"
44             commitText="${sha} ${etc}"
45             commitTextmd="[${sha}](https://github.com/${{ github.repository }}/commit/${sha}) ${etc}"
46             ;;
47           "")
48             ;;
49           *)
50             if test -n "${commit}"
51             then
52               problems+=("1) --- ${commitTextmd}")
53               echo ""
54               echo "--- ${commitText}"
55               commit=
56             fi
57             case "${dash}" in
58             *:[1-9]*:) # contains file and line number information
59               dashend=${dash#*:}
60               problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${{github.event.pull_request.head.ref}}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
61               ;;
62             *)
63               problems+=("\`${dash} ${sha} ${etc}\`")
64               ;;
65             esac
66             echo "${dash} ${sha} ${etc}"
67             ;;
68           esac
69         done <<< $(git log --check --pretty=format:"---% h% s" ${baseSha}..)
71         if test ${#problems[*]} -gt 0
72         then
73           if test -z "${commit}"
74           then
75             goodparent=${baseSha: 0:7}
76           fi
77           echo "🛑 Please review the Summary output for further information."
78           echo "### :x: A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
79           echo "" >>$GITHUB_STEP_SUMMARY
80           echo "Run these commands to correct the problem:" >>$GITHUB_STEP_SUMMARY
81           echo "1. \`git rebase --whitespace=fix ${goodparent}\`" >>$GITHUB_STEP_SUMMARY
82           echo "1. \`git push --force\`" >>$GITHUB_STEP_SUMMARY
83           echo " " >>$GITHUB_STEP_SUMMARY
84           echo "Errors:" >>$GITHUB_STEP_SUMMARY
85           for i in "${problems[@]}"
86           do
87             echo "${i}" >>$GITHUB_STEP_SUMMARY
88           done
90           exit 2
91         fi