Skip to content

Commit

Permalink
Merge pull request #7 from OpenWaterAnalytics/dev
Browse files Browse the repository at this point in the history
Initial release for ci-tools
  • Loading branch information
michaeltryby authored Dec 16, 2020
2 parents 36f8777 + 6a636ba commit a3d6d55
Show file tree
Hide file tree
Showing 21 changed files with 1,395 additions and 2 deletions.
4 changes: 4 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Authors ordered by first contribution

Michael Tryby <[email protected]> (public domain)
Caleb Buahin <[email protected]>
20 changes: 19 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
Creative Commons Legal Code



Copyright Notice

This project contains material prepared by the United States Government for
which domestic copyright protection is not available under 17 USC § 105.


No Copyright Restrictions 2020 U.S. Federal Government



License Notice

This project is distributed under the Creative Commons Zero (CC0) Universal
version 1.0 (see below).



CC0 1.0 Universal

Expand Down
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@

<!---
README.md
Created: May 3, 2020
Updated:
Author: See AUTHORS
--->

# ci-tools
Tools for continuous integration and local testing
Tools for continuous integration and local testing for SWMM and EPANET


### Dependencies

Before the project can be built and tested the required dependencies must be installed.

**Summary of Build Dependencies: Windows**

- Build
- Build Tools for Visual Studio 2017
- CMake 3.17

- Regression Test
- Python 3.7 64 bit
- curl
- git
- 7z

Once Python is present, the following command installs the required packages for regression testing.
```
\> cd < PROJECT_ROOT >
\>pip install -r tools\requirements-< PROJECT >.txt
```


### Build

EPANET can be built with one simple command.
```
\>tools\make.cmd
```


### Regression Test

This command runs regression tests for the local build and compares them to the latest benchmark.
```
\>tools\before-nrtest.cmd
\>tools\run-nrtest.cmd
```
63 changes: 63 additions & 0 deletions darwin/app-config.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env zsh

#
# app-config.sh - Generates nrtest app configuration file for test executable
#
# Date Created: 11/15/2017
# Updated: 08/21/2020
#
# Author: See AUTHORS
#
# Requires:
# git
#
# Environment Variables:
# PROJECT
#
# Arguments:
# 1 - absolute path to test executable
# 2 - Platform
# 3 - (SUT build id)
#

# Check requirements
where git &> /dev/null
[[ ! $? ]] && { echo "ERROR: git not installed"; return 1 }

# check that env variables are set
[[ ! -v PROJECT ]] && { echo "ERROR: PROJECT must be defined"; return 1 }


# check if project is swmm otherwise EPANET
TEST_CMD="run${PROJECT}"

# path to executable in cmake build tree
ABS_BUILD_PATH=$1

# process optional arguments
if [ ! -z "$2" ]; then
PLATFORM=$2
else
PLATFORM="unknown"
fi

if [ ! -z "$3" ]; then
BUILD_ID=$3
else
BUILD_ID="unknown"
fi


# determine version
VERSION=$( git rev-parse --short HEAD )
[[ ! -v VERSION ]] && { echo "ERROR: VERSION must be determined"; return 1 }

cat<<EOF
{
"name" : "${PROJECT}",
"version" : "${VERSION}",
"description" : "${PLATFORM} ${BUILD_ID}",
"setup_script" : "",
"exe" : "${ABS_BUILD_PATH}/${TEST_CMD}"
}
EOF
120 changes: 120 additions & 0 deletions darwin/before-nrtest.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/usr/bin/env zsh
#
# before-nrtest.sh - Runs before numerical regression test
#
# Date Created: 11/15/2017
# Updated: 08/21/2020
#
# Author: See AUTHORS
#
# Dependencies:
# curl
# tar
#
# Environment Variables:
# PROJECT
# BUILD_HOME - relative path
# PLATFORM
# NRTESTS_URL
#
# Arguments:
# 1 - (RELEASE_TAG) - Release tag
#
# Note:
# Tests and benchmark files are stored in the swmm-example-networks repo.
# This script retreives them using a stable URL associated with a release on
# GitHub and stages the files for nrtest to run. The script assumes that
# before-test.sh and app-config.sh are located together in the same folder.
#

export TEST_HOME="nrtests"

# check that env variables are set
REQUIRED_VARS=(PROJECT BUILD_HOME PLATFORM)
for i in ${REQUIRED_VARS}; do
[[ ! -v ${i} ]] && { echo "ERROR: $i must be defined"; return 1 }
done

# determine project directory
CUR_DIR=${PWD}
SCRIPT_HOME=${0:a:h}
cd ${SCRIPT_HOME}
cd ./../../
PROJECT_DIR=${PWD}

# set URL to github repo with nrtest files
if [[ -z "${NRTESTS_URL}" ]]
then
NRTESTS_URL="https://github.com/OpenWaterAnalytics/${PROJECT}-nrtestsuite"
fi

echo INFO: Staging files for regression testing

# use release tag arg else determine latest hard coded for now.
if [[ ! -z "$1" ]]
then
RELEASE_TAG=$1
else
LATEST_URL="${NRTESTS_URL}/releases/latest"
RELEASE_TAG=$( basename $( curl -Ls -o /dev/null -w %{url_effective} ${LATEST_URL} ) )
echo INFO: Latest nrtestsuite release: ${RELEASE_TAG}
fi


