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.

148 lines
3.2 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. update_changelog()
  38. {
  39. local new_version="$1"
  40. local new_date=$(date "+%Y-%m-%d")
  41. sed -i "s/\[Unreleased\]/\[${new_version}\] - ${new_date}/" "CHANGELOG.md"
  42. }
  43. check_working_directory()
  44. {
  45. local status
  46. status=$(git status --untracked-files="no" --porcelain="2")
  47. if [[ "$status" != "" ]]; then
  48. echo "Unable to create a new release while the working directory is not clean."
  49. abort_release
  50. fi
  51. }
  52. commit_new_version()
  53. {
  54. local new_version="$1"
  55. git add --update
  56. git commit -m "ACMEd v${new_version}"
  57. git tag -m "ACMEd v${new_version}" "v${new_version}"
  58. echo
  59. echo "Version ${new_version} has been committed and tagged."
  60. echo "If everything is correct, you can publish if using:"
  61. echo " git push"
  62. echo " git push origin v${new_version}"
  63. }
  64. release_new_version()
  65. {
  66. local new_version="$1"
  67. local current_date="$2"
  68. local confirm_git_diff
  69. update_crate_version "acme_common" "${new_version}"
  70. update_crate_version "acmed" "${new_version}"
  71. update_crate_version "tacd" "${new_version}"
  72. update_man_date "acmed.8" "${current_date}"
  73. update_man_date "acmed.toml.5" "${current_date}"
  74. update_man_date "tacd.8" "${current_date}"
  75. update_changelog "${new_version}"
  76. cargo update
  77. git diff
  78. echo
  79. echo -n "Does everything seems ok? [y|N] "
  80. read -r confirm_git_diff
  81. case "${confirm_git_diff}" in
  82. y|Y) commit_new_version "${new_version}";;
  83. *)
  84. git restore "."
  85. abort_release
  86. ;;
  87. esac
  88. }
  89. main()
  90. {
  91. local new_version
  92. local confirm_release
  93. check_working_directory
  94. display_crate_version "acme_common"
  95. display_crate_version "acmed"
  96. display_crate_version "tacd"
  97. echo
  98. display_man_date "acmed.8"
  99. display_man_date "acmed.toml.5"
  100. display_man_date "tacd.8"
  101. echo
  102. echo -n "Enter the new version: "
  103. read -r new_version
  104. export LC_TIME="en_US.UTF-8"
  105. current_date=$(date "+%b %d, %Y")
  106. echo
  107. echo "You are about to release version ${new_version} on ${current_date}"
  108. echo -n "Are you sure? [y/N] "
  109. read -r confirm_release
  110. case "${confirm_release}" in
  111. y|Y) release_new_version "${new_version}" "${current_date}";;
  112. *) abort_release;;
  113. esac
  114. }
  115. main