publish.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. crate_name=`echo $( awk -v FS="name = " 'NF>1{print $2; exit}' Cargo.toml )`
  43. echo "Publishing $crate_name to crates.io"
  44. if [ "$CRATE" == "protocol" ]
  45. then
  46. # Protocol crate needs --no-verify option due to build.rs modification.
  47. cargo publish --no-verify
  48. else
  49. cargo publish
  50. fi
  51. echo "Successfully published $crate_name to crates.io"
  52. done
  53. }
  54. function updateRepo {
  55. cd $WORKINGDIR
  56. echo "Pushing to master branch of repo."
  57. git push origin master
  58. echo "Pushing v$1 tag to master branch of repo."
  59. git push origin v$1
  60. }
  61. function run {
  62. switchBranch
  63. updateVersion $1
  64. commitAndTag $1
  65. publishCrates
  66. updateRepo $1
  67. echo "Successfully published v$1 to crates.io and uploaded changes to repo."
  68. }
  69. # First argument is new version number.
  70. run $1