Skip to content

ci(swift): use PR branch to test swift integration rather than version #17460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/all_plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/scripts/swift-integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,91 @@ void main(List<String> 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<String> 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<void> updatePackageSwiftFiles(String branch, List<String> 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<void> 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<void> buildSwiftExampleApp(String platform, String plugins) async {
final initialDirectory = Directory.current;
final platformName = platform == 'ios' ? 'iOS' : 'macOS';
Expand Down
Loading