release-notes.pl 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #!/usr/bin/perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. ###########################################################################
  23. ###############################################
  24. #
  25. # ==== How to use this script ====
  26. #
  27. # 1. Get recent commits added to RELEASE-NOTES:
  28. #
  29. # $ ./scripts/release-notes.pl
  30. #
  31. # 2. Edit RELEASE-NOTES and remove all entries that don't belong. Unused
  32. # references below will be cleaned up in the next step. Make sure to move
  33. # "changes" up to the changes section. All entries will by default be listed
  34. # under bug-fixes as this script can't know where to put them.
  35. #
  36. # 3. Run the cleanup script and let it sort the entries and remove unused
  37. # references from lines you removed in step (2):
  38. #
  39. # $ ./script/release-notes.pl cleanup
  40. #
  41. # 4. Reload RELEASE-NOTES and verify that things look okay. The cleanup
  42. # procedure can and should be re-run when lines are removed or rephrased.
  43. #
  44. # 5. Run ./scripts/contributors.sh and update the contributor list of names
  45. # The list can also be extended or edited manually.
  46. #
  47. # 6. Run ./scripts/delta and update the contributor count at the top, and
  48. # double-check/update the other counters.
  49. #
  50. # 7. Commit the file using "RELEASE-NOTES: synced" as commit message.
  51. #
  52. ################################################
  53. my $cleanup = ($ARGV[0] eq "cleanup");
  54. my @gitlog=`git log @^{/RELEASE-NOTES:.synced}..` if(!$cleanup);
  55. my @releasenotes=`cat RELEASE-NOTES`;
  56. my @o; # the entire new RELEASE-NOTES
  57. my @refused; # [num] = [2 bits of use info]
  58. my @refs; # [number] = [URL]
  59. for my $l (@releasenotes) {
  60. if($l =~ /^ o .*\[(\d+)\]/) {
  61. # referenced, set bit 0
  62. $refused[$1]=1;
  63. }
  64. elsif($l =~ /^ \[(\d+)\] = (.*)/) {
  65. # listed in a reference, set bit 1
  66. $refused[$1] |= 2;
  67. $refs[$1] = $2;
  68. }
  69. }
  70. # Return a new fresh reference number
  71. sub getref {
  72. for my $r (1 .. $#refs) {
  73. if(!$refused[$r] & 1) {
  74. return $r;
  75. }
  76. }
  77. # add at the end
  78. return $#refs + 1;
  79. }
  80. my $short;
  81. my $first;
  82. for my $l (@gitlog) {
  83. chomp $l;
  84. if($l =~ /^commit/) {
  85. if($first) {
  86. onecommit($short);
  87. }
  88. # starts a new commit
  89. undef @fixes;
  90. undef @closes;
  91. undef @bug;
  92. $short = "";
  93. $first = 0;
  94. }
  95. elsif(($l =~ /^ (.*)/) && !$first) {
  96. # first line
  97. $short = $1;
  98. $first = 1;
  99. push @line, $short;
  100. }
  101. elsif(($l =~ /^ (.*)/) && $first) {
  102. # not the first
  103. my $line = $1;
  104. if($line =~ /^Fixes(:|) .*[^0-9](\d+)/i) {
  105. push @fixes, $2;
  106. }
  107. elsif($line =~ /^Closes(:|) .*[^0-9](\d+)/i) {
  108. push @closes, $2;
  109. }
  110. elsif($line =~ /^Bug: (.*)/i) {
  111. push @bug, $1;
  112. }
  113. }
  114. }
  115. if($first) {
  116. onecommit($short);
  117. }
  118. # call at the end of a parsed commit
  119. sub onecommit {
  120. my ($short)=@_;
  121. my $ref;
  122. if($bug[0]) {
  123. $ref = $bug[0];
  124. }
  125. elsif($fixes[0]) {
  126. $ref = $fixes[0];
  127. }
  128. elsif($closes[0]) {
  129. $ref = $closes[0];
  130. }
  131. if($ref =~ /^#?(\d+)/) {
  132. $ref = "https://curl.se/bug/?i=$1"
  133. }
  134. if($ref) {
  135. my $r = getref();
  136. $refs[$r] = $ref;
  137. $moreinfo{$short}=$r;
  138. $refused[$r] |= 1;
  139. }
  140. }
  141. #### Output the new RELEASE-NOTES
  142. my @bullets;
  143. for my $l (@releasenotes) {
  144. if(($l =~ /^This release includes the following bugfixes:/) && !$cleanup) {
  145. push @o, $l;
  146. push @o, "\n";
  147. for my $f (@line) {
  148. push @o, sprintf " o %s%s\n", $f,
  149. $moreinfo{$f}? sprintf(" [%d]", $moreinfo{$f}): "";
  150. $refused[$moreinfo{$f}]=3;
  151. }
  152. push @o, " --- new entries are listed above this ---";
  153. next;
  154. }
  155. elsif($cleanup) {
  156. if($l =~ /^ --- new entries are listed/) {
  157. # ignore this if still around
  158. next;
  159. }
  160. elsif($l =~ /^ o .*/) {
  161. push @bullets, $l;
  162. next;
  163. }
  164. elsif($bullets[0]) {
  165. # output them case insensitively
  166. for my $b (sort { "\L$a" cmp "\L$b" } @bullets) {
  167. push @o, $b;
  168. }
  169. undef @bullets;
  170. }
  171. }
  172. if($l =~ /^ \[(\d+)\] = /) {
  173. # stop now
  174. last;
  175. }
  176. else {
  177. push @o, $l;
  178. }
  179. }
  180. my @srefs;
  181. my $ln;
  182. for my $n (1 .. $#refs) {
  183. my $r = $refs[$n];
  184. if($r && ($refused[$n] & 1)) {
  185. push @o, sprintf " [%d] = %s\n", $n, $r;
  186. }
  187. }
  188. open(O, ">RELEASE-NOTES");
  189. for my $l (@o) {
  190. print O $l;
  191. }
  192. close(O);
  193. exit;
  194. # Debug: show unused references
  195. for my $r (1 .. $#refs) {
  196. if($refused[$r] != 3) {
  197. printf "%s is %d!\n", $r, $refused[$r];
  198. }
  199. }