validate method

  1. @override
Future<ValidationCheck> validate(
  1. ReleaseContext context
)
override

Implementation

@override
Future<ValidationCheck> validate(ReleaseContext context) async {
  // Shorebird patches do not bump version
  if (context.type == ReleaseType.shorebirdPatch) {
    return ValidationCheck(
      name: name,
      status: CheckStatus.passed,
      message: 'Version safety skipped for Shorebird patch operation.',
    );
  }

  final history =
      await _metadataManager.getReleaseHistory(context.projectPath);
  final targetVer = context.versionName;
  final targetBuild = context.buildNumber?.toString();

  if (targetVer != null && targetBuild != null) {
    for (final past in history) {
      if (past.versionName == targetVer && past.buildNumber == targetBuild) {
        return ValidationCheck(
          name: name,
          status: CheckStatus.failed,
          message:
              'Version conflict: Version "$targetVer+$targetBuild" has already been released on ${past.timestamp}. Please bump version or build number.',
        );
      }
    }
  }

  return ValidationCheck(
    name: name,
    status: CheckStatus.passed,
    message: 'Target version is unique and valid.',
  );
}