release.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. #set -x
  3. args=("$@")
  4. function printHelp() {
  5. echo 'Shell Script utility to publish the modules of this project to Maven using the Gradle Wrapper'
  6. echo 'You can decide what to publish with the following arguments:'
  7. echo ' 1) all : tells the script to publish all the modules'
  8. echo ' 2) A list of modules (ex. components, core,...)'
  9. echo ''
  10. echo 'Options:'
  11. echo '-r to also automatically release the artifacts once they are published'
  12. echo '-c to clean the project before everything else'
  13. echo ''
  14. echo ''
  15. echo 'Before running this script makes sure that your JAVA_HOME environment variable is set and correct'
  16. }
  17. function checkArgs() {
  18. for var in "${args[@]}"; do
  19. if [ "$var" == "$1" ]; then
  20. ret="true"
  21. return
  22. fi
  23. done
  24. ret="false"
  25. }
  26. function checkRelease() {
  27. local ret=""
  28. checkArgs '-r'
  29. if [ "$ret" == "true" ]; then
  30. rel_ret='closeAndReleaseRepository'
  31. else
  32. rel_ret=''
  33. fi
  34. }
  35. function publishModules() {
  36. local rel_ret=""
  37. local tmp=""
  38. checkRelease
  39. if [ "$rel_ret" != "" ]; then
  40. echo 'Publishing and RELEASING specified modules!'
  41. else
  42. echo 'Publishing specified modules!'
  43. fi
  44. for var in "${args[@]}"; do
  45. tmp=$var # I don't fucking know why, it just works this way
  46. if [ "$var" != "all" ] && [ "$var" != "-h" ] && [ "$var" != "-r" ] && [ "$var" != "-c" ]; then
  47. ./gradlew "$tmp:publish"
  48. if [ "$rel_ret" != "" ]; then
  49. ./gradlew "$tmp:closeAndReleaseRepository"
  50. fi
  51. fi
  52. done
  53. }
  54. function main() {
  55. local ret=""
  56. if [ $# == 0 ]; then
  57. echo "No args provided"
  58. exit 1
  59. else
  60. cd ..
  61. fi
  62. checkArgs '-h'
  63. if [ "$ret" == "true" ]; then
  64. printHelp
  65. exit 1
  66. fi
  67. checkArgs '-c'
  68. if [ "$ret" == "true" ]; then
  69. ./gradlew clean
  70. fi
  71. checkArgs 'all'
  72. if [ "$ret" == "true" ]; then
  73. checkRelease
  74. ./gradlew publish "$rel_ret"
  75. exit 0
  76. fi
  77. publishModules
  78. }
  79. main "$@"