Set n:o digits in abbrev. hash in script that checks commit log.

Expliclyt set n:o digits in abbrev. hash in script that checks the
commit log to make script behave the same way on different platforms.

Also improve help text.
This commit is contained in:
Christian Ridderström 2017-08-20 18:34:25 +02:00
parent 854d7e1619
commit 4c4db93645

View File

@ -3,36 +3,44 @@
# #
CMD=$1 CMD=$1
SINCE_DATE=2015-01-01 SINCE_DATE=2015-01-01
# Set format of output as follows:
# abbrev-hash author-date(ISO8601-like) author-name author-email
FORMAT='%h %ai name=%an email=%ae' FORMAT='%h %ai name=%an email=%ae'
# For portability/robustness, explicitly set n:o digits in commit hash (%h)
HASH_ABBREV=10
SCRIPT=$0 SCRIPT=$0
function show_help() { function show_help() {
cat <<EOF cat <<EOF
SCRIPT=$SCRIPT SCRIPT=$SCRIPT
This script filters the git log for commits whose Script to filter the git log for commits whose author's e-mail is
author's e-mail is _not_ on @lyx.org. _not_ on @lyx.org. It's intended to be used by a CI job.
This script can be used to check that the LyX developers have This script can be used to check that the LyX developers have
correctly configured their git to provide an e-mail address that's in correctly configured their git to provide an e-mail address that's in
the @lyx.org domain. This is needed for proper functioning of the the @lyx.org domain. This is needed for proper functioning of the
e-mails being automatically sent to lyx-cvs@lyx.org. e-mails being automatically sent to lyx-cvs@lyx.org.
Syntax:
<SCRIPT> { --help | -h | --list | -l | --compute-hash }
<SCRIPT> { --check-hash | -c } <EXPECTED-HASH>
Examples: Examples:
# Show this help text
<SCRIPT> -h
# List contributions from non-@lyx.org-addresses since 2015-01-01 # List contributions from non-@lyx.org-addresses since 2015-01-01
$SCRIPT --list <SCRIPT> --list
# Compute hash (SHA-512) of list of contributors # Compute hash (SHA-512) of list of contributors
$SCRIPT --compute-hash <SCRIPT> --compute-hash
# Check hash of list of contributors against expected hash. # Check hash of list of contributors against expected hash.
# This scripts exist with a non-zero error code if hash does not match. # This scripts exist with a non-zero error code if hash does not match.
$SCRIPT --check-hash \ <SCRIPT> --check-hash \
1330d9fca5e385e9de8933cbf6d391222207b2f6af1cf7ca3175babfd4e5ab46b024ff2d98c7c8630b362be506da9376f9262a524755f9acf655d83dcce8a564 1330d9fca5e385e9de8933cbf6d391222207b2f6af1cf7ca3175babfd4e5ab46b024ff2d98c7c8630b362be506da9376f9262a524755f9acf655d83dcce8a564
# Show help text
$SCRIPT -h
Background: Background:
See e-mail thread on developers@lyx.org started by Scott 2017-07-30. See e-mail thread on developers@lyx.org started by Scott 2017-07-30.
EOF EOF
@ -45,13 +53,13 @@ function fail() {
} }
function list_filtered_git_log() { function list_filtered_git_log() {
git log --since=$SINCE_DATE --format="$FORMAT" \ git log --since=$SINCE_DATE --format="$FORMAT" --abbrev=$HASH_ABBREV \
| grep -v 'lyx\.org$' | grep -v 'lyx\.org$'
} }
function compute_current_hash() { function compute_current_hash() {
FILTERED_LOG=$( list_filtered_git_log ) FILTERED_LOG=$( list_filtered_git_log )
echo "$FILTERED_LOG" | shasum -a 512 | cut -d ' ' -f 1 CURRENT_HASH=$( echo "$FILTERED_LOG" | shasum -a 512 | cut -d ' ' -f 1 )
} }
case "$CMD" in case "$CMD" in
@ -65,16 +73,17 @@ case "$CMD" in
;; ;;
"--compute-hash") "--compute-hash")
CURRENT_HASH=$( compute_current_hash ) compute_current_hash
printf "Current hash: %s\n" "$CURRENT_HASH" printf "Current hash: %s\n" "$CURRENT_HASH"
exit 0 exit 0
;; ;;
"-c"|"--check-hash") "-c"|"--check-hash")
DESIRED_HASH=$2 DESIRED_HASH=$2
CURRENT_HASH=$( compute_current_hash ) [[ "$DESIRED_HASH" == "" ]] && fail "No expected hash value was provided."
compute_current_hash
if [[ "$CURRENT_HASH" == "$DESIRED_HASH" ]]; then if [[ "$CURRENT_HASH" == "$DESIRED_HASH" ]]; then
printf "Hash matches current hash\n:" printf "Hash of filtered git log matches that of the provided expected hash\n:"
printf " Current: %s\n" "$CURRENT_HASH" printf " Current: %s\n" "$CURRENT_HASH"
exit 0; exit 0;
else else