release.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #! /usr/bin/env bash
  2. # Copyright (c) Meta Platforms, Inc. and affiliates.
  3. set -e
  4. if [ ! -d unreleased_history ]; then
  5. echo "Can't find unreleased_history/ directory"
  6. exit 1
  7. fi
  8. GIT_PATHS="unreleased_history/ HISTORY.md"
  9. if [ ! "$DRY_RUN" ]; then
  10. # Check for uncommitted changes
  11. UNCOMMITTED="$(git diff -- $GIT_PATHS)"
  12. if [ "$UNCOMMITTED" ]; then
  13. echo 'Uncommitted changes to files to be modified. Please commit first to'
  14. echo 'ensure a clean revert path. You can always `git commit -a --amend`'
  15. echo 'to add more changes to your commit.'
  16. exit 2
  17. fi
  18. fi
  19. # Add first part of existing HISTORY file to new version
  20. awk '{ print } /NOTE/ { exit(0) }' < HISTORY.md > HISTORY.new
  21. # And a blank line separator
  22. echo >> HISTORY.new
  23. # Add new version header
  24. awk '/#define ROCKSDB_MAJOR/ { major = $3 }
  25. /#define ROCKSDB_MINOR/ { minor = $3 }
  26. /#define ROCKSDB_PATCH/ { patch = $3 }
  27. END { printf "## " major "." minor "." patch }' < include/rocksdb/version.h >> HISTORY.new
  28. echo " (`git log -n1 --date=format:"%m/%d/%Y" --format="%ad"`)" >> HISTORY.new
  29. function process_file () {
  30. # use awk to correct
  31. # * extra or missing newlines
  32. # * leading or trailing whitespace
  33. # * missing '* ' on first line
  34. awk '/./ { gsub(/^[ \t]+/, ""); gsub(/[ \t]+$/, "");
  35. if (notfirstline || $1 == "*") print;
  36. else print "* " $0;
  37. notfirstline=1; }' < $1 >> HISTORY.new
  38. echo git rm $1
  39. if [ ! "$DRY_RUN" ]; then
  40. git rm $1
  41. fi
  42. }
  43. PROCESSED_DIRECTORIES=""
  44. function process_dir () {
  45. PROCESSED_DIRECTORIES="$PROCESSED_DIRECTORIES $1"
  46. # ls will sort the files, including the permanent header file
  47. FILES="$(ls unreleased_history/$1/)"
  48. if [ "$FILES" ]; then
  49. echo "### $2" >> HISTORY.new
  50. for FILE in $FILES; do
  51. process_file "unreleased_history/$1/$FILE"
  52. done
  53. echo >> HISTORY.new
  54. echo "Saved entries from $1"
  55. else
  56. echo "Nothing new in $1"
  57. fi
  58. }
  59. # Process dirs and files
  60. process_dir new_features "New Features"
  61. process_dir public_api_changes "Public API Changes"
  62. process_dir behavior_changes "Behavior Changes"
  63. process_dir bug_fixes "Bug Fixes"
  64. process_dir performance_improvements "Performance Improvements"
  65. # Check for unexpected files or dirs at top level. process_dir/process_file
  66. # will deal with contents of these directories
  67. EXPECTED_REGEX="[^/]*[.]sh|README[.]txt|$(echo $PROCESSED_DIRECTORIES | tr ' ' '|')"
  68. platform=`uname`
  69. if [ $platform = 'Darwin' ]; then
  70. UNEXPECTED="$(find -E unreleased_history -mindepth 1 -maxdepth 1 -not -regex "[^/]*/($EXPECTED_REGEX)")"
  71. else
  72. UNEXPECTED="$(find unreleased_history/ -mindepth 1 -maxdepth 1 -regextype egrep -not -regex "[^/]*/($EXPECTED_REGEX)")"
  73. fi
  74. if [ "$UNEXPECTED" ]; then
  75. echo "Unexpected files I don't know how to process:"
  76. echo "$UNEXPECTED"
  77. rm HISTORY.new
  78. exit 3
  79. fi
  80. # Add rest of existing HISTORY file to new version (collapsing newlines)
  81. awk '/./ { if (note) pr=1 }
  82. /NOTE/ { note=1 }
  83. { if (pr) print }' < HISTORY.md >> HISTORY.new
  84. if [ "$DRY_RUN" ]; then
  85. echo '==========================================='
  86. diff -U3 HISTORY.md HISTORY.new || true
  87. rm HISTORY.new
  88. else
  89. mv HISTORY.new HISTORY.md
  90. echo "Done. Revert command: git checkout HEAD -- $GIT_PATHS"
  91. fi