forked from exercism/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanonical_data_check.sh
More file actions
executable file
·111 lines (88 loc) · 2.48 KB
/
canonical_data_check.sh
File metadata and controls
executable file
·111 lines (88 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
print_usage() {
echo "Usage: ./canonical_data_check.sh -t path/to/track -s path/to/problem/specifications"
}
# Execution begins
command -v jq >/dev/null 2>&1 || {
echo >&2 "This script requires jq but it's not installed. Aborting."
exit 1
}
num_args=$#
if [ $num_args -eq 0 ]
then
print_usage
exit 0
fi
path_to_track=
path_to_problem_specifications=
while getopts ":t:s:" option
do
case "$option" in
"t")
path_to_track="$OPTARG"
;;
"s")
path_to_problem_specifications="$OPTARG"
;;
*)
echo "Unrecognized option. Aborting."
print_usage
exit 1
;;
esac
done
if [ -z "$path_to_track" ]
then
echo "Path to track missing."
print_usage
exit 1
fi
if [ -z "$path_to_problem_specifications" ]
then
echo "Path to problem specifications missing."
print_usage
exit 1
fi
config_file_path="$path_to_track/config.json"
if ! [ -f "$config_file_path" ]
then
echo "Config file not found at $config_file_path."
exit 1
fi
track_exercise_slugs=$(jq '.exercises[] | select(has("deprecated") | not) | .slug' $config_file_path | tr -d "\"" | sort)
update_needed_count=0
for slug in $track_exercise_slugs
do
canonical_data_folder_path="$path_to_problem_specifications/exercises/$slug"
if ! [ -d "$canonical_data_folder_path" ]
then
echo "Canonical data folder $canonical_data_folder_path not found. Aborting."
exit 1
fi
canonical_data_file_path="$canonical_data_folder_path/canonical-data.json"
if ! [ -f "$canonical_data_file_path" ]
then
continue
fi
canonical_data_version=$(jq '.version' $canonical_data_file_path | tr -d "\"")
track_exercise_version_file_path="$path_to_track/exercises/$slug/.meta/version"
if ! [ -f "$track_exercise_version_file_path" ]
then
echo "$slug: needs update or version file (v$canonical_data_version)."
update_needed_count=$((update_needed_count + 1))
continue
fi
track_data_version=$(cat $track_exercise_version_file_path | sed 's/\r$//')
if [ "$track_data_version" = "$canonical_data_version" ]
then
# echo "$slug: up-to-date."
continue
else
update_needed_count=$((update_needed_count + 1))
echo "$slug: needs update (v$track_data_version -> v$canonical_data_version)."
fi
done
if [ $update_needed_count -eq 0 ]
then
echo "All exercises are up to date!"
fi