diff --git a/.github/workflows/all_plugins.yaml b/.github/workflows/all_plugins.yaml index 75c3496fbe95..43ceb16bafd0 100644 --- a/.github/workflows/all_plugins.yaml +++ b/.github/workflows/all_plugins.yaml @@ -131,8 +131,7 @@ jobs: - uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 - uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff with: - # TODO - enabling swift is on `master` channel at the moment. Update when it's on `stable` - channel: 'master' + channel: 'stable' - name: Setup firebase_core example app to test Swift integration # run this before running melos boostrap to ensure the example app is set up run: | diff --git a/.github/workflows/scripts/swift-integration.dart b/.github/workflows/scripts/swift-integration.dart index b87f35ebfc26..38251294d6cd 100644 --- a/.github/workflows/scripts/swift-integration.dart +++ b/.github/workflows/scripts/swift-integration.dart @@ -9,11 +9,91 @@ void main(List arguments) async { if (arguments.isEmpty) { throw Exception('No FlutterFire dependency arguments provided.'); } + + // Get the current git branch from GitHub Actions environment or fallback to git command + final currentBranch = await getCurrentBranch(); + print('Current branch: $currentBranch'); + + // Update all Package.swift files to use branch dependencies + await updatePackageSwiftFiles(currentBranch, arguments); + final plugins = arguments.join(','); await buildSwiftExampleApp('ios', plugins); await buildSwiftExampleApp('macos', plugins); } +Future getCurrentBranch() async { + // Try GitHub Actions environment variables first + String? branch = Platform.environment['GITHUB_HEAD_REF']; // For pull requests + + if (branch == null || branch.isEmpty) { + branch = Platform.environment['GITHUB_REF_NAME']; // For direct pushes + } + + if (branch == null || branch.isEmpty) { + // Fallback to git command for local testing + print('GitHub Actions environment variables not found, trying git command...'); + final result = await Process.run('git', ['branch', '--show-current']); + if (result.exitCode != 0) { + throw Exception('Failed to get current git branch: ${result.stderr}'); + } + branch = result.stdout.toString().trim(); + } + + if (branch.isEmpty) { + throw Exception('Could not determine current branch from GitHub Actions environment or git command'); + } + + return branch; +} + +Future updatePackageSwiftFiles(String branch, List packages) async { + print('Updating Package.swift files to use branch: $branch'); + + // Update each package's Package.swift files + for (final package in packages) { + await updatePackageSwiftForPackage(package, branch); + } +} + +Future updatePackageSwiftForPackage(String packageName, String branch) async { + // Check both ios and macos directories + final platforms = ['ios', 'macos']; + + for (final platform in platforms) { + final packageSwiftPath = 'packages/$packageName/$packageName/$platform/$packageName/Package.swift'; + final file = File(packageSwiftPath); + + if (!file.existsSync()) { + print('Warning: Package.swift not found at $packageSwiftPath'); + continue; + } + + print('Updating $packageSwiftPath'); + final content = await file.readAsString(); + + // Replace exact version dependency with branch dependency + String updatedContent = content; + + // Pattern to match the exact version dependency + final exactVersionPattern = RegExp( + r'\.package\(url: "https://github\.com/firebase/flutterfire", exact: [^)]+\)', + multiLine: true + ); + + // Replace with branch dependency + final branchDependency = '.package(url: "https://github.com/firebase/flutterfire", branch: "$branch")'; + + if (exactVersionPattern.hasMatch(content)) { + updatedContent = content.replaceAll(exactVersionPattern, branchDependency); + await file.writeAsString(updatedContent); + print('✓ Updated $packageSwiftPath to use branch: $branch'); + } else { + print('⚠ No exact version dependency found in $packageSwiftPath'); + } + } +} + Future buildSwiftExampleApp(String platform, String plugins) async { final initialDirectory = Directory.current; final platformName = platform == 'ios' ? 'iOS' : 'macOS';