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.

140 lines
2.8 KiB

1 month ago
1 month ago
1 month ago
1 month ago
  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_version
  14. crate_version=$(grep "^version" "Cargo.toml" | cut -d '"' -f2)
  15. echo "Current version: ${crate_version}"
  16. }
  17. update_crate_version()
  18. {
  19. local new_version="$2"
  20. sed -i "s/^version = .*/version = \"${new_version}\"/" "/Cargo.toml"
  21. }
  22. display_man_date()
  23. {
  24. local man_name="$1"
  25. local man_date
  26. man_date=$(grep ".Dd" "man/en/${man_name}" | sed "s/\.Dd //")
  27. echo "Current date for ${man_name}: ${man_date}"
  28. }
  29. update_man_date()
  30. {
  31. local man_name="$1"
  32. local new_date="$2"
  33. sed -i "s/\.Dd .*/\.Dd ${new_date}/" "man/en/${man_name}"
  34. }
  35. update_changelog()
  36. {
  37. local new_version="$1"
  38. local new_date=$(date "+%Y-%m-%d")
  39. sed -i "s/\[Unreleased\]/\[${new_version}\] - ${new_date}/" "CHANGELOG.md"
  40. }
  41. check_working_directory()
  42. {
  43. local status
  44. status=$(git status --untracked-files="no" --porcelain="2")
  45. if [[ "$status" != "" ]]; then
  46. echo "Unable to create a new release while the working directory is not clean."
  47. abort_release
  48. fi
  49. }
  50. commit_new_version()
  51. {
  52. local new_version="$1"
  53. git add --update
  54. git commit -m "ACMEd v${new_version}"
  55. git tag -m "ACMEd v${new_version}" "v${new_version}"
  56. echo
  57. echo "Version ${new_version} has been committed and tagged."
  58. echo "If everything is correct, you can publish if using:"
  59. echo " git push"
  60. echo " git push origin v${new_version}"
  61. }
  62. release_new_version()
  63. {
  64. local new_version="$1"
  65. local current_date="$2"
  66. local confirm_git_diff
  67. update_crate_version "${new_version}"
  68. update_man_date "acmed.8" "${current_date}"
  69. update_man_date "acmed.toml.5" "${current_date}"
  70. update_changelog "${new_version}"
  71. cargo update
  72. git diff
  73. echo
  74. echo -n "Does everything seems ok? [y|N] "
  75. read -r confirm_git_diff
  76. case "${confirm_git_diff}" in
  77. y|Y) commit_new_version "${new_version}";;
  78. *)
  79. git restore "."
  80. abort_release
  81. ;;
  82. esac
  83. }
  84. main()
  85. {
  86. local new_version
  87. local confirm_release
  88. check_working_directory
  89. display_crate_version
  90. echo
  91. display_man_date "acmed.8"
  92. display_man_date "acmed.toml.5"
  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