@@ -157,6 +157,12 @@ class VersionCheckCommand extends PackageLoopingCommand {
157157
158158 late final Set <String > _prLabels = _getPRLabels ();
159159
160+ Future <String > _getRelativePackagePath (RepositoryPackage package) async {
161+ final Directory gitRoot =
162+ packagesDir.fileSystem.directory ((await gitDir).path);
163+ return getRelativePosixPath (package.directory, from: gitRoot);
164+ }
165+
160166 @override
161167 final String name = 'version-check' ;
162168
@@ -211,33 +217,35 @@ class VersionCheckCommand extends PackageLoopingCommand {
211217 bool versionChanged;
212218
213219 if (usesBatchRelease && ! hasPostReleaseLabel) {
214- final List <String > changedFiles =
215- await _gitVersionFinder.getChangedFiles ();
220+ final String relativePackagePath = await _getRelativePackagePath (package);
221+ final List <String > changedFilesInPackage = changedFiles
222+ .where ((String path) => path.startsWith (relativePackagePath))
223+ .toList ();
224+
216225 // For batch release, we only check pending changelog files.
217- final List <PendingChangelogEntry > allChangelogs =
218- < PendingChangelogEntry > [];
226+ final List <PendingChangelogEntry > allChangelogs;
219227 try {
220- allChangelogs. addAll ( package.getPendingChangelogs () );
228+ allChangelogs = package.getPendingChangelogs ();
221229 } on FormatException catch (e) {
222230 errors.add (e.message);
223231 return PackageResult .fail (errors);
224232 }
225233
226234 final List <PendingChangelogEntry > newEntries = allChangelogs
227235 .where ((PendingChangelogEntry entry) =>
228- changedFiles .contains (entry.file.path))
236+ changedFilesInPackage .contains (entry.file.path))
229237 .toList ();
230238 versionChanged = newEntries.any (
231239 (PendingChangelogEntry entry) => entry.version != VersionChange .skip);
232240
233241 // The changelog.md and pubspec.yaml's version should not be updated directly.
234- if (changedFiles .contains (package.changelogFile.path )) {
242+ if (changedFilesInPackage .contains ('$ relativePackagePath /CHANGELOG.md' )) {
235243 printError (
236244 'This package uses batch release, so CHANGELOG.md should not be changed directly.\n '
237245 'Instead, create a pending changelog file in pending_changelogs folder.' );
238246 errors.add ('CHANGELOG.md changed' );
239247 }
240- if (changedFiles .contains (package.pubspecFile.path )) {
248+ if (changedFilesInPackage .contains ('$ relativePackagePath /pubspec.yaml' )) {
241249 if (versionState != _CurrentVersionState .unchanged) {
242250 printError (
243251 'This package uses batch release, so the version in pubspec.yaml should not be changed directly.\n '
@@ -577,10 +585,7 @@ ${indentation}The first version listed in CHANGELOG.md is $fromChangeLog.
577585 // Find the relative path to the current package, as it would appear at the
578586 // beginning of a path reported by changedFiles (which always uses
579587 // Posix paths).
580- final Directory gitRoot =
581- packagesDir.fileSystem.directory ((await gitDir).path);
582- final String relativePackagePath =
583- getRelativePosixPath (package.directory, from: gitRoot);
588+ final String relativePackagePath = await _getRelativePackagePath (package);
584589
585590 final PackageChangeState state = await checkPackageChangeState (package,
586591 changedPaths: changedFiles,
@@ -594,7 +599,13 @@ ${indentation}The first version listed in CHANGELOG.md is $fromChangeLog.
594599 bool missingVersionChange = false ;
595600 bool missingChangelogChange = false ;
596601 if (state.needsVersionChange) {
597- if (_prLabels.contains (_missingVersionChangeOverrideLabel)) {
602+ final bool isBatchRelease =
603+ package.parseCiConfig ()? .isBatchRelease ?? false ;
604+ if (isBatchRelease && state.hasChangelogChange) {
605+ // Batch release packages are not supposed to have version changes, so
606+ // if there is a changelog change (which for batch release means a
607+ // pending changelog entry), that is sufficient.
608+ } else if (_prLabels.contains (_missingVersionChangeOverrideLabel)) {
598609 logWarning ('Ignoring lack of version change due to the '
599610 '"$_missingVersionChangeOverrideLabel " label.' );
600611 } else {
0 commit comments