publish.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. WORKINGDIR="$( cd "$(dirname "$0")" ; pwd -P )"
  3. cd $WORKINGDIR
  4. crates=( "protocol" "core" "audio" "metadata" "playback" "connect" "librespot" )
  5. function switchBranch {
  6. # You are expected to have committed/stashed your changes before running this.
  7. echo "Switching to master branch and merging development."
  8. git checkout master
  9. git pull
  10. git merge dev
  11. }
  12. function updateVersion {
  13. for CRATE in "${crates[@]}"
  14. do
  15. if [ "$CRATE" = "librespot" ]
  16. then
  17. CRATE=''
  18. fi
  19. crate_path="$WORKINGDIR/$CRATE/Cargo.toml"
  20. crate_path=${crate_path//\/\///}
  21. sed -i '' "s/^version.*/version = \"$1\"/g" "$crate_path"
  22. echo "Path is $crate_path"
  23. if [ "$CRATE" = "librespot" ]
  24. then
  25. cargo update
  26. fi
  27. done
  28. }
  29. function commitAndTag {
  30. git commit -a -m "Update version numbers to $1"
  31. git tag "v$1" -a -m "Update to version $1"
  32. }
  33. function get_crate_name {
  34. awk -v FS="name = " 'NF>1{print $2; exit}' Cargo.toml
  35. }
  36. function remoteWait() {
  37. IFS=:
  38. secs=${1}
  39. crate_name=${2}
  40. while [ $secs -gt 0 ]
  41. do
  42. sleep 1 &
  43. printf "\rSleeping to allow %s to propagate on crates.io servers. Continuing in %2d second(s)." ${crate_name} ${secs}
  44. secs=$(( $secs - 1 ))
  45. wait
  46. done
  47. echo
  48. }
  49. function publishCrates {
  50. for CRATE in "${crates[@]}"
  51. do
  52. if [ "$CRATE" = "librespot" ]
  53. then
  54. CRATE=''
  55. fi
  56. crate_path="$WORKINGDIR/$CRATE"
  57. crate_path=${crate_path//\/\///}
  58. cd $crate_path
  59. # Also need to update Cargo.lock in root directory
  60. crate_name=`echo $( awk -v FS="name = " 'NF>1{print $2; exit}' Cargo.toml )`
  61. echo "Publishing $crate_name to crates.io"
  62. if [ "$CRATE" == "protocol" ]
  63. then
  64. # Protocol crate needs --no-verify option due to build.rs modification.
  65. cargo publish --no-verify
  66. else
  67. cargo publish
  68. fi
  69. echo "Successfully published $crate_name to crates.io"
  70. remoteWait 30 crate_name
  71. done
  72. }
  73. function updateRepo {
  74. cd $WORKINGDIR
  75. echo "Pushing to master branch of repo."
  76. git push origin master
  77. echo "Pushing v$1 tag to master branch of repo."
  78. git push origin v$1
  79. }
  80. function run {
  81. switchBranch
  82. updateVersion $1
  83. commitAndTag $1
  84. publishCrates
  85. updateRepo $1
  86. echo "Successfully published v$1 to crates.io and uploaded changes to repo."
  87. }
  88. # First argument is new version number.
  89. run $1