CI: add formal checks
[openwrt/openwrt.git] / .github / workflows / formal.yml
1 name: Test Formalities
2
3 on:
4 pull_request:
5
6 jobs:
7 build:
8 name: Test Formalities
9 runs-on: ubuntu-latest
10 strategy:
11 fail-fast: false
12
13 steps:
14 - uses: actions/checkout@v2
15 with:
16 ref: ${{ github.event.pull_request.head.sha }}
17 fetch-depth: 0
18
19 - name: Determine branch name
20 run: |
21 BRANCH="${GITHUB_BASE_REF#refs/heads/}"
22 echo "Building for $BRANCH"
23 echo "BRANCH=$BRANCH" >> $GITHUB_ENV
24
25 - name: Test formalities
26 run: |
27 source .github/workflows/ci_helpers.sh
28
29 RET=0
30 for commit in $(git rev-list HEAD ^origin/$BRANCH); do
31 info "=== Checking commit '$commit'"
32 if git show --format='%P' -s $commit | grep -qF ' '; then
33 err "Pull request should not include merge commits"
34 RET=1
35 fi
36
37 author="$(git show -s --format=%aN $commit)"
38 if echo $author | grep -q '\S\+\s\+\S\+'; then
39 success "Author name ($author) seems ok"
40 else
41 err "Author name ($author) need to be your real name 'firstname lastname'"
42 RET=1
43 fi
44
45 subject="$(git show -s --format=%s $commit)"
46 if echo "$subject" | grep -q -e '^[0-9A-Za-z,+/_-]\+: ' -e '^Revert '; then
47 success "Commit subject line seems ok ($subject)"
48 else
49 err "Commit subject line MUST start with '<area>: ' ($subject)"
50 RET=1
51 fi
52
53 body="$(git show -s --format=%b $commit)"
54 sob="$(git show -s --format='Signed-off-by: %aN <%aE>' $commit)"
55 if echo "$body" | grep -qF "$sob"; then
56 success "Signed-off-by match author"
57 else
58 err "Signed-off-by is missing or doesn't match author (should be '$sob')"
59 RET=1
60 fi
61
62 if echo "$body" | grep -v "Signed-off-by:"; then
63 success "A commit message exists"
64 else
65 err "Missing commit message. Please describe your changes"
66 RET=1
67 fi
68 done
69
70 exit $RET