validate method
Implementation
@override
Future<ValidationCheck> validate(ReleaseContext context) async {
final envName = context.config.environmentName ??
context.environment['ENVIRONMENT'] ??
context.environment['ENV'];
if (envName == null || envName.isEmpty) {
return ValidationCheck(
name: name,
status: CheckStatus.passed,
message: 'No target environment specified (default fallback)',
);
}
final target = TargetEnvironment.parse(envName);
final flavor = context.config.flavor ?? context.environment['FLAVOR'];
// 1. Mismatch check between environment and flavor
if (flavor != null && flavor.isNotEmpty) {
final normalizedFlavor = flavor.toLowerCase();
if (target == TargetEnvironment.production &&
(normalizedFlavor.contains('dev') ||
normalizedFlavor.contains('stg') ||
normalizedFlavor.contains('stage'))) {
return ValidationCheck(
name: name,
status: CheckStatus.failed,
message:
'Environment mismatch: Cannot run production environment with non-production flavor "$flavor".',
);
}
if (target == TargetEnvironment.development &&
(normalizedFlavor.contains('prod') ||
normalizedFlavor.contains('release'))) {
return ValidationCheck(
name: name,
status: CheckStatus.failed,
message:
'Environment mismatch: Cannot run development environment with production flavor "$flavor".',
);
}
}
// 2. Shorebird Patch environment safety check
if (context.type == ReleaseType.shorebirdPatch) {
if (target == TargetEnvironment.development) {
return ValidationCheck(
name: name,
status: CheckStatus.warning,
message:
'Applying Shorebird patch targeting development environment.',
details: 'Verify target release ID before deploying.',
);
}
}
return ValidationCheck(
name: name,
status: CheckStatus.passed,
message:
'Target environment "${target.name}" valid${flavor != null ? ' (Flavor: $flavor)' : ''}',
);
}