Skip to content

Commit 013d72d

Browse files
authored
CI check to verify required exercises files exist. (#458)
* Bash script to check for required exercise files Checks to see that all exercises have both a `description.md` and a `metadata.yml` file. Note this only checks for existence and does not validate the contents in any way. If there are required files missing the return value will be 1 and the CI check will fail. If --progress command line option is provided, progress will be displayed by outputing a `.` to STDOUT for each directory checked and a completion message will also be displayed.
1 parent 0146e53 commit 013d72d

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ addons:
99

1010
script:
1111
- bin/jsonlint
12+
- bin/check_required_files_present

bin/check_required_files_present

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
MISSING_FILES=0
3+
SHOW_PROGRESS='false'
4+
5+
if [ ! -d exercises ] ; then
6+
echo "\"exercises\" directory not found, make sure you're running from the repository root" >&2
7+
exit 1
8+
fi
9+
10+
function show_progress {
11+
if [ $SHOW_PROGRESS == 'true' ]; then
12+
echo -n '.'
13+
fi
14+
}
15+
16+
function require_file {
17+
filename=$1
18+
if [ ! -f $filename ]; then
19+
echo "required file missing: $filename" >&2
20+
let "MISSING_FILES+=1"
21+
fi
22+
}
23+
24+
function check_directory {
25+
directory=$1
26+
for exercise_directory in $directory/* ; do
27+
show_progress
28+
require_file "$exercise_directory/description.md"
29+
require_file "$exercise_directory/metadata.yml"
30+
done
31+
32+
}
33+
34+
while :
35+
do
36+
case "$1" in
37+
-p | --progress)
38+
SHOW_PROGRESS="true"
39+
shift 1
40+
;;
41+
*)
42+
check_directory 'exercises'
43+
if [ $SHOW_PROGRESS == 'true' ]; then
44+
echo
45+
echo Done: $MISSING_FILES files missing.
46+
fi
47+
if (( $MISSING_FILES > 0 )); then
48+
exit 1
49+
else
50+
exit 0
51+
fi
52+
;;
53+
esac
54+
done
55+

0 commit comments

Comments
 (0)