release-notes.pl 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. # SPDX-License-Identifier: curl
  23. #
  24. ###########################################################################
  25. ###############################################
  26. #
  27. # ==== How to use this script ====
  28. #
  29. # 1. Get recent commits added to RELEASE-NOTES:
  30. #
  31. # $ ./scripts/release-notes.pl
  32. #
  33. # 2. Edit RELEASE-NOTES and remove all entries that don't belong. Unused
  34. # references below will be cleaned up in the next step. Make sure to move
  35. # "changes" up to the changes section. All entries will by default be listed
  36. # under bug-fixes as this script can't know where to put them.
  37. #
  38. # 3. Run the cleanup script and let it sort the entries and remove unused
  39. # references from lines you removed in step (2):
  40. #
  41. # $ ./scripts/release-notes.pl cleanup
  42. #
  43. # 4. Reload RELEASE-NOTES and verify that things look okay. The cleanup
  44. # procedure can and should be re-run when lines are removed or rephrased.
  45. #
  46. # 5. Run ./scripts/contributors.sh and update the contributor list of names
  47. # The list can also be extended or edited manually.
  48. #
  49. # 6. Run ./scripts/delta and update the contributor count at the top, and
  50. # double-check/update the other counters.
  51. #
  52. # 7. Commit the file using "RELEASE-NOTES: synced" as commit message.
  53. #
  54. ################################################
  55. my $cleanup = ($ARGV[0] eq "cleanup");
  56. my @gitlog=`git log @^{/RELEASE-NOTES:.synced}..` if(!$cleanup);
  57. my @releasenotes=`cat RELEASE-NOTES`;
  58. my @o; # the entire new RELEASE-NOTES
  59. my @refused; # [num] = [2 bits of use info]
  60. my @refs; # [number] = [URL]
  61. for my $l (@releasenotes) {
  62. if($l =~ /^ o .*\[(\d+)\]/) {
  63. # referenced, set bit 0
  64. $refused[$1]=1;
  65. }
  66. elsif($l =~ /^ \[(\d+)\] = (.*)/) {
  67. # listed in a reference, set bit 1
  68. $refused[$1] |= 2;
  69. $refs[$1] = $2;
  70. }
  71. }
  72. # Return a new fresh reference number
  73. sub getref {
  74. for my $r (1 .. $#refs) {
  75. if(!$refused[$r] & 1) {
  76. return $r;
  77. }
  78. }
  79. # add at the end
  80. return $#refs + 1;
  81. }
  82. # '#num'
  83. # 'num'
  84. # 'https://github.com/curl/curl/issues/6939'
  85. # 'https://github.com/curl/curl-www/issues/69'
  86. sub extract {
  87. my ($ref)=@_;
  88. if($ref =~ /^(\#|)(\d+)/) {
  89. # return the plain number
  90. return $2;
  91. }
  92. elsif($ref =~ /^https:\/\/github.com\/curl\/curl\/.*\/(\d+)/) {
  93. # return the plain number
  94. return $1;
  95. }
  96. else {
  97. # return the URL
  98. return $ref;
  99. }
  100. }
  101. my $short;
  102. my $first;
  103. for my $l (@gitlog) {
  104. chomp $l;
  105. if($l =~ /^commit/) {
  106. if($first) {
  107. onecommit($short);
  108. }
  109. # starts a new commit
  110. undef @fixes;
  111. undef @closes;
  112. undef @bug;
  113. $short = "";
  114. $first = 0;
  115. }
  116. elsif(($l =~ /^ (.*)/) && !$first) {
  117. # first line
  118. $short = $1;
  119. $first = 1;
  120. push @line, $short;
  121. }
  122. elsif(($l =~ /^ (.*)/) && $first) {
  123. # not the first
  124. my $line = $1;
  125. if($line =~ /^Fixes(:|) *(.*)/i) {
  126. push @fixes, extract($2);
  127. }
  128. elsif($line =~ /^Clo(s|)es(:|) *(.*)/i) {
  129. push @closes, extract($3);
  130. }
  131. elsif($line =~ /^Bug: (.*)/i) {
  132. push @bug, extract($1);
  133. }
  134. }
  135. }
  136. if($first) {
  137. onecommit($short);
  138. }
  139. # call at the end of a parsed commit
  140. sub onecommit {
  141. my ($short)=@_;
  142. my $ref;
  143. if($bug[0]) {
  144. $ref = $bug[0];
  145. }
  146. elsif($fixes[0]) {
  147. $ref = $fixes[0];
  148. }
  149. elsif($closes[0]) {
  150. $ref = $closes[0];
  151. }
  152. if($ref =~ /^#?(\d+)/) {
  153. $ref = "https://curl.se/bug/?i=$1"
  154. }
  155. if($ref) {
  156. my $r = getref();
  157. $refs[$r] = $ref;
  158. $moreinfo{$short}=$r;
  159. $refused[$r] |= 1;
  160. }
  161. }
  162. #### Output the new RELEASE-NOTES
  163. my @bullets;
  164. for my $l (@releasenotes) {
  165. if(($l =~ /^This release includes the following bugfixes:/) && !$cleanup) {
  166. push @o, $l;
  167. push @o, "\n";
  168. for my $f (@line) {
  169. push @o, sprintf " o %s%s\n", $f,
  170. $moreinfo{$f}? sprintf(" [%d]", $moreinfo{$f}): "";
  171. $refused[$moreinfo{$f}]=3;
  172. }
  173. push @o, " --- new entries are listed above this ---";
  174. next;
  175. }
  176. elsif($cleanup) {
  177. if($l =~ /^ --- new entries are listed/) {
  178. # ignore this if still around
  179. next;
  180. }
  181. elsif($l =~ /^ o .*/) {
  182. push @bullets, $l;
  183. next;
  184. }
  185. elsif($bullets[0]) {
  186. # output them case insensitively
  187. for my $b (sort { "\L$a" cmp "\L$b" } @bullets) {
  188. push @o, $b;
  189. }
  190. undef @bullets;
  191. }
  192. }
  193. if($l =~ /^ \[(\d+)\] = /) {
  194. # stop now
  195. last;
  196. }
  197. else {
  198. push @o, $l;
  199. }
  200. }
  201. my @srefs;
  202. my $ln;
  203. for my $n (1 .. $#refs) {
  204. my $r = $refs[$n];
  205. if($r && ($refused[$n] & 1)) {
  206. push @o, sprintf " [%d] = %s\n", $n, $r;
  207. }
  208. }
  209. open(O, ">RELEASE-NOTES");
  210. for my $l (@o) {
  211. print O $l;
  212. }
  213. close(O);
  214. exit;
  215. # Debug: show unused references
  216. for my $r (1 .. $#refs) {
  217. if($refused[$r] != 3) {
  218. printf "%s is %d!\n", $r, $refused[$r];
  219. }
  220. }