check-crates.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/usr/bin/env bash
  2. # input:
  3. # env:
  4. # - CRATE_TOKEN
  5. # - COMMIT_RANGE
  6. if [[ -z $COMMIT_RANGE ]]; then
  7. echo "COMMIT_RANGE should be provided"
  8. exit 1
  9. fi
  10. if ! command -v toml &>/dev/null; then
  11. echo "not found toml-cli"
  12. cargo install toml-cli
  13. fi
  14. declare skip_patterns=(
  15. "Cargo.toml"
  16. "programs/sbf"
  17. )
  18. declare -A verified_crate_owners=(
  19. ["anza-team"]=1
  20. )
  21. # get Cargo.toml from git diff
  22. readarray -t files <<<"$(git diff "$COMMIT_RANGE" --diff-filter=AM --name-only | grep Cargo.toml)"
  23. printf "%s\n" "${files[@]}"
  24. error_count=0
  25. for file in "${files[@]}"; do
  26. read -r crate_name package_publish workspace < <(toml get "$file" . | jq -r '(.package.name | tostring)+" "+(.package.publish | tostring)+" "+(.workspace | tostring)')
  27. echo "=== $crate_name ($file) ==="
  28. if [[ $package_publish = 'false' ]]; then
  29. echo -e "⏩ skip (package_publish: $package_publish)\n"
  30. continue
  31. fi
  32. if [[ "$workspace" != "null" ]]; then
  33. echo -e "⏩ skip (is a workspace root)\n"
  34. continue
  35. fi
  36. for skip_pattern in "${skip_patterns[@]}"; do
  37. if [[ $file =~ ^$skip_pattern ]]; then
  38. echo -e "⏩ skip (match skip patterns)\n"
  39. continue 2
  40. fi
  41. done
  42. response=$(curl -s https://crates.io/api/v1/crates/"$crate_name"/owners)
  43. errors=$(echo "$response" | jq .errors)
  44. if [[ $errors != "null" ]]; then
  45. details=$(echo "$response" | jq .errors | jq -r ".[0].detail")
  46. if [[ $details = *"does not exist"* ]]; then
  47. ((error_count++))
  48. echo "❌ new crate $crate_name not found on crates.io. you can either
  49. 1. mark it as not for publication in its Cargo.toml
  50. [package]
  51. ...
  52. publish = false
  53. or
  54. 2. make a dummy publication.
  55. example:
  56. scripts/reserve-cratesio-package-name.sh \
  57. --token <GRIMES_CRATESIO_TOKEN> \
  58. lib solana-new-lib-crate
  59. see also: scripts/reserve-cratesio-package-name.sh --help
  60. "
  61. else
  62. ((error_count++))
  63. echo "❌ $response"
  64. fi
  65. else
  66. readarray -t owners <<<"$(echo "$response" | jq .users | jq -r ".[] | .login")"
  67. verified_owner_count=0
  68. unverified_owner_count=0
  69. for owner in "${owners[@]}"; do
  70. if [[ -z $owner ]]; then
  71. continue
  72. fi
  73. owner_id="$(echo "$owner" | awk '{print $1}')"
  74. if [[ ${verified_crate_owners[$owner_id]} ]]; then
  75. ((verified_owner_count++))
  76. echo "✅ $owner"
  77. else
  78. ((unverified_owner_count++))
  79. echo "❌ $owner"
  80. fi
  81. done
  82. if [[ ($unverified_owner_count -gt 0) ]]; then
  83. ((error_count++))
  84. echo "error: found unverified owner(s)"
  85. elif [[ ($verified_owner_count -le 0) ]]; then
  86. ((error_count++))
  87. echo "error: there are no verified owners"
  88. fi
  89. fi
  90. echo ""
  91. done
  92. if [ "$error_count" -eq 0 ]; then
  93. echo "success"
  94. exit 0
  95. else
  96. exit 1
  97. fi