2
0

formal.yml 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. name: Test Formalities
  2. on:
  3. pull_request:
  4. jobs:
  5. build:
  6. name: Test Formalities
  7. runs-on: ubuntu-latest
  8. strategy:
  9. fail-fast: false
  10. steps:
  11. - uses: actions/checkout@v4
  12. with:
  13. ref: ${{ github.event.pull_request.head.sha }}
  14. fetch-depth: 0
  15. - name: Determine branch name
  16. run: |
  17. BRANCH="${GITHUB_BASE_REF#refs/heads/}"
  18. echo "Building for $BRANCH"
  19. echo "BRANCH=$BRANCH" >> $GITHUB_ENV
  20. - name: Test for merge commits, subject, S.O.B., and email
  21. run: |
  22. source .github/workflows/ci_helpers.sh
  23. RET=0
  24. for commit in $(git rev-list HEAD ^origin/$BRANCH); do
  25. info "=== Checking commit '$commit'"
  26. if git show --format='%P' -s $commit | grep -qF ' '; then
  27. err "Pull request should not include merge commits"
  28. RET=1
  29. fi
  30. authorname="$(git show -s --format=%aN $commit)"
  31. if echo $authorname | grep -q '\S\+\s\+\S\+'; then
  32. success "Author name ($authorname) seems ok"
  33. elif echo $authorname | grep -q '\S\+'; then
  34. success "Author name ($authorname) seems to be nick or alias"
  35. else
  36. err "Author name ($authorname) must be one of: real name 'firstname lastname' OR nickname/alias/handle "
  37. RET=1
  38. fi
  39. committername="$(git show -s --format=%cN $commit)"
  40. # Pattern \S\+\s\+\S\+ matches >= 2 names i.e. 3 and more e.g. "John Von Doe" also match
  41. if echo $committername | grep -q '\S\+\s\+\S\+'; then
  42. success "Committer name ($committername) seems ok"
  43. elif echo $committername | grep -q '\S\+'; then
  44. # Pattern \S\+ matches single names, typical of nicks or handles
  45. success "Committer name ($committername) seems to be nick or alias"
  46. else
  47. err "Committer name ($committername) must be one of: real name 'firstname lastname' OR nickname/alias/handle "
  48. RET=1
  49. fi
  50. subject="$(git show -s --format=%s $commit)"
  51. if echo "$subject" | grep -q -e '^[0-9A-Za-z,+/_-]\+: ' -e '^Revert '; then
  52. success "Commit subject line seems ok ($subject)"
  53. elif echo "$subject" | grep -iq '^Translated using Weblate.*'; then
  54. success "Weblate commit subject line exception OK: $subject"
  55. elif echo "$subject" | grep -iq '^Added translation using Weblate.*'; then
  56. success "Weblate commit subject line exception OK: $subject"
  57. else
  58. err "Commit subject line MUST start with '<package name>: ' ($subject)"
  59. RET=1
  60. fi
  61. body="$(git show -s --format=%b $commit)"
  62. authoremail="$(git show -s --format='<%aE>' $commit)"
  63. sob="$(git show -s --format='Signed-off-by: %aN <%aE>' $commit)"
  64. if echo "$body" | grep -qF "$sob"; then
  65. success "Signed-off-by matches author"
  66. elif echo "$authoremail" | grep -iqF "<hosted@weblate.org>"; then
  67. success "Signed-off-by exception: authored by Weblate"
  68. else
  69. err "Signed-off-by is missing or doesn't match author (should be '$sob')"
  70. RET=1
  71. fi
  72. if echo "$authoremail" | grep -iqF "users.noreply"; then
  73. err "Real email address policy: please configure GitHub email ($authoremail) to a real one"
  74. RET=1
  75. fi
  76. done
  77. exit $RET