generateWorkflows method

Future<WorkflowGenerationResult> generateWorkflows({
  1. required String projectPath,
  2. required CIConfig config,
})

Generate CI workflows for the project at projectPath.

Implementation

Future<WorkflowGenerationResult> generateWorkflows({
  required String projectPath,
  required CIConfig config,
}) async {
  final steps = <String>['Initialized WorkflowGenerator'];
  final created = <String>[];
  final skipped = <String>[];
  final previews = <String, String>{};

  final workflowsDir = Directory('$projectPath/.github/workflows');

  if (!config.dryRun && !await workflowsDir.exists()) {
    await workflowsDir.create(recursive: true);
    steps.add('Created directory .github/workflows');
  }

  // 1. Generate flutter_verify.yml
  if (config.generateVerifyWorkflow) {
    final path = '$projectPath/.github/workflows/flutter_verify.yml';
    final content = _generateVerifyYaml();
    previews['.github/workflows/flutter_verify.yml'] = content;

    if (await File(path).exists() && !config.force) {
      skipped.add('.github/workflows/flutter_verify.yml');
      steps.add(
          'Skipped flutter_verify.yml (file already exists). Use --force to overwrite.');
    } else {
      if (!config.dryRun) {
        await File(path).writeAsString(content);
      }
      created.add('.github/workflows/flutter_verify.yml');
      steps.add('Generated .github/workflows/flutter_verify.yml');
    }
  }

  // 2. Generate flutter_release.yml
  if (config.generateReleaseWorkflow) {
    final path = '$projectPath/.github/workflows/flutter_release.yml';
    final content = _generateReleaseYaml(config.platform);
    previews['.github/workflows/flutter_release.yml'] = content;

    if (await File(path).exists() && !config.force) {
      skipped.add('.github/workflows/flutter_release.yml');
      steps.add(
          'Skipped flutter_release.yml (file already exists). Use --force to overwrite.');
    } else {
      if (!config.dryRun) {
        await File(path).writeAsString(content);
      }
      created.add('.github/workflows/flutter_release.yml');
      steps.add('Generated .github/workflows/flutter_release.yml');
    }
  }

  // 3. Generate flutter_patch.yml
  if (config.generatePatchWorkflow) {
    final path = '$projectPath/.github/workflows/flutter_patch.yml';
    final content = _generatePatchYaml(config.platform);
    previews['.github/workflows/flutter_patch.yml'] = content;

    if (await File(path).exists() && !config.force) {
      skipped.add('.github/workflows/flutter_patch.yml');
      steps.add(
          'Skipped flutter_patch.yml (file already exists). Use --force to overwrite.');
    } else {
      if (!config.dryRun) {
        await File(path).writeAsString(content);
      }
      created.add('.github/workflows/flutter_patch.yml');
      steps.add('Generated .github/workflows/flutter_patch.yml');
    }
  }

  return WorkflowGenerationResult(
    success: true,
    createdFiles: created,
    skippedFiles: skipped,
    executedSteps: steps,
    previews: previews,
  );
}