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

canonical_data_check.sh 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. for slug in $track_exercise_slugs
  54. do
  55. canonical_data_folder_path="$path_to_problem_specifications/exercises/$slug"
  56. if ! [ -d "$canonical_data_folder_path" ]
  57. then
  58. echo "Canonical data folder $canonical_data_folder_path not found. Aborting."
  59. exit 1
  60. fi
  61. canonical_data_file_path="$canonical_data_folder_path/canonical-data.json"
  62. if ! [ -f "$canonical_data_file_path" ]
  63. then
  64. # echo "$slug: no canonical data found."
  65. continue
  66. fi
  67. canonical_data_version=$(jq '.version' $canonical_data_file_path | tr -d "\"")
  68. track_exercise_version_file_path="$path_to_track/exercises/$slug/.meta/version"
  69. if ! [ -f "$track_exercise_version_file_path" ]
  70. then
  71. echo "$slug: needs update or version file (v$canonical_data_version)."
  72. continue
  73. fi
  74. track_data_version=$(cat $track_exercise_version_file_path)
  75. if [ "$track_data_version" = "$canonical_data_version" ]
  76. then
  77. # echo "$slug: up-to-date."
  78. continue
  79. else
  80. echo "$slug: needs update (v$track_data_version -> v$canonical_data_version)."
  81. fi
  82. done