publish.sh 2.4 KB

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