|
16 | 16 |
|
17 | 17 | from .. import ChipFlowError |
18 | 18 | from ..platforms import SiliconPlatform, top_interfaces |
| 19 | +from urllib.parse import urlparse |
19 | 20 |
|
20 | 21 |
|
21 | 22 | logger = logging.getLogger(__name__) |
@@ -155,34 +156,42 @@ def submit(self, rtlil_path, *, dry_run=False): |
155 | 156 | return |
156 | 157 |
|
157 | 158 | logger.info(f"Submitting {submission_name} for project {self.project_name}") |
| 159 | + endpoint = os.environ.get("CHIPFLOW_API_ENDPOINT", "https://build.chipflow.org/api/builds") |
| 160 | + host = urlparse(endpoint).netloc |
158 | 161 |
|
159 | 162 | resp = requests.post( |
160 | | - os.environ.get("CHIPFLOW_API_ENDPOINT", "https://app.chipflow-infra.com/api/builds"), |
| 163 | + os.environ.get("CHIPFLOW_API_ENDPOINT", "https://build.chipflow.org/api/builds"), |
161 | 164 | auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]), |
162 | 165 | data=data, |
163 | 166 | files={ |
164 | 167 | "rtlil": open(rtlil_path, "rb"), |
165 | 168 | "config": json.dumps(config), |
166 | 169 | }) |
167 | | - resp_data = resp.json() |
168 | | - if resp.status_code == 403: |
169 | | - raise ChipFlowError( |
170 | | - "Authentication failed; please verify the values of the the CHIPFLOW_API_KEY_ID " |
171 | | - "and CHIPFLOW_API_KEY_SECRET environment variables, if the issue persists, " |
172 | | - "contact support to resolve it") |
173 | | - elif resp.status_code >= 400: |
174 | | - raise ChipFlowError( |
175 | | - f"Submission failed ({resp_data['statusCode']} {resp_data['error']}: " |
176 | | - f"{resp_data['message']}); please contact support and provide this error message") |
177 | | - elif resp.status_code >= 300: |
178 | | - assert False, "3xx responses should not be returned" |
179 | | - elif resp.status_code >= 200: |
180 | | - if not resp_data["ok"]: |
181 | | - raise ChipFlowError( |
182 | | - f"Submission failed ({resp_data['msg']}); please contact support and provide " |
183 | | - f"this error message") |
184 | | - else: |
185 | | - print(f"{resp_data['msg']} (#{resp_data['id']}: {resp_data['name']}); " |
186 | | - f"{resp_data['url']}") |
| 170 | + |
| 171 | + # Parse response body |
| 172 | + try: |
| 173 | + resp_data = resp.json() |
| 174 | + except ValueError: |
| 175 | + resp_data = resp.text |
| 176 | + |
| 177 | + # Handle response based on status code |
| 178 | + if resp.status_code == 200: |
| 179 | + logger.info(f"Submitted design: {resp_data}") |
| 180 | + print(f"https://{host}/build/{resp_data["build_id"]}") |
| 181 | + |
187 | 182 | else: |
188 | | - ChipFlowError(f"Unexpected response from API: {resp}") |
| 183 | + # Log detailed information about the failed request |
| 184 | + logger.error(f"Request failed with status code {resp.status_code}") |
| 185 | + logger.error(f"Request URL: {resp.request.url}") |
| 186 | + |
| 187 | + # Log headers with auth information redacted |
| 188 | + headers = dict(resp.request.headers) |
| 189 | + if "Authorization" in headers: |
| 190 | + headers["Authorization"] = "REDACTED" |
| 191 | + logger.error(f"Request headers: {headers}") |
| 192 | + |
| 193 | + logger.error(f"Request data: {data}") |
| 194 | + logger.error(f"Response headers: {dict(resp.headers)}") |
| 195 | + logger.error(f"Response body: {resp_data}") |
| 196 | + |
| 197 | + raise ChipFlowError(f"Failed to submit design: {resp_data}") |
0 commit comments