release-notes.pl 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. $short =~ s/ ?\[(ci skip|skip ci)\]//g;
  120. $first = 1;
  121. push @line, $short;
  122. }
  123. elsif(($l =~ /^ (.*)/) && $first) {
  124. # not the first
  125. my $line = $1;
  126. if($line =~ /^Fixes(:|) *(.*)/i) {
  127. push @fixes, extract($2);
  128. }
  129. elsif($line =~ /^Clo(s|)es(:|) *(.*)/i) {
  130. push @closes, extract($3);
  131. }
  132. elsif($line =~ /^Bug: (.*)/i) {
  133. push @bug, extract($1);
  134. }
  135. }
  136. }
  137. if($first) {
  138. onecommit($short);
  139. }
  140. # call at the end of a parsed commit
  141. sub onecommit {
  142. my ($short)=@_;
  143. my $ref;
  144. if($bug[0]) {
  145. $ref = $bug[0];
  146. }
  147. elsif($fixes[0]) {
  148. $ref = $fixes[0];
  149. }
  150. elsif($closes[0]) {
  151. $ref = $closes[0];
  152. }
  153. if($ref =~ /^#?(\d+)/) {
  154. $ref = "https://curl.se/bug/?i=$1"
  155. }
  156. if($ref) {
  157. my $r = getref();
  158. $refs[$r] = $ref;
  159. $moreinfo{$short}=$r;
  160. $refused[$r] |= 1;
  161. }
  162. }
  163. #### Output the new RELEASE-NOTES
  164. my @bullets;
  165. for my $l (@releasenotes) {
  166. if(($l =~ /^This release includes the following bugfixes:/) && !$cleanup) {
  167. push @o, $l;
  168. push @o, "\n";
  169. for my $f (@line) {
  170. push @o, sprintf " o %s%s\n", $f,
  171. $moreinfo{$f}? sprintf(" [%d]", $moreinfo{$f}): "";
  172. $refused[$moreinfo{$f}]=3;
  173. }
  174. push @o, " --- new entries are listed above this ---";
  175. next;
  176. }
  177. elsif($cleanup) {
  178. if($l =~ /^ --- new entries are listed/) {
  179. # ignore this if still around
  180. next;
  181. }
  182. elsif($l =~ /^ o .*/) {
  183. push @bullets, $l;
  184. next;
  185. }
  186. elsif($bullets[0]) {
  187. # output them case insensitively
  188. for my $b (sort { "\L$a" cmp "\L$b" } @bullets) {
  189. push @o, $b;
  190. }
  191. undef @bullets;
  192. }
  193. }
  194. if($l =~ /^ \[(\d+)\] = /) {
  195. # stop now
  196. last;
  197. }
  198. else {
  199. push @o, $l;
  200. }
  201. }
  202. my @srefs;
  203. my $ln;
  204. for my $n (1 .. $#refs) {
  205. my $r = $refs[$n];
  206. if($r && ($refused[$n] & 1)) {
  207. push @o, sprintf " [%d] = %s\n", $n, $r;
  208. }
  209. }
  210. open(O, ">RELEASE-NOTES");
  211. for my $l (@o) {
  212. print O $l;
  213. }
  214. close(O);
  215. exit;
  216. # Debug: show unused references
  217. for my $r (1 .. $#refs) {
  218. if($refused[$r] != 3) {
  219. printf "%s is %d!\n", $r, $refused[$r];
  220. }
  221. }