fix: choose newest xcarchive in ios release (#2577)
Co-authored-by: Eric Seidel <eric@shorebird.dev>
This commit is contained in:
@@ -104,6 +104,7 @@ words:
|
||||
- vmcode
|
||||
- writeln
|
||||
- xcarchive
|
||||
- xcarchives
|
||||
- xcframework
|
||||
- xcodebuild
|
||||
- xcodeproj
|
||||
|
||||
@@ -282,6 +282,15 @@ class ArtifactManager {
|
||||
return archiveDirectory
|
||||
.listSync()
|
||||
.whereType<Directory>()
|
||||
// Get the most recently modified xcarchive to handle cases where an app
|
||||
// may produce multiple xcarchives with different names.
|
||||
// This still could grab the wrong ipa, if multiple `flutter` commands
|
||||
// are running in parallel or the clock is/was broken on the machine.
|
||||
// If either of those occurs in the wild we can check the contents of
|
||||
// the xcarchives, but this should be good enough for now.
|
||||
.sorted(
|
||||
(a, b) => b.statSync().modified.compareTo(a.statSync().modified),
|
||||
)
|
||||
.firstWhereOrNull((directory) => directory.path.endsWith('.xcarchive'));
|
||||
}
|
||||
|
||||
|
||||
@@ -593,6 +593,66 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group(
|
||||
'when multiple xcarchive directories exist',
|
||||
() {
|
||||
late Directory oldArchiveDirectory;
|
||||
late Directory newArchiveDirectory;
|
||||
|
||||
setUp(() async {
|
||||
oldArchiveDirectory = Directory(
|
||||
p.join(
|
||||
projectRoot.path,
|
||||
'build',
|
||||
'ios',
|
||||
'archive',
|
||||
'Runner.xcarchive',
|
||||
),
|
||||
)..createSync(recursive: true);
|
||||
// Wait to ensure the new archive directory is created after the old
|
||||
// archive directory.
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
newArchiveDirectory = Directory(
|
||||
p.join(
|
||||
projectRoot.path,
|
||||
'build',
|
||||
'ios',
|
||||
'archive',
|
||||
'Runner2.xcarchive',
|
||||
),
|
||||
)..createSync(recursive: true);
|
||||
});
|
||||
|
||||
test('selects the most recently updated xcarchive', () async {
|
||||
final firstResult = runWithOverrides(
|
||||
() => artifactManager.getXcarchiveDirectory(),
|
||||
);
|
||||
// The new archive directory should be selected because it was created
|
||||
// after the old archive directory.
|
||||
expect(firstResult!.path, equals(newArchiveDirectory.path));
|
||||
|
||||
// Now recreate the old archive directory and ensure it is selected.
|
||||
oldArchiveDirectory.deleteSync(recursive: true);
|
||||
oldArchiveDirectory = Directory(
|
||||
p.join(
|
||||
projectRoot.path,
|
||||
'build',
|
||||
'ios',
|
||||
'archive',
|
||||
'Runner.xcarchive',
|
||||
),
|
||||
)..createSync(recursive: true);
|
||||
final secondResult = runWithOverrides(
|
||||
() => artifactManager.getXcarchiveDirectory(),
|
||||
);
|
||||
expect(secondResult!.path, equals(oldArchiveDirectory.path));
|
||||
});
|
||||
},
|
||||
onPlatform: {
|
||||
'windows': const Skip('Flaky on Windows'),
|
||||
},
|
||||
);
|
||||
|
||||
group('when archive directory does not exist', () {
|
||||
test('returns null', () {
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user