607585b923191a525dd0b9c8c7cf6e409157f99f
[project/luci.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@v3
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 for merge commits, subject, S.O.B., and email
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 authorname="$(git show -s --format=%aN $commit)"
38 if echo $authorname | grep -q '\S\+\s\+\S\+'; then
39 success "Author name ($authorname) seems ok"
40 elif echo $authorname | grep -q '\S\+'; then
41 success "Author name ($authorname) seems to be nick or alias"
42 else
43 err "Author name ($authorname) must be one of: real name 'firstname lastname' OR nickname/alias/handle "
44 RET=1
45 fi
46
47 committername="$(git show -s --format=%cN $commit)"
48 # Pattern \S\+\s\+\S\+ matches >= 2 names i.e. 3 and more e.g. "John Von Doe" also match
49 if echo $committername | grep -q '\S\+\s\+\S\+'; then
50 success "Committer name ($committername) seems ok"
51 elif echo $committername | grep -q '\S\+'; then
52 # Pattern \S\+ matches single names, typical of nicks or handles
53 success "Committer name ($committername) seems to be nick or alias"
54 else
55 err "Committer name ($committername) must be one of: real name 'firstname lastname' OR nickname/alias/handle "
56 RET=1
57 fi
58
59 subject="$(git show -s --format=%s $commit)"
60 if echo "$subject" | grep -q -e '^[0-9A-Za-z,+/_-]\+: ' -e '^Revert '; then
61 success "Commit subject line seems ok ($subject)"
62 elif echo "$subject" | grep -iq '^Translated using Weblate.*'; then
63 success "Weblate commit subject line exception OK: $subject"
64 else
65 err "Commit subject line MUST start with '<package name>: ' ($subject)"
66 RET=1
67 fi
68
69 body="$(git show -s --format=%b $commit)"
70 authoremail="$(git show -s --format='<%aE>' $commit)"
71 sob="$(git show -s --format='Signed-off-by: %aN <%aE>' $commit)"
72 if echo "$body" | grep -qF "$sob"; then
73 success "Signed-off-by matches author"
74 elif echo "$authoremail" | grep -iqF "<hosted@weblate.org>"; then
75 success "Signed-off-by exception: authored by Weblate"
76 else
77 err "Signed-off-by is missing or doesn't match author (should be '$sob')"
78 RET=1
79 fi
80
81 if echo "$authoremail" | grep -iqF "users.noreply"; then
82 err "Real email address policy: please configure GitHub email ($authoremail) to a real one"
83 RET=1
84 fi
85 done
86
87 exit $RET