publish.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. while [ $secs -gt 0 ]
  40. do
  41. sleep 1 &
  42. printf "\rSleeping to allow packages to propagate on crates.io servers. Continuing in %2d second(s)." ${secs}
  43. secs=$(( $secs - 1 ))
  44. wait
  45. done
  46. echo
  47. }
  48. function publishCrates {
  49. for CRATE in "${crates[@]}"
  50. do
  51. if [ "$CRATE" = "librespot" ]
  52. then
  53. CRATE=''
  54. fi
  55. crate_path="$WORKINGDIR/$CRATE"
  56. crate_path=${crate_path//\/\///}
  57. cd $crate_path
  58. # Also need to update Cargo.lock in root directory
  59. crate_name=`echo $( awk -v FS="name = " 'NF>1{print $2; exit}' Cargo.toml )`
  60. echo "Publishing $crate_name to crates.io"
  61. if [ "$CRATE" == "protocol" ]
  62. then
  63. # Protocol crate needs --no-verify option due to build.rs modification.
  64. cargo publish --no-verify
  65. else
  66. cargo publish
  67. fi
  68. echo "Successfully published $crate_name to crates.io"
  69. remoteWait 30
  70. done
  71. }
  72. function updateRepo {
  73. cd $WORKINGDIR
  74. echo "Pushing to master branch of repo."
  75. git push origin master
  76. echo "Pushing v$1 tag to master branch of repo."
  77. git push origin v$1
  78. }
  79. function run {
  80. switchBranch
  81. updateVersion $1
  82. commitAndTag $1
  83. publishCrates
  84. updateRepo $1
  85. echo "Successfully published v$1 to crates.io and uploaded changes to repo."
  86. }
  87. # First argument is new version number.
  88. run $1