You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.0 KiB

  1. #!/usr/bin/env bash
  2. #
  3. # This script creates a new release and is therefore not meant to be
  4. # used by anyone but the project manager. It will therefore remain
  5. # undocumented and may assume some specific environment.
  6. abort_release()
  7. {
  8. echo "Aborting."
  9. exit 1
  10. }
  11. display_crate_version()
  12. {
  13. local crate_name="$1"
  14. local crate_version
  15. crate_version=$(grep "^version" "${crate_name}/Cargo.toml" | cut -d '"' -f2)
  16. echo "Current version for crate ${crate_name}: ${crate_version}"
  17. }
  18. update_crate_version()
  19. {
  20. local crate_name="$1"
  21. local new_version="$2"
  22. sed -i "s/^version = .*/version = \"${new_version}\"/" "${crate_name}/Cargo.toml"
  23. }
  24. display_man_date()
  25. {
  26. local man_name="$1"
  27. local man_date
  28. man_date=$(grep ".Dd" "man/en/${man_name}" | sed "s/\.Dd //")
  29. echo "Current date for ${man_name}: ${man_date}"
  30. }
  31. update_man_date()
  32. {
  33. local man_name="$1"
  34. local new_date="$2"
  35. sed -i "s/\.Dd .*/\.Dd ${new_date}/" "man/en/${man_name}"
  36. }
  37. check_working_directory()
  38. {
  39. local status
  40. status=$(git status --untracked-files="no" --porcelain="2")
  41. if [[ "$status" != "" ]]; then
  42. echo "Unable to create a new release while the working directory is not clean."
  43. abort_release
  44. fi
  45. }
  46. commit_new_version()
  47. {
  48. local new_version="$1"
  49. git add --update
  50. git commit -m "ACMEd v${new_version}"
  51. git tag -m "ACMEd v${new_version}" "v${new_version}"
  52. echo
  53. echo "Version ${new_version} has been committed and tagged."
  54. echo "If everything is correct, you can publish if using:"
  55. echo " git push"
  56. echo " git push origin v${new_version}"
  57. }
  58. release_new_version()
  59. {
  60. local new_version="$1"
  61. local current_date="$2"
  62. local confirm_git_diff
  63. update_crate_version "acme_common" "${new_version}"
  64. update_crate_version "acmed" "${new_version}"
  65. update_crate_version "tacd" "${new_version}"
  66. update_man_date "acmed.8" "${current_date}"
  67. update_man_date "acmed.toml.5" "${current_date}"
  68. update_man_date "tacd.8" "${current_date}"
  69. git diff
  70. echo
  71. echo -n "Does everything seems ok? [y|N] "
  72. read -r confirm_git_diff
  73. case "${confirm_git_diff}" in
  74. y|Y) commit_new_version "${new_version}";;
  75. *)
  76. git restore "."
  77. abort_release
  78. ;;
  79. esac
  80. }
  81. main()
  82. {
  83. local new_version
  84. local confirm_release
  85. check_working_directory
  86. display_crate_version "acme_common"
  87. display_crate_version "acmed"
  88. display_crate_version "tacd"
  89. echo
  90. display_man_date "acmed.8"
  91. display_man_date "acmed.toml.5"
  92. display_man_date "tacd.8"
  93. echo
  94. echo -n "Enter the new version: "
  95. read -r new_version
  96. export LC_TIME="en_US.UTF-8"
  97. current_date=$(date "+%b %d, %Y")
  98. echo
  99. echo "You are about to release version ${new_version} on ${current_date}"
  100. echo -n "Are you sure? [y/N] "
  101. read -r confirm_release
  102. case "${confirm_release}" in
  103. y|Y) release_new_version "${new_version}" "${current_date}";;
  104. *) abort_release;;
  105. esac
  106. }
  107. main