git.iko.soy/typeable/pandoc
on 2.13 help sign in
typeable/pandoc/.github/workflows/commit-validation.yml
38 lines 1.5 kB history raw
1name: commit-validation
2on: [ push, pull_request ]
4jobs:
5 check-commit-msg-length:
6 runs-on: ubuntu-latest
7 steps:
8 - uses: actions/checkout@v1
9 - name: Check commit message length
10 run: |
11 # Get last commit messages
12 if [ "${{github.event_name}}" = "push" ]; then
13 if [ "${{github.event.before}}" = "0000000000000000000000000000000000000000" ]; then
14 # We are on a new branch
15 current="$(echo '${{github.ref}}' | sed 's!^refs/heads!origin!')"
16 readarray -t other < <(git show-ref | awk -F' ' '{ sub(/^refs\/remotes\//,"",$NF); }($NF != "'"$current"'"){print "^" $NF;}')
17 LOG_RANGE=( "$current" "${other[@]}" )
18 unset current other
19 else
20 # We are on existing branch
21 LOG_RANGE=( "${{github.event.before}}.." )
22 fi
23 elif [ "${{github.event_name}}" = "pull_request" ]; then
24 LOG_RANGE=( "origin/${{github.base_ref}}.." )
25 fi
26 if [[ -v LOG_RANGE ]]; then
27 if git log --no-merges --pretty=format:"%s" "${LOG_RANGE[@]}" -- | grep -qE "^[^#].{78}"; then
28 echo -e "Last commit log contains a line with more than 78 characters:\n"
29 git log --no-merges --pretty=format:"%h: %s" "${LOG_RANGE[@]}" -- | grep -E "^[^:]+: [^#].{78}"
30 echo
31 exit 1
32 else
33 echo "Commit log looks good."
34 fi
35 unset LOG_RANGE
36 else
37 echo "Not checking commits on ${{github.event_name}}"
38 fi