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