# build URLs for test and benchmark files
if [[ ! -v RELEASE_TAG ]]
then
echo "ERROR: tag RELEASE_TAG is invalid" ; return 1
else
TESTFILES_URL="${NRTESTS_URL}/archive/${RELEASE_TAG}.tar.gz"
BENCHFILES_URL="${NRTESTS_URL}/releases/download/${RELEASE_TAG}/benchmark-${PLATFORM}.tar.gz"
fi

echo INFO: Staging files for regression testing

# create a clean directory for staging regression tests
if [[ -d ${TEST_HOME} ]]; then
rm -rf ${TEST_HOME}
fi

mkdir ${TEST_HOME}
cd ${TEST_HOME}

# retrieve tests and benchmarks for regression testing
curl -fsSL -o nrtestfiles.tar.gz ${TESTFILES_URL}
# retrieve swmm benchmark results
curl -fsSL -o benchmarks.tar.gz ${BENCHFILES_URL}

# extract tests and setup symlink
tar xzf nrtestfiles.tar.gz
ln -s ${PROJECT}-nrtestsuite-${RELEASE_TAG:1}/public tests


# create benchmark dir and extract benchmarks
mkdir benchmark
tar xzf benchmarks.tar.gz -C benchmark


#determine ref_build_id
MANIFEST_FILE=$( find . -name manifest.json )

while read line; do
if [[ $line == *"${PLATFORM} "* ]]; then
REF_BUILD_ID=${line#*"${PLATFORM} "}
REF_BUILD_ID=${REF_BUILD_ID//"\","/""}
fi
done < $MANIFEST_FILE


if [[ -z "${REF_BUILD_ID}" ]]
then
echo "ERROR: REF_BUILD_ID could not be determined" ; exit 1
fi

export REF_BUILD_ID=$REF_BUILD_ID

# GitHub Actions
echo "REF_BUILD_ID=$REF_BUILD_ID" >> $GITHUB_ENV

# return user to current dir
cd ${CUR_DIR}
104 changes: 104 additions & 0 deletions darwin/make.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env zsh
#
#
# make.sh - Builds swmm/epanet executable
#
# Date Created: 06/29/2020
# Updated: 08/21/2020
#
# Authors: See AUTHORS
#
# Environment Variables:
# PROJECT
#
# Optional Arguments:
# -g ("GENERATOR") defaults to "Ninja"
# -t builds and runs unit tests (requires Boost)


setopt extendedglob

export BUILD_HOME="build"

# determine project directory
CUR_DIR=${PWD}
SCRIPT_HOME=${0:a:h}
cd ${SCRIPT_HOME}
cd ./../../
PROJECT_DIR=${PWD}


# determine project
if [[ ! -v PROJECT ]]
then
[[ $( basename $PROJECT_DIR ) = ((#i)'STO'*|(#i)'SWM'*) ]] && { export PROJECT="swmm" }
[[ $( basename $PROJECT_DIR ) = ((#i)'WAT'*|(#i)'EPA'*) ]] && { export PROJECT="epanet" }
fi
# check that PROJECT is defined
[[ ! -v PROJECT ]] && { echo "ERROR: PROJECT must be defined"; return 1 }
# prepare for artifact upload
if [ ! -d upload ]; then
mkdir upload
fi
echo INFO: Building ${PROJECT} ...
GENERATOR="Xcode"
TESTING=0
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-g|--gen)
GENERATOR="$2"
shift # past argument
shift # past value
;;
-t|--test)
TESTING=1
shift # past argument
;;
*) # unknown option
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
# perform the build
cmake -E make_directory ${BUILD_HOME}
RESULT=$?
if [ ${TESTING} -eq 1 ];
then
echo "Building debug"
cmake -E chdir ./${BUILD_HOME} cmake -G "${GENERATOR}" -DBUILD_TESTS=ON .. \
&& cmake --build ./${BUILD_HOME} --config Debug \
&& cmake -E chdir ./${BUILD_HOME} ctest -C Debug --output-on-failure
RESULT=$?
else
echo "Building release"
cmake -E chdir ./${BUILD_HOME} cmake -G "${GENERATOR}" -DBUILD_TESTS=OFF .. \
&& cmake --build ./${BUILD_HOME} --config Release --target package
RESULT=$?
cp ./${BUILD_HOME}/*.tar.gz ./upload >&1
fi
export PLATFORM="darwin"
#GitHub Actions
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV
# return user to current dir
cd ${CUR_DIR}
return $RESULT
Empty file added darwin/requirements-epanet.txt
Empty file.
21 changes: 21 additions & 0 deletions darwin/requirements-swmm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# requirements-win.txt - Python requirements for running nrtest on Win32/Win64
#
# Date Created: 10/17/2019
# Date Updated: 11/26/2019
#
# Author: See AUTHORS
#
# Useful for configuring a python environment to run nrtests on swmm.
#
# usage:
# pip install -r tools/requirements-win.txt
#

nrtest

-f https://github.com/SWMM-Project/swmm-python/releases/download/v0.6.0-rc.1/swmm_toolkit-0.5.0-cp37-cp37m-macosx_10_10_x86_64.whl
swmm-toolkit

-f https://github.com/SWMM-Project/swmm-python/releases/download/v0.6.0-rc.1/nrtest_swmm-0.6.0-py3-none-any.whl
nrtest-swmm
Loading

0 comments on commit a3d6d55

Please sign in to comment.