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