Skip to content

Commit c37d792

Browse files
committed
Add a CI workflow that checks commiter/author emails against the AUTHORS file.
1 parent 8509533 commit c37d792

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright (c) 2022, 219 Design, LLC
3+
# See LICENSE.txt
4+
#
5+
# https://www.219design.com
6+
# Software | Electrical | Mechanical | Product Design
7+
#
8+
name: verify_authors
9+
10+
on: [push]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-20.04
15+
16+
steps:
17+
- uses: actions/checkout@v1
18+
19+
# Remove apt repos that are known to break from time to time
20+
# See https://github.com/actions/virtual-environments/issues/323
21+
- name: Remove broken apt repos
22+
run: |
23+
for apt_file in `grep -lr microsoft /etc/apt/sources.list.d/`; do sudo rm $apt_file; done
24+
25+
- if: runner.os == 'Linux'
26+
# Fix (another kind) of azure ubuntu apt repo issue. (Unable to connect to azure.archive.ubuntu.com)
27+
run: sed -e 's/azure.archive.ubuntu.com/us.archive.ubuntu.com/g' -e t -e d /etc/apt/sources.list | sudo tee /etc/apt/sources.list.d/nonazure.list
28+
29+
- name: verify_authors
30+
run: ./verify_authors.sh

AUTHORS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# New contributors must add their name and email for this git repository
2+
# following the format reported by `git shortlog -sen | cut -f 2`.
3+
4+
Sean Moore <sean@219design.com>
5+

verify_authors.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright (c) 2022, 219 Design, LLC
5+
# See LICENSE.txt
6+
#
7+
# https://www.219design.com
8+
# Software | Electrical | Mechanical | Product Design
9+
#
10+
11+
set -euo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
12+
IFS=$'\n\t'
13+
14+
function error() {
15+
echo $@ >& /dev/stderr
16+
}
17+
18+
function missing_primary_branch() {
19+
error "Did you use the wrong branch?"
20+
git branch -a
21+
}
22+
23+
PRIMARY_BRANCH=origin/master
24+
echo "Primary branch is ${PRIMARY_BRANCH}."
25+
26+
trap missing_primary_branch EXIT
27+
ancestor_commit=$(git merge-base ${PRIMARY_BRANCH} HEAD)
28+
trap "" EXIT
29+
echo "The most recent common ancestor commit with the primary branch is ${ancestor_commit}."
30+
31+
authors=$(cat AUTHORS)
32+
git_authors=$(git shortlog -se ${ancestor_commit}..HEAD | cut -f 2)
33+
git_committers=$(git shortlog -se --committer ${ancestor_commit}..HEAD | cut -f 2)
34+
35+
echo
36+
echo "AUTHORS file lines:"
37+
for author in $authors
38+
do
39+
echo $author
40+
done
41+
42+
echo
43+
echo "git Authors:"
44+
for git_author in $git_authors
45+
do
46+
echo $git_author
47+
done
48+
49+
echo
50+
echo "git Committers:"
51+
for git_committer in $git_committers
52+
do
53+
echo $git_committer
54+
done
55+
56+
echo
57+
58+
echo "Checking git Authors."
59+
for git_author in $git_authors
60+
do
61+
found=0
62+
for author in $authors
63+
do
64+
if [ "$git_author" == "$author" ]
65+
then
66+
found=1
67+
fi
68+
done
69+
70+
if [ 0 -eq $found ]
71+
then
72+
error "Failed to find git author \"${git_author}\" in AUTHORS file."
73+
error "Note that \`git commit --amend\` is not sufficient to change a commit author."
74+
exit -1
75+
fi
76+
done
77+
echo "Verified git Authors."
78+
79+
echo "Checking git Committers."
80+
for git_committer in $git_committers
81+
do
82+
found=0
83+
for author in $authors
84+
do
85+
if [ "$git_committer" == "$author" ]
86+
then
87+
found=1
88+
fi
89+
done
90+
91+
if [ 0 -eq $found ]
92+
then
93+
error "Failed to find git committer \"${git_committer}\" in AUTHORS file."
94+
error "Note that you can't see the committer with \`git log\` but can with \`git log --pretty=full\`."
95+
exit -1
96+
fi
97+
done
98+
echo "Verified git Committers."
99+
100+
echo "Contributions verified."

0 commit comments

Comments
 (0)