55Airbyte CDK manifests.
66"""
77
8+ import copy
89import sys
910from importlib import metadata
1011from pathlib import Path
@@ -42,6 +43,13 @@ def validate_manifest(manifest_path: Path) -> None:
4243
4344 This command validates the manifest file and checks version compatibility.
4445 If validation fails, it will suggest running the migrate command if needed.
46+
47+ Exit codes:
48+ \\ b
49+ 0: Manifest is valid and up to date
50+ 1: Manifest is valid but needs migration, or general errors
51+ 2: Manifest has validation errors that are fixable via migration
52+ 3: Manifest has validation errors that are NOT fixable via migration
4553 """
4654 try :
4755 with open (manifest_path , "r" ) as f :
@@ -56,37 +64,55 @@ def validate_manifest(manifest_path: Path) -> None:
5664
5765 schema = _get_declarative_component_schema ()
5866
59- validate (manifest_dict , schema )
67+ validation_error = None
68+ try :
69+ validate (manifest_dict , schema )
70+ original_is_valid = True
71+ except ValidationError as e :
72+ original_is_valid = False
73+ validation_error = e
6074
61- migration_handler = ManifestMigrationHandler (manifest_dict )
75+ migration_handler = ManifestMigrationHandler (copy . deepcopy ( manifest_dict ) )
6276 migrated_manifest = migration_handler .apply_migrations ()
63-
64- if migrated_manifest != manifest_dict :
65- click .echo (
66- f"⚠️ Manifest { manifest_path } is valid but could benefit from migration to the latest version." ,
67- err = True ,
68- )
69- click .echo (
70- "Run 'airbyte-cdk manifest migrate' to apply available migrations." , err = True
71- )
72- sys .exit (1 )
73-
74- click .echo (f"✅ Manifest { manifest_path } is valid and up to date." )
77+
78+ migration_available = migrated_manifest != manifest_dict
79+
80+ if original_is_valid :
81+ if migration_available :
82+ click .echo (
83+ f"⚠️ Manifest { manifest_path } is valid but could benefit from migration to the latest version." ,
84+ err = True ,
85+ )
86+ click .echo (
87+ "Run 'airbyte-cdk manifest migrate' to apply available migrations." , err = True
88+ )
89+ sys .exit (1 )
90+ else :
91+ click .echo (f"✅ Manifest { manifest_path } is valid and up to date." )
92+ return
93+
94+ if migration_available :
95+ try :
96+ validate (migrated_manifest , schema )
97+ click .echo (f"❌ Validation failed for { manifest_path } :" , err = True )
98+ click .echo (f" { validation_error .message } " , err = True )
99+ click .echo ("✅ Issues are fixable via migration. Run 'airbyte-cdk manifest migrate' to fix these issues." , err = True )
100+ sys .exit (2 ) # Fixable issues
101+ except ValidationError :
102+ click .echo (f"❌ Validation failed for { manifest_path } :" , err = True )
103+ click .echo (f" { validation_error .message } " , err = True )
104+ sys .exit (3 ) # Non-fixable issues
105+ else :
106+ click .echo (f"❌ Validation failed for { manifest_path } :" , err = True )
107+ click .echo (f" { validation_error .message } " , err = True )
108+ sys .exit (3 ) # Non-fixable issues
75109
76110 except FileNotFoundError :
77111 click .echo (f"❌ Error: Manifest file { manifest_path } not found" , err = True )
78112 sys .exit (1 )
79113 except yaml .YAMLError as e :
80114 click .echo (f"❌ Error: Invalid YAML in { manifest_path } : { e } " , err = True )
81115 sys .exit (1 )
82- except ValidationError as e :
83- click .echo (f"❌ Validation failed for { manifest_path } :" , err = True )
84- click .echo (f" { e .message } " , err = True )
85- click .echo (
86- "Run 'airbyte-cdk manifest migrate' to apply available migrations that might fix this issue." ,
87- err = True ,
88- )
89- sys .exit (1 )
90116 except Exception as e :
91117 click .echo (f"❌ Unexpected error validating { manifest_path } : { e } " , err = True )
92118 sys .exit (1 )
0 commit comments