@@ -9,11 +9,91 @@ void main(List<String> arguments) async {
99 if (arguments.isEmpty) {
1010 throw Exception ('No FlutterFire dependency arguments provided.' );
1111 }
12+
13+ // Get the current git branch from GitHub Actions environment or fallback to git command
14+ final currentBranch = await getCurrentBranch ();
15+ print ('Current branch: $currentBranch ' );
16+
17+ // Update all Package.swift files to use branch dependencies
18+ await updatePackageSwiftFiles (currentBranch, arguments);
19+
1220 final plugins = arguments.join (',' );
1321 await buildSwiftExampleApp ('ios' , plugins);
1422 await buildSwiftExampleApp ('macos' , plugins);
1523}
1624
25+ Future <String > getCurrentBranch () async {
26+ // Try GitHub Actions environment variables first
27+ String ? branch = Platform .environment['GITHUB_HEAD_REF' ]; // For pull requests
28+
29+ if (branch == null || branch.isEmpty) {
30+ branch = Platform .environment['GITHUB_REF_NAME' ]; // For direct pushes
31+ }
32+
33+ if (branch == null || branch.isEmpty) {
34+ // Fallback to git command for local testing
35+ print ('GitHub Actions environment variables not found, trying git command...' );
36+ final result = await Process .run ('git' , ['branch' , '--show-current' ]);
37+ if (result.exitCode != 0 ) {
38+ throw Exception ('Failed to get current git branch: ${result .stderr }' );
39+ }
40+ branch = result.stdout.toString ().trim ();
41+ }
42+
43+ if (branch.isEmpty) {
44+ throw Exception ('Could not determine current branch from GitHub Actions environment or git command' );
45+ }
46+
47+ return branch;
48+ }
49+
50+ Future <void > updatePackageSwiftFiles (String branch, List <String > packages) async {
51+ print ('Updating Package.swift files to use branch: $branch ' );
52+
53+ // Update each package's Package.swift files
54+ for (final package in packages) {
55+ await updatePackageSwiftForPackage (package, branch);
56+ }
57+ }
58+
59+ Future <void > updatePackageSwiftForPackage (String packageName, String branch) async {
60+ // Check both ios and macos directories
61+ final platforms = ['ios' , 'macos' ];
62+
63+ for (final platform in platforms) {
64+ final packageSwiftPath = 'packages/$packageName /$packageName /$platform /$packageName /Package.swift' ;
65+ final file = File (packageSwiftPath);
66+
67+ if (! file.existsSync ()) {
68+ print ('Warning: Package.swift not found at $packageSwiftPath ' );
69+ continue ;
70+ }
71+
72+ print ('Updating $packageSwiftPath ' );
73+ final content = await file.readAsString ();
74+
75+ // Replace exact version dependency with branch dependency
76+ String updatedContent = content;
77+
78+ // Pattern to match the exact version dependency
79+ final exactVersionPattern = RegExp (
80+ r'\.package\(url: "https://github\.com/firebase/flutterfire", exact: [^)]+\)' ,
81+ multiLine: true
82+ );
83+
84+ // Replace with branch dependency
85+ final branchDependency = '.package(url: "https://github.com/firebase/flutterfire", branch: "$branch ")' ;
86+
87+ if (exactVersionPattern.hasMatch (content)) {
88+ updatedContent = content.replaceAll (exactVersionPattern, branchDependency);
89+ await file.writeAsString (updatedContent);
90+ print ('✓ Updated $packageSwiftPath to use branch: $branch ' );
91+ } else {
92+ print ('⚠ No exact version dependency found in $packageSwiftPath ' );
93+ }
94+ }
95+ }
96+
1797Future <void > buildSwiftExampleApp (String platform, String plugins) async {
1898 final initialDirectory = Directory .current;
1999 final platformName = platform == 'ios' ? 'iOS' : 'macOS' ;
0 commit comments