@@ -73,34 +73,41 @@ Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automati
7373''' ;
7474 github.appendStepSummary (markdownTable);
7575
76- final existingCommentId = await allowFailure (
77- github.findCommentId (
78- user: _githubActionsUser,
79- searchTerm: _publishBotTag,
80- ),
81- logError: print,
82- );
76+ await inLogGroup ('Preparing PR comment' , () async {
77+ final existingCommentId = await allowFailure (
78+ github.findCommentId (
79+ user: _githubActionsUser,
80+ searchTerm: _publishBotTag,
81+ ),
82+ logError: print,
83+ );
8384
84- if (existingCommentId != null ) {
85- final idFile = File ('./output/commentId' );
86- print ('''
85+ if (existingCommentId != null ) {
86+ final idFile = File ('./output/commentId' );
87+ print ('''
8788Saving existing comment id $existingCommentId to file ${idFile .path }''' );
88- await idFile.create (recursive: true );
89- await idFile.writeAsString (existingCommentId.toString ());
90- }
89+ await idFile.create (recursive: true );
90+ await idFile.writeAsString (existingCommentId.toString ());
91+ }
9192
92- if (results.hasSuccess || existingCommentId != null ) {
93- final description =
94- results.hasSuccess ? '$_publishBotDescription \n\n ' : '' ;
95- final commentText = '$_publishBotTag \n\n '
96- '$description '
97- '$markdownTable ' ;
98-
99- final commentFile = File ('./output/comment.md' );
100- print ('Saving comment markdown to file ${commentFile .path }' );
101- await commentFile.create (recursive: true );
102- await commentFile.writeAsString (commentText);
103- }
93+ if (results.hasSuccess || existingCommentId != null ) {
94+ final description =
95+ results.hasSuccess ? '$_publishBotDescription \n\n ' : '' ;
96+ final commentText = '$_publishBotTag \n\n '
97+ '$description '
98+ '$markdownTable ' ;
99+
100+ final commentFile = File ('./output/comment.md' );
101+ print ('Saving comment markdown to file ${commentFile .path }' );
102+ await commentFile.create (recursive: true );
103+ await commentFile.writeAsString (commentText);
104+ }
105+ });
106+
107+ // Print the release links last, outside of any group, so they are easy to
108+ // find in the log even if the PR comment can't be written.
109+ print ('' );
110+ print (results.describeForLog ());
104111
105112 if (results.hasError && exitCode == 0 ) {
106113 exitCode = 1 ;
@@ -111,7 +118,10 @@ Saving existing comment id $existingCommentId to file ${idFile.path}''');
111118
112119 Future <VerificationResults > verify (GithubApi github, {Pub ? pub}) async {
113120 final repo = Repository (directory);
114- final packages = repo.locatePackages (ignore: ignoredPackages);
121+ final packages = await inLogGroup (
122+ 'Locating packages' ,
123+ () => repo.locatePackages (ignore: ignoredPackages),
124+ );
115125
116126 final filesInPR = await allowFailure (
117127 github.listFilesForPR (directory, ignoredPackages),
@@ -128,121 +138,131 @@ Saving existing comment id $existingCommentId to file ${idFile.path}''');
128138 relevantFiles? .where ((f) => f.isInPackage (package)).toList ();
129139 final isAffected = packageFiles == null || packageFiles.isNotEmpty;
130140
131- final repoTag = repo.calculateRepoTag (package, tagPrefix: tagPrefix);
141+ final result = await inLogGroup (
142+ 'Validating package:${package .name } ${package .version }' ,
143+ () async {
144+ final result = await _verifyPackage (
145+ package,
146+ repo,
147+ github,
148+ pubClient,
149+ packageFiles: packageFiles,
150+ isAffected: isAffected,
151+ );
152+ print (result);
153+ return result;
154+ },
155+ );
156+ results.addResult (result);
157+ }
132158
133- print ('' );
134- print ('Validating $package :${package .name }' );
159+ if (pub == null ) {
160+ pubClient.close ();
161+ }
135162
136- print ('pubspec:' );
137- final pubspecVersion = package.pubspec.version? .toString ();
138- if (pubspecVersion == null ) {
139- final result = Result .fail (
140- package,
141- "no version specified (perhaps you need a' publish_to: none' entry?)" ,
142- isAffected: isAffected,
143- );
144- print (result);
145- results.addResult (result);
146- continue ;
147- }
148- print (' - version: $pubspecVersion ' );
163+ return results;
164+ }
149165
150- final changelogVersion = package.changelog.latestVersion;
151- print ('changelog:' );
152- print (package.changelog.describeLatestChanges.trimRight ());
166+ /// Validates a single [package] and returns the result.
167+ ///
168+ /// The [packageFiles] are the files in [package] modified by the PR, or
169+ /// `null` if the files in the PR could not be determined.
170+ Future <Result > _verifyPackage (
171+ Package package,
172+ Repository repo,
173+ GithubApi github,
174+ Pub pubClient, {
175+ required List <GitFile >? packageFiles,
176+ required bool isAffected,
177+ }) async {
178+ print ('pubspec:' );
179+ final pubspecVersion = package.pubspec.version? .toString ();
180+ if (pubspecVersion == null ) {
181+ return Result .fail (
182+ package,
183+ "no version specified (perhaps you need a' publish_to: none' entry?)" ,
184+ isAffected: isAffected,
185+ );
186+ }
187+ print (' - version: $pubspecVersion ' );
153188
154- if (pubspecVersion != changelogVersion) {
155- final result = Result .fail (
156- package,
157- 'pubspec version ($pubspecVersion ) and changelog ($changelogVersion ) '
158- "don't agree" ,
159- isAffected: isAffected,
160- );
161- print (result);
162- results.addResult (result);
163- continue ;
164- }
189+ final changelogVersion = package.changelog.latestVersion;
190+ print ('changelog:' );
191+ print (package.changelog.describeLatestChanges.trimRight ());
165192
166- if (await pubClient.hasPublishedVersion (package.name, pubspecVersion)) {
167- final hasNonChangelogChanges = packageFiles != null &&
168- packageFiles.any (
169- (f) =>
170- ! path.equals (
171- f.pathInRepository,
172- package.changelog.file.path,
173- ) &&
174- ! path.split (f.filename).contains ('.github' ),
175- );
176- if (hasNonChangelogChanges &&
177- ! github.prLabels.contains (_ignoreWarningsLabel)) {
178- final result = Result .fail (
179- package,
180- 'version $pubspecVersion is already published at pub.dev; '
181- 'bump to a `-wip` version (or add the `$_ignoreWarningsLabel ` '
182- 'label to ignore)' ,
183- isAffected: isAffected,
184- );
185- print (result);
186- results.addResult (result);
187- } else {
188- final result = Result .info (
189- package,
190- Result .alreadyPublishedMessage,
191- isAffected: isAffected,
193+ if (pubspecVersion != changelogVersion) {
194+ return Result .fail (
195+ package,
196+ 'pubspec version ($pubspecVersion ) and changelog ($changelogVersion ) '
197+ "don't agree" ,
198+ isAffected: isAffected,
199+ );
200+ }
201+
202+ if (await pubClient.hasPublishedVersion (package.name, pubspecVersion)) {
203+ final hasNonChangelogChanges = packageFiles != null &&
204+ packageFiles.any (
205+ (f) =>
206+ ! path.equals (
207+ f.pathInRepository,
208+ package.changelog.file.path,
209+ ) &&
210+ ! path.split (f.filename).contains ('.github' ),
192211 );
193- print (result);
194- results.addResult (result);
195- }
196- } else if (package.pubspec.version! .wip) {
197- final result = Result .info (
212+ if (hasNonChangelogChanges &&
213+ ! github.prLabels.contains (_ignoreWarningsLabel)) {
214+ return Result .fail (
198215 package,
199- Result .wipMessage,
216+ 'version $pubspecVersion is already published at pub.dev; '
217+ 'bump to a `-wip` version (or add the `$_ignoreWarningsLabel ` '
218+ 'label to ignore)' ,
200219 isAffected: isAffected,
201220 );
202- print (result);
203- results.addResult (result);
204- } else {
205- const preReleaseText =
206- 'consider publishing the package as a pre-release instead' ;
207-
208- final result = await _runPublish (package, dryRun: true , force: false );
209-
210- final hasPreReleaseText = result.stdout.contains (preReleaseText);
211- final hasWarningsLabel = github.prLabels.contains (_ignoreWarningsLabel);
212- final ignoreWarnings = hasPreReleaseText || hasWarningsLabel;
213-
214- if (result.code != 0 && ! ignoreWarnings) {
215- exitCode = result.code;
216- final message =
217- 'pub publish dry-run failed; add the `$_ignoreWarningsLabel ` '
218- 'label to ignore' ;
219- github.notice (message: message);
220- results.addResult (
221- Result .fail (package, message, isAffected: isAffected),
222- );
223- } else {
224- final result = Result .success (
225- package,
226- '**ready to publish**' ,
227- gitTag: repoTag,
228- publishReleaseUri: repo.calculateReleaseUri (
229- package,
230- github,
231- tagPrefix: tagPrefix,
232- ),
233- isAffected: isAffected,
234- );
235- print (result);
236- results.addResult (result);
237- }
238221 }
222+ return Result .info (
223+ package,
224+ Result .alreadyPublishedMessage,
225+ isAffected: isAffected,
226+ );
239227 }
240228
241- if (pub == null ) {
242- pubClient.close ();
229+ if (package.pubspec.version! .wip) {
230+ return Result .info (
231+ package,
232+ Result .wipMessage,
233+ isAffected: isAffected,
234+ );
243235 }
244236
245- return results;
237+ const preReleaseText =
238+ 'consider publishing the package as a pre-release instead' ;
239+
240+ final result = await _runPublish (package, dryRun: true , force: false );
241+
242+ final hasPreReleaseText = result.stdout.contains (preReleaseText);
243+ final hasWarningsLabel = github.prLabels.contains (_ignoreWarningsLabel);
244+ final ignoreWarnings = hasPreReleaseText || hasWarningsLabel;
245+
246+ if (result.code != 0 && ! ignoreWarnings) {
247+ exitCode = result.code;
248+ final message =
249+ 'pub publish dry-run failed; add the `$_ignoreWarningsLabel ` '
250+ 'label to ignore' ;
251+ github.notice (message: message);
252+ return Result .fail (package, message, isAffected: isAffected);
253+ }
254+
255+ return Result .success (
256+ package,
257+ '**ready to publish**' ,
258+ gitTag: repo.calculateRepoTag (package, tagPrefix: tagPrefix),
259+ publishReleaseUri: repo.calculateReleaseUri (
260+ package,
261+ github,
262+ tagPrefix: tagPrefix,
263+ ),
264+ isAffected: isAffected,
265+ );
246266 }
247267
248268 /// Publish the indicated package in the repository.
@@ -276,12 +296,15 @@ Saving existing comment id $existingCommentId to file ${idFile.path}''');
276296 print ('' );
277297
278298 final repo = Repository ();
279- final packages = repo.locatePackages ();
280- print ('' );
281- print ('Repository packages:' );
282- for (final package in packages) {
283- print (' $package ' );
284- }
299+ final packages = await inLogGroup ('Locating packages' , () {
300+ final packages = repo.locatePackages ();
301+ print ('' );
302+ print ('Repository packages:' );
303+ for (final package in packages) {
304+ print (' $package ' );
305+ }
306+ return packages;
307+ });
285308 print ('' );
286309
287310 // Find package to publish.
@@ -424,6 +447,45 @@ class VerificationResults {
424447
425448 return buffer.toString ().trimRight ();
426449 }
450+
451+ /// A plain text description of the results which need action, for the end
452+ /// of the workflow log.
453+ ///
454+ /// Lists any errors, and the links to create a GitHub release for each
455+ /// package which is ready to publish.
456+ String describeForLog () {
457+ final buffer = StringBuffer ();
458+
459+ final errors = results.where ((r) => r.severity == Severity .error);
460+ if (errors.isNotEmpty) {
461+ buffer.writeln ('Packages with errors:' );
462+ for (final r in errors) {
463+ buffer.writeln (' package:${r .package .name } ${r .package .version }: '
464+ '${r .message }' );
465+ }
466+ buffer.writeln ();
467+ }
468+
469+ final ready = results.where ((r) => r.severity == Severity .success);
470+ if (ready.isEmpty) {
471+ buffer.writeln ('No packages are ready to publish.' );
472+ } else {
473+ buffer
474+ ..writeln ('Packages ready to publish:' )
475+ ..writeln (_publishBotDescription)
476+ ..writeln ();
477+ for (final r in ready) {
478+ final tag = r.gitTag == null ? '' : ' (${r .gitTag })' ;
479+ buffer.writeln (' package:${r .package .name } ${r .package .version }$tag ' );
480+ final publishReleaseUri = r.publishReleaseUri;
481+ if (publishReleaseUri != null ) {
482+ buffer.writeln (' $publishReleaseUri ' );
483+ }
484+ }
485+ }
486+
487+ return buffer.toString ().trimRight ();
488+ }
427489}
428490
429491class Result {
0 commit comments