|
50 | 50 | except ImportError: |
51 | 51 | sync_bundles = None |
52 | 52 |
|
| 53 | +try: |
| 54 | + import check_input_assets |
| 55 | +except ImportError: |
| 56 | + check_input_assets = None |
| 57 | + |
53 | 58 |
|
54 | 59 | class TemplateSyncer: |
55 | 60 | """Main class for template synchronization operations""" |
@@ -1090,6 +1095,81 @@ def sync_bundles(self): |
1090 | 1095 | # sync_bundles uses SystemExit for errors, convert to exception |
1091 | 1096 | raise Exception(f"Bundle sync failed: {e}") |
1092 | 1097 |
|
| 1098 | + def check_input_assets(self): |
| 1099 | + """ |
| 1100 | + Validate input assets referenced in workflow files using check_input_assets module |
| 1101 | + """ |
| 1102 | + if check_input_assets is None: |
| 1103 | + raise ImportError("check_input_assets module is not available") |
| 1104 | + |
| 1105 | + try: |
| 1106 | + # Get repository root (parent of scripts directory) |
| 1107 | + repo_root = self.syncer.templates_dir.parent |
| 1108 | + templates_dir = repo_root / "templates" |
| 1109 | + inputs_dir = repo_root / "input" |
| 1110 | + |
| 1111 | + # Find workflow files |
| 1112 | + self.syncer.logger.info(" Finding workflow files...") |
| 1113 | + workflow_files = check_input_assets.find_workflow_files(templates_dir) |
| 1114 | + self.syncer.logger.info(f" Found {len(workflow_files)} workflow files") |
| 1115 | + |
| 1116 | + # Extract all asset references |
| 1117 | + self.syncer.logger.info(" Extracting asset references...") |
| 1118 | + all_assets = [] |
| 1119 | + for workflow_file in workflow_files: |
| 1120 | + assets = check_input_assets.extract_asset_references( |
| 1121 | + workflow_file, |
| 1122 | + check_input_assets.ASSET_NODE_TYPES |
| 1123 | + ) |
| 1124 | + all_assets.extend(assets) |
| 1125 | + |
| 1126 | + self.syncer.logger.info(f" Found {len(all_assets)} asset references") |
| 1127 | + |
| 1128 | + # Validate assets |
| 1129 | + self.syncer.logger.info(" Validating assets...") |
| 1130 | + valid_assets, missing_assets = check_input_assets.validate_assets(all_assets, inputs_dir) |
| 1131 | + |
| 1132 | + # Generate report |
| 1133 | + report = check_input_assets.generate_report( |
| 1134 | + valid_assets, |
| 1135 | + missing_assets, |
| 1136 | + len(workflow_files), |
| 1137 | + check_input_assets.ASSET_NODE_TYPES |
| 1138 | + ) |
| 1139 | + |
| 1140 | + # Save report |
| 1141 | + report_file = repo_root / "asset_validation_report.md" |
| 1142 | + if not self.syncer.dry_run: |
| 1143 | + with open(report_file, 'w', encoding='utf-8') as f: |
| 1144 | + f.write(report) |
| 1145 | + self.syncer.logger.info(f" ✅ Report saved to: {report_file}") |
| 1146 | + |
| 1147 | + # Generate and save upload JSON file |
| 1148 | + self.syncer.logger.info(" Generating upload JSON...") |
| 1149 | + base_url = "https://raw.githubusercontent.com/Comfy-Org/workflow_templates/refs/heads/main/input/" |
| 1150 | + upload_data = check_input_assets.generate_upload_json(inputs_dir, templates_dir, base_url) |
| 1151 | + upload_file = repo_root / "workflow_template_input_files.json" |
| 1152 | + |
| 1153 | + if not self.syncer.dry_run: |
| 1154 | + with open(upload_file, 'w', encoding='utf-8') as f: |
| 1155 | + json.dump(upload_data, f, indent=2, ensure_ascii=False) |
| 1156 | + self.syncer.logger.info(f" ✅ Generated {len(upload_data['assets'])} asset entries") |
| 1157 | + self.syncer.logger.info(f" ✅ Upload JSON saved to: {upload_file}") |
| 1158 | + else: |
| 1159 | + self.syncer.logger.info(f" [DRY RUN] Would generate {len(upload_data['assets'])} asset entries") |
| 1160 | + |
| 1161 | + # Log summary |
| 1162 | + if missing_assets: |
| 1163 | + self.syncer.logger.warning(f" ⚠️ Validation found {len(missing_assets)} missing asset(s)") |
| 1164 | + self.syncer.logger.warning(f" ✅ {len(valid_assets)} asset(s) successfully validated") |
| 1165 | + else: |
| 1166 | + self.syncer.logger.info(f" ✅ Validation passed: All {len(valid_assets)} asset(s) found") |
| 1167 | + |
| 1168 | + return len(missing_assets) == 0 |
| 1169 | + |
| 1170 | + except Exception as e: |
| 1171 | + raise Exception(f"Input assets validation failed: {e}") |
| 1172 | + |
1093 | 1173 | def fix_master_vram_data(self): |
1094 | 1174 | """ |
1095 | 1175 | Fix vram data in the master index.json file before synchronization |
@@ -1153,6 +1233,7 @@ def run_sync(self) -> bool: |
1153 | 1233 | 2. Sync i18n.json translations to all language files |
1154 | 1234 | 3. Collect ALL translations from language files back to i18n.json |
1155 | 1235 | 4. Sync bundles (manifest and bundle package assets) |
| 1236 | + 5. Check input assets (validate referenced assets exist) |
1156 | 1237 | """ |
1157 | 1238 | self.syncer.logger.info("🚀 Starting template synchronization...") |
1158 | 1239 | self.syncer.logger.info(f"Master file: {self.syncer.master_file}") |
@@ -1263,6 +1344,20 @@ def run_sync(self) -> bool: |
1263 | 1344 | else: |
1264 | 1345 | self.syncer.logger.warning("\n⚠️ sync_bundles module not available, skipping bundle synchronization") |
1265 | 1346 |
|
| 1347 | + # Step 5: Check input assets |
| 1348 | + if check_input_assets is not None: |
| 1349 | + self.syncer.logger.info("\n🔍 Step 5: Validating input assets...") |
| 1350 | + try: |
| 1351 | + validation_passed = self.check_input_assets() |
| 1352 | + if not validation_passed: |
| 1353 | + self.syncer.logger.warning(" ⚠️ Input assets validation found missing assets (see report for details)") |
| 1354 | + # Don't fail the entire sync if validation fails, but log the warning |
| 1355 | + except Exception as e: |
| 1356 | + self.syncer.logger.error(f"Failed to validate input assets: {e}") |
| 1357 | + # Don't fail the entire sync if validation fails, but log the error |
| 1358 | + else: |
| 1359 | + self.syncer.logger.warning("\n⚠️ check_input_assets module not available, skipping input assets validation") |
| 1360 | + |
1266 | 1361 | return success |
1267 | 1362 |
|
1268 | 1363 |
|
|
0 commit comments