44import sys
55import os
66
7+
78def validate_workflow ():
89 workflow_file = ".github/workflows/ci.yml"
9-
10+
1011 if not os .path .exists (workflow_file ):
1112 print (f"❌ Workflow file not found: { workflow_file } " )
1213 return False
13-
14+
1415 try :
1516 with open (workflow_file , 'r' ) as file :
1617 workflow = yaml .safe_load (file )
17-
18+
1819 print ("✅ YAML syntax is valid" )
1920 print (f"📋 Workflow name: { workflow .get ('name' , 'Unknown' )} " )
2021 print (f"🔧 Number of jobs: { len (workflow .get ('jobs' , {}))} " )
21-
22+
2223 # Check required sections
2324 required_sections = ['on' , 'jobs' ]
2425 for section in required_sections :
@@ -27,28 +28,28 @@ def validate_workflow():
2728 else :
2829 print (f"❌ Required section '{ section } ' missing" )
2930 return False
30-
31+
3132 # Check jobs structure
3233 jobs = workflow .get ('jobs' , {})
3334 job_names = list (jobs .keys ())
3435 print (f"🏗️ Jobs found: { ', ' .join (job_names )} " )
35-
36+
3637 for job_name , job_config in jobs .items ():
3738 if 'runs-on' not in job_config :
3839 print (f"❌ Missing 'runs-on' for job: { job_name } " )
3940 return False
40-
41+
4142 # Check for environment variables
4243 if 'env' in workflow :
4344 print (f"🌍 Environment variables: { list (workflow ['env' ].keys ())} " )
44-
45+
4546 # Check permissions
4647 if 'permissions' in workflow :
4748 print (f"🔐 Permissions configured: { list (workflow ['permissions' ].keys ())} " )
48-
49+
4950 print ("\n 🎉 Workflow validation passed!" )
5051 return True
51-
52+
5253 except yaml .YAMLError as e :
5354 print (f"❌ YAML syntax error: { e } " )
5455 return False
0 commit comments