1 """Validate the YAML files for GitHub Actions workflows.
3 TODO: b/359303016 - convert to use unittest
11 # Ensure every job is in the list of blocking jobs.
13 os
.path
.join(os
.path
.dirname(__file__
), '../workflows/test_runner.yml'), 'r'
15 data
= yaml
.safe_load(f
)
17 # List of all YAML files that are used by jobs in the test_runner.yml file.
20 # Get a list of all jobs in the test_runner, except for the blocking job and
21 # the tag removal job, which is not always run.
22 all_jobs
= list(data
['jobs'].keys())
23 all_jobs
.remove('all-blocking-tests')
24 all_jobs
.remove('remove-tag')
27 blocking_jobs
= data
['jobs']['all-blocking-tests']['needs']
30 if 'uses' in data
['jobs'][job
]:
33 os
.path
.dirname(__file__
),
35 os
.path
.basename(data
['jobs'][job
]['uses']),
38 if job
not in blocking_jobs
:
40 raise ValueError('Job %s is not in the list of blocking jobs.' % job
)
42 print('PASSED: All jobs are in the list of blocking jobs.')
44 # Ensure every job with a continuous prefix conditions every step on whether we
45 # are in a continuous run.
46 for file in yaml_files
:
47 with
open(file, 'r') as f
:
48 data
= yaml
.safe_load(f
)
51 if 'steps' not in jobs
[job
]:
53 continuous_condition
= 'inputs.continuous-prefix' in jobs
[job
]['name']
54 steps
= jobs
[job
]['steps']
58 elif 'with' in step
and 'name' in step
['with']:
59 name
= step
['with']['name']
62 'Step in job %s from file %s does not have a name.' % (job
, file)
64 if continuous_condition
and 'continuous-run' not in step
.get('if', ''):
66 'Step %s in job %s from file %s does not check the continuous-run'
67 ' condition' % (name
, job
, file)
69 if not continuous_condition
and 'continuous-run' in step
.get('if', ''):
71 'Step %s in job %s from file %s checks the continuous-run'
72 ' condition but the job does not contain the continuous-prefix'
75 print('PASSED: All steps in all jobs check the continuous-run condition.')