Skip to content

Commit

Permalink
Improve checksum test (#3927)
Browse files Browse the repository at this point in the history
* Update shell script and GH workflow
  • Loading branch information
AntoineGautier authored Jul 8, 2024
1 parent c128f96 commit fc92ba5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,17 @@ jobs:
chmod u=rw,og=rw $ff
done
done
test-checksum:
# Skip if the commit message contains "ci skip"
if: "!contains(github.event.head_commit.message, 'ci skip')"

runs-on: ubuntu-22.04

steps:
# Checks-out repository under $GITHUB_WORKSPACE, so job can access it
- name: Checkout code
uses: actions/checkout@v3

- name: Compute the checksum and check that it matches the value from the last commit
run: ./Resources/Scripts/travis/templates/checkandrun.sh --checksum --skip --diffhead
25 changes: 14 additions & 11 deletions Buildings/Resources/Scripts/travis/templates/checkandrun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
# - If all simulations succeed: overwrite stored checksum with new value,
# otherwise do nothing.
#
# To update the checksums and run simulations locally, execute:
# ./Resources/Scripts/travis/templates/checkandrun.sh --checksum --local [--tool SIMULATOR]
# To update the checksum and skip all simulations, execute:
# ./Resources/Scripts/travis/templates/checkandrun.sh --checksum --skip
#
# To update the checksum and check that it matches the value from the last commit, execute:
# ./Resources/Scripts/travis/templates/checkandrun.sh --checksum --skip --diffhead
#
# To update the checksums and run simulations, execute:
# ./Resources/Scripts/travis/templates/checkandrun.sh --checksum [--tool SIMULATOR]
#
# To simply update the checksums locally and skip all simulations, execute:
# ./Resources/Scripts/travis/templates/checkandrun.sh --checksum --local --skip

LOCALRUN=false
DIFFHEAD=false
SKIP=false
USE_CHECKSUM=false
SIMULATOR=Dymola
Expand All @@ -33,8 +37,8 @@ CEND='\033[0m'

while [[ "$1" != "" ]]; do
case $1 in
--local )
LOCALRUN=true
--diffhead )
DIFFHEAD=true
;;
--skip )
SKIP=true
Expand Down Expand Up @@ -64,7 +68,7 @@ while [[ "$1" != "" ]]; do
echo "Invalid option: $1"
echo "Usage: checkandrun.sh --checksum [--local] [--skip] [--tool SIMULATOR] [--cover FRACTION_TEST_COVERAGE]"
echo " --checksum triggers testing based on checksum verification (only method currently available, mandatory option)."
echo " --local is for local execution (use this option to update the checksums and run simulations)."
echo " --diffhead is to check that the current checksum matches the value from the last commit."
echo " --skip disables all simulations (use this option to simply update the checksums locally)."
echo " --tool allows specifying the Modelica tool to be used, defaulting to Dymola."
echo " --cover allows specifying the fraction of test coverage, defaulting to 1."
Expand Down Expand Up @@ -111,9 +115,8 @@ for type in "${!test_script[@]}"; do
# Add checksum file to the index so that differences show up in git diff even if file was never added before.
git add --intent-to-add "./Resources/Scripts/travis/templates/$type.checksum"

# Diff/HEAD: only for remote testing.
# (Locally, it is expected that there is some diff/HEAD, and we proceed directly to the next step: diff/master.)
if [ "$LOCALRUN" = false ]; then
# Diff/HEAD
if [ "$DIFFHEAD" = true ]; then
diff_checksum="$(git diff --name-only HEAD | grep Resources/Scripts/travis/templates/$type.checksum)"
if (( $? == 0 )); then
printf "${CRED}Computed checksum does not match checksum on HEAD${CEND}: please commit updated checksum for Templates.%s.\n" $type
Expand Down

0 comments on commit fc92ba5

Please sign in to comment.