release-notes.pl 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 2020 - 2022, 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. # $ ./scripts/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. # '#num'
  81. # 'num'
  82. # 'https://github.com/curl/curl/issues/6939'
  83. # 'https://github.com/curl/curl-www/issues/69'
  84. sub extract {
  85. my ($ref)=@_;
  86. if($ref =~ /^(\#|)(\d+)/) {
  87. # return the plain number
  88. return $2;
  89. }
  90. elsif($ref =~ /^https:\/\/github.com\/curl\/curl\/.*\/(\d+)/) {
  91. # return the plain number
  92. return $1;
  93. }
  94. else {
  95. # return the URL
  96. return $ref;
  97. }
  98. }
  99. my $short;
  100. my $first;
  101. for my $l (@gitlog) {
  102. chomp $l;
  103. if($l =~ /^commit/) {
  104. if($first) {
  105. onecommit($short);
  106. }
  107. # starts a new commit
  108. undef @fixes;
  109. undef @closes;
  110. undef @bug;
  111. $short = "";
  112. $first = 0;
  113. }
  114. elsif(($l =~ /^ (.*)/) && !$first) {
  115. # first line
  116. $short = $1;
  117. $first = 1;
  118. push @line, $short;
  119. }
  120. elsif(($l =~ /^ (.*)/) && $first) {
  121. # not the first
  122. my $line = $1;
  123. if($line =~ /^Fixes(:|) *(.*)/i) {
  124. push @fixes, extract($2);
  125. }
  126. elsif($line =~ /^Clo(s|)es(:|) *(.*)/i) {
  127. push @closes, extract($3);
  128. }
  129. elsif($line =~ /^Bug: (.*)/i) {
  130. push @bug, extract($1);
  131. }
  132. }
  133. }
  134. if($first) {
  135. onecommit($short);
  136. }
  137. # call at the end of a parsed commit
  138. sub onecommit {
  139. my ($short)=@_;
  140. my $ref;
  141. if($bug[0]) {
  142. $ref = $bug[0];
  143. }
  144. elsif($fixes[0]) {
  145. $ref = $fixes[0];
  146. }
  147. elsif($closes[0]) {
  148. $ref = $closes[0];
  149. }
  150. if($ref =~ /^#?(\d+)/) {
  151. $ref = "https://curl.se/bug/?i=$1"
  152. }
  153. if($ref) {
  154. my $r = getref();
  155. $refs[$r] = $ref;
  156. $moreinfo{$short}=$r;
  157. $refused[$r] |= 1;
  158. }
  159. }
  160. #### Output the new RELEASE-NOTES
  161. my @bullets;
  162. for my $l (@releasenotes) {
  163. if(($l =~ /^This release includes the following bugfixes:/) && !$cleanup) {
  164. push @o, $l;
  165. push @o, "\n";
  166. for my $f (@line) {
  167. push @o, sprintf " o %s%s\n", $f,
  168. $moreinfo{$f}? sprintf(" [%d]", $moreinfo{$f}): "";
  169. $refused[$moreinfo{$f}]=3;
  170. }
  171. push @o, " --- new entries are listed above this ---";
  172. next;
  173. }
  174. elsif($cleanup) {
  175. if($l =~ /^ --- new entries are listed/) {
  176. # ignore this if still around
  177. next;
  178. }
  179. elsif($l =~ /^ o .*/) {
  180. push @bullets, $l;
  181. next;
  182. }
  183. elsif($bullets[0]) {
  184. # output them case insensitively
  185. for my $b (sort { "\L$a" cmp "\L$b" } @bullets) {
  186. push @o, $b;
  187. }
  188. undef @bullets;
  189. }
  190. }
  191. if($l =~ /^ \[(\d+)\] = /) {
  192. # stop now
  193. last;
  194. }
  195. else {
  196. push @o, $l;
  197. }
  198. }
  199. my @srefs;
  200. my $ln;
  201. for my $n (1 .. $#refs) {
  202. my $r = $refs[$n];
  203. if($r && ($refused[$n] & 1)) {
  204. push @o, sprintf " [%d] = %s\n", $n, $r;
  205. }
  206. }
  207. open(O, ">RELEASE-NOTES");
  208. for my $l (@o) {
  209. print O $l;
  210. }
  211. close(O);
  212. exit;
  213. # Debug: show unused references
  214. for my $r (1 .. $#refs) {
  215. if($refused[$r] != 3) {
  216. printf "%s is %d!\n", $r, $refused[$r];
  217. }
  218. }