|
1 | 1 | """ |
2 | 2 | Collect information about GitHub workflows in the repo. |
3 | 3 | """ |
4 | | -import numpy as np |
5 | 4 | # The MIT License (MIT) |
6 | 5 | # |
7 | 6 | # Copyright (c) 2024 Aliaksei Bialiauski |
@@ -109,66 +108,74 @@ def fetch(path) -> str: |
109 | 108 |
|
110 | 109 |
|
111 | 110 | def workflow_info(content): |
112 | | - yml = yaml.safe_load(content) |
113 | | - jobs = yml["jobs"].items() |
114 | | - jcount = len(jobs) |
115 | | - oss = [] |
| 111 | + yml = yaml.safe_load( |
| 112 | + '\n'.join(line for line in content.splitlines() if not line.strip().startswith('#')).strip() |
| 113 | + ) |
| 114 | + jcount = 0 |
116 | 115 | scount = 0 |
117 | | - for job, jdetails in jobs: |
118 | | - runs = jdetails.get("runs-on") |
119 | | - if runs is not None and not isinstance(runs, dict): |
120 | | - if isinstance(runs, list): |
121 | | - for r in runs: |
122 | | - oss.append(r) |
123 | | - if not isinstance(runs, list) and runs.startswith("$"): |
124 | | - if jdetails.get("strategy"): |
125 | | - matrix = jdetails.get("strategy").get("matrix") |
126 | | - if matrix is not None: |
127 | | - if isinstance(matrix, str): |
128 | | - oss.append(runs) |
129 | | - else: |
130 | | - keys = [ |
131 | | - key.strip() for key in |
132 | | - runs.strip().replace("${{", "").replace("}}", "") |
133 | | - .split(".")[1:] |
134 | | - ] |
135 | | - if len(keys) == 1: |
136 | | - if matrix.get(keys[0]): |
137 | | - for matrixed in matrix.get(keys[0]): |
138 | | - if isinstance(matrixed, list): |
139 | | - for r in matrixed: |
140 | | - oss.append(r) |
141 | | - else: |
142 | | - oss.append(matrixed) |
143 | | - elif len(keys) > 1: |
144 | | - for system in dot_values(keys, matrix): |
145 | | - oss.append(system) |
146 | | - elif matrix.get("include"): |
147 | | - for include in matrix.get("include"): |
148 | | - oss.append( |
149 | | - include.get( |
150 | | - runs.strip() |
151 | | - .replace("${{", "") |
152 | | - .replace("}}", "") |
153 | | - .split(".")[1].strip() |
| 116 | + oss = [] |
| 117 | + w_release = False |
| 118 | + if yml is not None: |
| 119 | + jobs = yml["jobs"].items() |
| 120 | + jcount = len(jobs) |
| 121 | + oss = [] |
| 122 | + scount = 0 |
| 123 | + for job, jdetails in jobs: |
| 124 | + runs = jdetails.get("runs-on") |
| 125 | + if runs is not None and not isinstance(runs, dict): |
| 126 | + if isinstance(runs, list): |
| 127 | + for r in runs: |
| 128 | + oss.append(r) |
| 129 | + if not isinstance(runs, list) and runs.startswith("$"): |
| 130 | + if jdetails.get("strategy"): |
| 131 | + matrix = jdetails.get("strategy").get("matrix") |
| 132 | + if matrix is not None: |
| 133 | + if isinstance(matrix, str): |
| 134 | + oss.append(runs) |
| 135 | + else: |
| 136 | + keys = [ |
| 137 | + key.strip() for key in |
| 138 | + runs.strip().replace("${{", "").replace("}}", "") |
| 139 | + .split(".")[1:] |
| 140 | + ] |
| 141 | + if len(keys) == 1: |
| 142 | + if matrix.get(keys[0]): |
| 143 | + for matrixed in matrix.get(keys[0]): |
| 144 | + if isinstance(matrixed, list): |
| 145 | + for r in matrixed: |
| 146 | + oss.append(r) |
| 147 | + else: |
| 148 | + oss.append(matrixed) |
| 149 | + elif len(keys) > 1: |
| 150 | + for system in dot_values(keys, matrix): |
| 151 | + oss.append(system) |
| 152 | + elif matrix.get("include"): |
| 153 | + for include in matrix.get("include"): |
| 154 | + oss.append( |
| 155 | + include.get( |
| 156 | + runs.strip() |
| 157 | + .replace("${{", "") |
| 158 | + .replace("}}", "") |
| 159 | + .split(".")[1].strip() |
| 160 | + ) |
154 | 161 | ) |
155 | | - ) |
156 | | - elif not isinstance(runs, list): |
| 162 | + elif not isinstance(runs, list): |
| 163 | + oss.append(runs) |
| 164 | + elif isinstance(runs, dict): |
| 165 | + if runs.get("group"): |
| 166 | + oss.append(runs.get("group")) |
| 167 | + elif runs is not None: |
157 | 168 | oss.append(runs) |
158 | | - elif isinstance(runs, dict): |
159 | | - if runs.get("group"): |
160 | | - oss.append(runs.get("group")) |
161 | | - elif runs is not None: |
162 | | - oss.append(runs) |
163 | | - steps = jdetails.get("steps") |
164 | | - if steps is not None: |
165 | | - scount = len(steps) |
166 | | - oss = set(oss) |
| 169 | + steps = jdetails.get("steps") |
| 170 | + if steps is not None: |
| 171 | + scount = len(steps) |
| 172 | + oss = set(oss) |
| 173 | + w_release = used_for_releases(yml) |
167 | 174 | return { |
168 | 175 | "w_jobs": jcount, |
169 | 176 | "w_steps": scount, |
170 | 177 | "w_oss": sorted(oss), |
171 | | - "w_release": used_for_releases(yml) |
| 178 | + "w_release": w_release |
172 | 179 | } |
173 | 180 |
|
174 | 181 |
|
|
0 commit comments