execute method
Executes the release workflow represented by this strategy.
Implementation
@override
Future<ReleaseResult> execute(ReleaseContext context) async {
final steps = <String>[
'Initialized ReleaseContext',
'Selected ShorebirdPatchStrategy',
];
// 1. Tool Check
final toolCheck = await _toolValidator.validate(context);
if (toolCheck.isFailed) {
return ReleaseResult.failure(
type: type,
message: 'Shorebird tool check failed.',
errors: [toolCheck.message],
);
}
steps.add(toolCheck.message);
// 2. Project Config Check
final projectCheck = await _projectValidator.validate(context);
if (projectCheck.isFailed) {
return ReleaseResult.failure(
type: type,
message: 'Shorebird project check failed.',
errors: [projectCheck.message],
);
}
steps.add(projectCheck.message);
// 3. Patch Change Analysis & Safety Evaluation
steps.add('Analyzing repository changes for patch eligibility...');
final PatchEligibilityResult eligibility =
await _changeAnalyzer.analyzeWorkingTree(context.projectPath);
if (!eligibility.isEligible) {
return ReleaseResult.failure(
type: type,
message: 'Shorebird patch safety evaluation failed.',
executedSteps: steps,
errors: [
eligibility.explanation,
...eligibility.blockers,
],
warnings: eligibility.warnings,
);
}
steps.add('Patch eligibility check passed: ${eligibility.explanation}');
final platformStr = context.targetPlatform ?? 'android';
final platform = BuildPlatform.parse(platformStr);
String? targetReleaseVersion;
if (context.versionName != null && context.buildNumber != null) {
targetReleaseVersion = '${context.versionName}+${context.buildNumber}';
}
if (platform == BuildPlatform.all) {
return _executeAllPlatforms(
context, steps, targetReleaseVersion, eligibility);
}
steps.add('Executing Shorebird patch for platform $platform...');
final cmdResult = await _shorebirdClient.executePatch(
projectPath: context.projectPath,
platform: platform,
dryRun: context.dryRun,
releaseVersion: targetReleaseVersion,
);
steps.addAll(cmdResult.executedSteps);
if (!cmdResult.success) {
return ReleaseResult.failure(
type: type,
message: 'Shorebird patch execution failed for $platform.',
executedSteps: steps,
errors: cmdResult.errors,
warnings: eligibility.warnings,
);
}
if (context.dryRun) {
return ReleaseResult.success(
type: type,
message: '[DRY-RUN] Shorebird Patch preview completed successfully.',
versionName: context.versionName,
buildNumber: context.buildNumber,
targetPlatform: platformStr,
executedSteps: steps,
warnings: eligibility.warnings,
metadata: {
'dryRun': true,
'command': cmdResult.commandString,
'eligibility': eligibility,
},
);
}
return ReleaseResult.success(
type: type,
message: 'Shorebird patch applied successfully.',
versionName: context.versionName,
buildNumber: context.buildNumber,
targetPlatform: platformStr,
executedSteps: steps,
warnings: eligibility.warnings,
metadata: {
'command': cmdResult.commandString,
'eligibility': eligibility,
},
);
}