publish.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. done
  24. }
  25. function commitAndTag {
  26. git commit -a -m "Update version numbers to $1"
  27. git tag "v$1" -a -m "Update to version $1"
  28. }
  29. function get_crate_name {
  30. awk -v FS="name = " 'NF>1{print $2; exit}' Cargo.toml
  31. }
  32. function publishCrates {
  33. for CRATE in "${crates[@]}"
  34. do
  35. if [ "$CRATE" = "librespot" ]
  36. then
  37. CRATE=''
  38. fi
  39. crate_path="$WORKINGDIR/$CRATE"
  40. crate_path=${crate_path//\/\///}
  41. cd $crate_path
  42. # Also need to update Cargo.lock in root directory
  43. crate_name=`echo $( awk -v FS="name = " 'NF>1{print $2; exit}' Cargo.toml )`
  44. echo "Publishing $crate_name to crates.io"
  45. if [ "$CRATE" == "protocol" ]
  46. then
  47. # Protocol crate needs --no-verify option due to build.rs modification.
  48. cargo publish --no-verify
  49. else
  50. cargo publish
  51. fi
  52. echo "Successfully published $crate_name to crates.io"
  53. # Should sleep here for 30 seconds to allow Crates.io time to push updated package to edge servers.
  54. done
  55. }
  56. function updateRepo {
  57. cd $WORKINGDIR
  58. echo "Pushing to master branch of repo."
  59. git push origin master
  60. echo "Pushing v$1 tag to master branch of repo."
  61. git push origin v$1
  62. }
  63. function run {
  64. switchBranch
  65. updateVersion $1
  66. commitAndTag $1
  67. publishCrates
  68. updateRepo $1
  69. echo "Successfully published v$1 to crates.io and uploaded changes to repo."
  70. }
  71. # First argument is new version number.
  72. run $1