diff --git a/.github/check-for-changes-in-epoch-duration.sh b/.github/check-for-changes-in-epoch-duration.sh index 9f39fc16..a28d3bb5 100755 --- a/.github/check-for-changes-in-epoch-duration.sh +++ b/.github/check-for-changes-in-epoch-duration.sh @@ -1,22 +1,31 @@ #!/bin/bash -set -xeuo pipefail +set -euo pipefail # Colorful output. function greenprint { echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" } +function yellowprint { + echo -e "\033[1;33m[$(date -Isecond)] ${1}\033[0m" +} + +function redprint { + echo -e "\033[1;31m[$(date -Isecond)] ${1}\033[0m" +} + check_block_time() { # WARNING: exits on error from=$1 to=$2 - if git --no-pager diff "${from}...${to}" | grep 'MILLISECS_PER_BLOCK'; then - greenprint "FAIL: MILLISECS_PER_BLOCK has been modified! This will brick the blockchain!" + if git --no-pager diff "${from}...${to}" -- runtime/ | grep 'MILLISECS_PER_BLOCK' | grep const | grep --regexp='^[\+|\-]'; then + redprint "FAIL: modified line(s) referencing MILLISECS_PER_BLOCK found!" + redprint "FAIL: Don't change the value of this variable! This will brick the blockchain!" exit 1 else - greenprint "PASS: MILLISECS_PER_BLOCK has not been modified!" + greenprint "PASS: modified lines referencing MILLISECS_PER_BLOCK not found!" fi } @@ -25,11 +34,12 @@ check_blocks_for_faster_epoch() { from=$1 to=$2 - if git --no-pager diff "${from}...${to}" | grep 'BLOCKS_FOR_FASTER_EPOCH'; then - greenprint "FAIL: BLOCKS_FOR_FASTER_EPOCH has been modified! This will brick Devnet!" + if git --no-pager diff "${from}...${to}" -- runtime/ | grep 'BLOCKS_FOR_FASTER_EPOCH' | grep const | grep --regexp='^[\+|\-]'; then + redprint "FAIL: modified line(s) referencing BLOCKS_FOR_FASTER_EPOCH found!" + redprint "FAIL: Don't change the value of this variable! This will brick Devnet!" exit 1 else - greenprint "PASS: BLOCKS_FOR_FASTER_EPOCH has not been modified!" + greenprint "PASS: modified lines referencing BLOCKS_FOR_FASTER_EPOCH not found!" fi } @@ -38,11 +48,12 @@ check_epoch_duration() { from=$1 to=$2 - if git --no-pager diff "${from}...${to}" | grep 'EPOCH_DURATION'; then - greenprint "FAIL: EPOCH_DURATION has been modified! This will brick the blockchain!" + if git --no-pager diff "${from}...${to}" -- runtime/ | grep 'EPOCH_DURATION' | grep const | grep --regexp='^[\+|\-]'; then + redprint "FAIL: modified line(s) referencing EPOCH_DURATION found!" + redprint "FAIL: Don't change the value of this variable! This will brick the blockchain!" exit 1 else - greenprint "PASS: EPOCH_DURATION has not been modified!" + greenprint "PASS: modified lines referencing EPOCH_DURATION not found!" fi } @@ -51,11 +62,12 @@ check_slot_duration() { from=$1 to=$2 - if git --no-pager diff "${from}...${to}" | grep 'SLOT_DURATION'; then - greenprint "FAIL: SLOT_DURATION has been modified! This will brick the blockchain!" + if git --no-pager diff "${from}...${to}" -- runtime/ | grep 'SLOT_DURATION' | grep const | grep --regexp='^[\+|\-]'; then + redprint "FAIL: modified line(s) referencing SLOT_DURATION found!" + redprint "FAIL: Don't change the value of this variable! This will brick the blockchain!" exit 1 else - greenprint "PASS: SLOT_DURATION has not been modified!" + greenprint "PASS: modified lines referencing SLOT_DURATION not found!" fi } @@ -65,24 +77,24 @@ check_slot_duration() { FROM=$(git rev-parse "${1:-origin/dev}") TO=$(git rev-parse "${2:-HEAD}") -greenprint "DEBUG: Inspecting range $FROM..$TO" +yellowprint "DEBUG: Inspecting range $FROM...$TO" if [ -z "$FROM" ]; then - echo "ERROR: FROM is empty. Exiting..." + redprint "ERROR: FROM is empty. Exiting..." exit 2 fi if [ -z "$TO" ]; then - echo "ERROR: TO is empty. Exiting..." + redprint "ERROR: TO is empty. Exiting..." exit 2 fi if git --no-pager diff --name-only "${FROM}"..."${TO}" | grep -e '^runtime'; then - greenprint "INFO: runtime/ has been modified. Checking for changes in EPOCH_DURATION!" + yellowprint "INFO: runtime/ dir has been modified. Checking for critical changes!" check_block_time "${FROM}" "${TO}" check_blocks_for_faster_epoch "${FROM}" "${TO}" check_epoch_duration "${FROM}" "${TO}" check_slot_duration "${FROM}" "${TO}" else - greenprint "INFO: runtime/ has NOT been modified. Will NOT check for changes in EPOCH_DURATION!" + greenprint "INFO: runtime/ dir has NOT been modified. All good!" fi