@@ -68,7 +68,6 @@ class ReleaseNotesCommand extends Command {
6868 CliCommand .git (['stash' ]),
6969 CliCommand .git (['checkout' , 'main' ]),
7070 CliCommand .git (['pull' ]),
71- CliCommand .git (['submodule' , 'update' , '--init' , '--recursive' ]),
7271 CliCommand .git ([
7372 'checkout' ,
7473 '-b' ,
@@ -114,7 +113,7 @@ class ReleaseNotesCommand extends Command {
114113 ),
115114 )..createSync ();
116115
117- final srcLines = devToolsReleaseNotes.srcLines ;
116+ final srcLines = devToolsReleaseNotes.sourceLines ;
118117
119118 // Copy release notes images and fix image reference paths.
120119 if (devToolsReleaseNotes.imageLineIndices.isNotEmpty) {
@@ -142,19 +141,19 @@ class ReleaseNotesCommand extends Command {
142141 }
143142 }
144143
145- final metadataHeader = '''---
144+ releaseNotesMd. writeAsStringSync ( '''---
146145title: DevTools $releaseNotesVersion release notes
147146shortTitle: $releaseNotesVersion release notes
148147breadcrumb: $releaseNotesVersion
149148showToc: false
150149---
151150
152- ''' ;
151+ ''' ) ;
153152
154- // Write the 'release-notes-<x.y.z>.md' file, including any updates for
155- // image paths.
153+ // Write the contents of the 'release-notes-<x.y.z>.md' file,
154+ // including any updates for image paths.
156155 releaseNotesMd.writeAsStringSync (
157- metadataHeader + srcLines.joinWithNewLine (),
156+ srcLines.joinWithNewLine (). trimLeft (),
158157 flush: true ,
159158 );
160159
@@ -178,7 +177,7 @@ class _DevToolsReleaseNotes {
178177 _DevToolsReleaseNotes ._({
179178 required this .file,
180179 required this .version,
181- required this .srcLines ,
180+ required this .sourceLines ,
182181 required this .imageLineIndices,
183182 });
184183
@@ -192,8 +191,8 @@ class _DevToolsReleaseNotes {
192191
193192 final rawLines = file.readAsLinesSync ();
194193
195- late String version;
196- late int titleLineIndex ;
194+ String ? version;
195+ int ? sourceStartIndex ;
197196 final versionRegExp = RegExp (r"\d+\.\d+\.\d+" );
198197 for (int i = 0 ; i < rawLines.length; i++ ) {
199198 final line = rawLines[i];
@@ -202,17 +201,34 @@ class _DevToolsReleaseNotes {
202201 // This match should be from the line "# DevTools <x.y.z> release notes".
203202 version = matches.first.group (0 )! ;
204203 // This is the markdown title where the release notes src begins.
205- titleLineIndex = i;
204+ sourceStartIndex = i + 1 ;
206205 break ;
207206 }
208207
208+ if (version == null || sourceStartIndex == null ) {
209+ throw Exception (
210+ 'Could not find the title line ("# DevTools x.y.z release notes") '
211+ 'in the NEXT_RELEASE_NOTES.md file.' ,
212+ );
213+ }
214+
215+ if (sourceStartIndex >= rawLines.length) {
216+ throw Exception (
217+ 'No content found after the title line ("# DevTools x.y.z release notes") '
218+ 'in the NEXT_RELEASE_NOTES.md file.' ,
219+ );
220+ }
221+
222+ // Don't include the copyright, draft notice, or h1 header in
223+ // the output release notes.
224+ final sourceLines = rawLines.sublist (sourceStartIndex);
225+
209226 // TODO(kenz): one nice polish task could be to remove sections that are
210227 // empty (i.e. sections that have the line
211228 // "TODO: Remove this section if there are not any updates.").
212- final srcLines = rawLines.sublist (titleLineIndex);
213229 final imageLineIndices = < int > {};
214- for (int i = 0 ; i < srcLines .length; i++ ) {
215- final line = srcLines [i];
230+ for (int i = 0 ; i < sourceLines .length; i++ ) {
231+ final line = sourceLines [i];
216232 if (line.contains (_imagePathMarker)) {
217233 imageLineIndices.add (i);
218234 }
@@ -221,14 +237,14 @@ class _DevToolsReleaseNotes {
221237 return _DevToolsReleaseNotes ._(
222238 file: file,
223239 version: version,
224- srcLines : srcLines ,
240+ sourceLines : sourceLines ,
225241 imageLineIndices: imageLineIndices,
226242 );
227243 }
228244
229245 final File file;
230246 final String version;
231- final List <String > srcLines ;
247+ final List <String > sourceLines ;
232248 final Set <int > imageLineIndices;
233249
234250 static final _imagePathMarker = RegExp (r'images\/.*\.png' );
0 commit comments