lots of exercises in java... from https://github.com/exercism/java

canonical_data_check.sh 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env bash
  2. print_usage() {
  3. echo "Usage: ./canonical_data_check.sh -t path/to/track -s path/to/problem/specifications"
  4. }
  5. # Execution begins
  6. command -v jq >/dev/null 2>&1 || {
  7. echo >&2 "This script requires jq but it's not installed. Aborting."
  8. exit 1
  9. }
  10. num_args=$#
  11. if [ $num_args -eq 0 ]
  12. then
  13. print_usage
  14. exit 0
  15. fi
  16. path_to_track=
  17. path_to_problem_specifications=
  18. while getopts ":t:s:" option
  19. do
  20. case "$option" in
  21. "t")
  22. path_to_track="$OPTARG"
  23. ;;
  24. "s")
  25. path_to_problem_specifications="$OPTARG"
  26. ;;
  27. *)
  28. echo "Unrecognized option. Aborting."
  29. print_usage
  30. exit 1
  31. ;;
  32. esac
  33. done
  34. if [ -z "$path_to_track" ]
  35. then
  36. echo "Path to track missing."
  37. print_usage
  38. exit 1
  39. fi
  40. if [ -z "$path_to_problem_specifications" ]
  41. then
  42. echo "Path to problem specifications missing."
  43. print_usage
  44. exit 1
  45. fi
  46. config_file_path="$path_to_track/config.json"
  47. if ! [ -f "$config_file_path" ]
  48. then
  49. echo "Config file not found at $config_file_path."
  50. exit 1
  51. fi
  52. track_exercise_slugs=$(jq '.exercises[] | select(has("deprecated") | not) | .slug' $config_file_path | tr -d "\"")
  53. update_needed_count=0
  54. for slug in $track_exercise_slugs
  55. do
  56. canonical_data_folder_path="$path_to_problem_specifications/exercises/$slug"
  57. if ! [ -d "$canonical_data_folder_path" ]
  58. then
  59. echo "Canonical data folder $canonical_data_folder_path not found. Aborting."
  60. exit 1
  61. fi
  62. canonical_data_file_path="$canonical_data_folder_path/canonical-data.json"
  63. if ! [ -f "$canonical_data_file_path" ]
  64. then
  65. # echo "$slug: no canonical data found."
  66. continue
  67. fi
  68. canonical_data_version=$(jq '.version' $canonical_data_file_path | tr -d "\"")
  69. track_exercise_version_file_path="$path_to_track/exercises/$slug/.meta/version"
  70. if ! [ -f "$track_exercise_version_file_path" ]
  71. then
  72. echo "$slug: needs update or version file (v$canonical_data_version)."
  73. update_needed_count=$((update_needed_count + 1))
  74. continue
  75. fi
  76. track_data_version=$(cat $track_exercise_version_file_path | sed 's/\r$//')
  77. if [ "$track_data_version" = "$canonical_data_version" ]
  78. then
  79. # echo "$slug: up-to-date."
  80. continue
  81. else
  82. update_needed_count=$((update_needed_count + 1))
  83. echo "$slug: needs update (v$track_data_version -> v$canonical_data_version)."
  84. fi
  85. done
  86. if [ $update_needed_count -eq 0 ]
  87. then
  88. echo "All exercises are up to date!"
  89. fi