]> git.lyx.org Git - features.git/blob - development/CI/bin/check_git_log_for_unrecognised_email_addresses.sh
Add script for CI job to check git log for non @lyx.org-adressses
[features.git] / development / CI / bin / check_git_log_for_unrecognised_email_addresses.sh
1 #!/bin/bash
2 #
3 #
4 CMD=$1
5 SINCE_DATE=2015-01-01
6 FORMAT='%h %ai name=%an email=%ae'
7 SCRIPT=$0
8
9 function show_help() {
10     cat <<EOF
11 SCRIPT=$SCRIPT
12
13 This script filters the git log for commits whose
14 author's e-mail is _not_ on @lyx.org.
15
16 This script can be used to check that the LyX developers have
17 correctly configured their git to provide an e-mail address that's in
18 the @lyx.org domain. This is needed for proper functioning of the
19 e-mails being automatically sent to lyx-cvs@lyx.org.
20
21 Examples:
22         # List contributions from non-@lyx.org-addresses since 2015-01-01
23         $SCRIPT --list
24
25     # Compute hash (SHA-512) of list of contributors
26         $SCRIPT --compute-hash
27
28     # Check hash of list of contributors against expected hash.
29     # This scripts exist with a non-zero error code if hash does not match.
30         $SCRIPT --check-hash \
31         1330d9fca5e385e9de8933cbf6d391222207b2f6af1cf7ca3175babfd4e5ab46b024ff2d98c7c8630b362be506da9376f9262a524755f9acf655d83dcce8a564
32
33     # Show help text
34         $SCRIPT -h
35
36 Background:
37 See e-mail thread on developers@lyx.org started by Scott 2017-07-30.
38 EOF
39 }
40
41
42 function fail() {
43     printf "An error occured: %s\n" "$*"
44     exit 1
45 }
46
47 function list_filtered_git_log() {
48     git log --since=$SINCE_DATE --format="$FORMAT" \
49         | grep -v 'lyx\.org$'
50 }
51
52 function compute_current_hash() {
53     FILTERED_LOG=$( list_filtered_git_log )
54     echo "$FILTERED_LOG" | shasum -a 512 | cut -d ' ' -f 1
55 }
56
57 case "$CMD" in
58     "-h"|"--help")
59         show_help
60         exit 0
61         ;;
62
63     "-l"|"--list")
64         list_filtered_git_log
65         ;;
66
67     "--compute-hash")
68         CURRENT_HASH=$( compute_current_hash )
69         printf "Current hash: %s\n" "$CURRENT_HASH"
70         exit 0
71         ;;
72
73     "-c"|"--check-hash")
74         DESIRED_HASH=$2
75         CURRENT_HASH=$( compute_current_hash )
76         if [[ "$CURRENT_HASH" == "$DESIRED_HASH" ]]; then
77             printf "Hash matches current hash\n:"
78             printf "  Current: %s\n" "$CURRENT_HASH"
79             exit 0;
80         else
81             printf "Hash mismatch:\n"
82             printf "  Desired: %s\n" "$DESIRED_HASH"
83             printf "  Current: %s\n" "$CURRENT_HASH"
84             printf "Latest log:\n%s\n" "$FILTERED_LOG"
85             exit 1
86         fi
87         ;;
88
89     *)
90         fail "Unrecognised command(s), give '-h' for help: '$*'"
91         ;;
92 esac
93