-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: update dependencies with script (#369)
- Loading branch information
1 parent
a62c9d0
commit c696842
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright 2024, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:convert'; | ||
import 'dart:io'; | ||
import 'package:path/path.dart' as p; | ||
import 'package:yaml/yaml.dart'; | ||
import 'package:yaml_edit/yaml_edit.dart'; | ||
|
||
Future<void> main(List<String> args) async { | ||
const bomPath = | ||
'https://raw.githubusercontent.com/firebase/flutterfire/master/scripts/versions.json'; | ||
final http = HttpClient(); | ||
final request = await http.getUrl(Uri.parse(bomPath)); | ||
final response = await request.close(); // sends the request | ||
final jsonString = await response.transform(utf8.decoder).join(); | ||
final json = jsonDecode(jsonString) as Map<String, dynamic>; | ||
|
||
final latestVersions = | ||
json[json.keys.first]["packages"] as Map<String, dynamic>; | ||
|
||
final iosSdkVersion = json[json.keys.first]["firebase_sdk"]["ios"] as String; | ||
|
||
final pubspecFilePaths = findPubspecFiles(Directory.current); | ||
|
||
final listOfFutures = <Future>[]; | ||
for (final filePath in pubspecFilePaths) { | ||
final future = updatePubspecFile(filePath, latestVersions); | ||
listOfFutures.add(future); | ||
} | ||
|
||
listOfFutures.add( | ||
updatePodfileVersion( | ||
iosSdkVersion, | ||
'./tests/ios/Podfile', | ||
), | ||
); | ||
listOfFutures.add( | ||
updatePodfileVersion( | ||
iosSdkVersion, | ||
'./tests/macos/Podfile', | ||
), | ||
); | ||
|
||
await Future.wait(listOfFutures); | ||
|
||
print( | ||
'All dependencies updated, please double check they are the latest, commit and push the changes.', | ||
); | ||
} | ||
|
||
Future<void> updatePubspecFile( | ||
String filePath, | ||
Map<String, dynamic> latestVersions, | ||
) async { | ||
final content = await File(filePath).readAsString(); | ||
final yamlEditor = YamlEditor(content); | ||
final pubspec = loadYaml(content) as YamlMap; | ||
|
||
final dependencies = pubspec['dependencies'] as YamlMap?; | ||
|
||
if (dependencies != null) { | ||
dependencies.forEach((key, value) { | ||
if (latestVersions.containsKey(key)) { | ||
yamlEditor.update(['dependencies', key], '^${latestVersions[key]}'); | ||
} | ||
}); | ||
} | ||
|
||
await File(filePath).writeAsString(yamlEditor.toString()); | ||
} | ||
|
||
List<String> findPubspecFiles(Directory root) { | ||
final pubspecFiles = <String>[]; | ||
final directories = [ | ||
Directory(p.join(root.path, 'packages')), | ||
Directory(p.join(root.path, 'tests')) | ||
]; | ||
|
||
for (final dir in directories) { | ||
if (dir.existsSync()) { | ||
dir.listSync(recursive: true).forEach((entity) { | ||
if (entity is File && p.basename(entity.path) == 'pubspec.yaml') { | ||
if (!entity.path.contains('.symlinks') && | ||
!entity.path.contains('.plugin_symlinks')) { | ||
pubspecFiles.add(entity.path); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
return pubspecFiles; | ||
} | ||
|
||
Future<void> updatePodfileVersion( | ||
String iosSdkVersion, | ||
String podfilePath, | ||
) async { | ||
final podfile = File(podfilePath); | ||
if (!await podfile.exists()) { | ||
throw Exception('Podfile not found at $podfilePath'); | ||
} | ||
|
||
String content = await podfile.readAsString(); | ||
|
||
final updatedContent = content.replaceAllMapped( | ||
RegExp( | ||
r"pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '\d+\.\d+\.\d+'"), | ||
(match) => | ||
"pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '$iosSdkVersion'", | ||
); | ||
|
||
await podfile.writeAsString(updatedContent); | ||
|
||
print( | ||
'Updated Podfile Firestore framework on path: $podfilePath to version: $iosSdkVersion'); | ||
} |