Skip to content

Commit 237e91e

Browse files
committed
Add the build.sh script
1 parent 476b3b6 commit 237e91e

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

build.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
EXERCISES_DIR=exercises
6+
SOLUTIONS_DIR=solutions
7+
STAGING_DIR=staging
8+
SCRIPT_DIR=scripts
9+
10+
function help() {
11+
echo "Usage:"
12+
echo " build.sh <command>"
13+
echo " Commands:"
14+
echo " validate - Run through each exercise, stage the exercise, then apply the solution. Verify the exercise builds in it's final state."
15+
}
16+
17+
function validate() {
18+
WORKING_DIR=$(pwd)
19+
20+
EXERCISES=($(ls $SOLUTIONS_DIR/ | grep "^[0-9]*"))
21+
22+
TMP_DIR=target/tmp
23+
rm -rf $TMP_DIR
24+
mkdir -p $TMP_DIR
25+
26+
cp -r $EXERCISES_DIR $TMP_DIR
27+
cp -r $SOLUTIONS_DIR $TMP_DIR
28+
cp -r $STAGING_DIR $TMP_DIR
29+
30+
cd $TMP_DIR/$EXERCISES_DIR
31+
32+
for EXERCISE in "${EXERCISES[@]}"
33+
do
34+
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
35+
echo $EXERCISE
36+
./exercise.sh stage $EXERCISE
37+
./exercise.sh solve $EXERCISE
38+
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
39+
40+
if [ -f "pom.xml" ]; then
41+
mvn clean test
42+
fi
43+
done
44+
45+
rm -rf $TMP_DIR
46+
47+
cd $WORKING_DIR
48+
}
49+
50+
## Determine which command is being requested, and execute it.
51+
COMMAND=${1:-"help"}
52+
if [ "$COMMAND" = "validate" ]; then
53+
validate
54+
elif [ "$COMMAND" = "help" ]; then
55+
help
56+
else
57+
echo "INVALID COMMAND: $COMMAND"
58+
help
59+
exit 1
60+
fi

0 commit comments

Comments
 (0)