diff --git a/chipflow_lib/steps/silicon.py b/chipflow_lib/steps/silicon.py index 63a7f4e7..73a302c9 100644 --- a/chipflow_lib/steps/silicon.py +++ b/chipflow_lib/steps/silicon.py @@ -84,11 +84,6 @@ def run_cli(self, args): raise ChipFlowError( "Key `chipflow.project_id` is not defined in chipflow.toml; " "see https://chipflow.io/beta for details on how to join the beta") - if ("CHIPFLOW_API_KEY_ID" not in os.environ or - "CHIPFLOW_API_KEY_SECRET" not in os.environ): - raise ChipFlowError( - "Environment variables `CHIPFLOW_API_KEY_ID` and `CHIPFLOW_API_KEY_SECRET` " - "must be set in order to submit a design") rtlil_path = self.prepare() # always prepare before submission if args.action == "submit": @@ -104,6 +99,24 @@ def prepare(self): def submit(self, rtlil_path, *, dry_run=False, wait=False): """Submit the design to the ChipFlow cloud builder. """ + if not dry_run: + # Check for CHIPFLOW_API_KEY_SECRET or CHIPFLOW_API_KEY + if not os.environ.get("CHIPFLOW_API_KEY") and not os.environ.get("CHIPFLOW_API_KEY_SECRET"): + raise ChipFlowError( + "Environment variable `CHIPFLOW_API_KEY` must be set to submit a design." + ) + # Log a deprecation warning if CHIPFLOW_API_KEY_SECRET is used + if os.environ.get("CHIPFLOW_API_KEY_SECRET"): + logger.warning( + "Environment variable `CHIPFLOW_API_KEY_SECRET` is deprecated. " + "Please migrate to using `CHIPFLOW_API_KEY` instead." + ) + chipflow_api_key = os.environ.get("CHIPFLOW_API_KEY") or os.environ.get("CHIPFLOW_API_KEY_SECRET") + if chipflow_api_key is None: + raise ChipFlowError( + "Environment variable `CHIPFLOW_API_KEY` is empty." + ) + git_head = subprocess.check_output( ["git", "-C", os.environ["CHIPFLOW_ROOT"], "rev-parse", "--short", "HEAD"], @@ -160,7 +173,7 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False): build_submit_url, # TODO: This needs to be reworked to accept only one key, auth accepts user and pass # TODO: but we want to submit a single key - auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]), + auth=(None, chipflow_api_key), data=data, files={ "rtlil": open(rtlil_path, "rb"), @@ -191,7 +204,7 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False): logger.info("Polling build status...") status_resp = requests.get( build_status_url, - auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]) + auth=(None, chipflow_api_key) ) if status_resp.status_code != 200: logger.error(f"Failed to fetch build status: {status_resp.text}") @@ -219,7 +232,7 @@ def submit(self, rtlil_path, *, dry_run=False, wait=False): stream_event_counter += 1 with requests.get( log_stream_url, - auth=(os.environ["CHIPFLOW_API_KEY_ID"], os.environ["CHIPFLOW_API_KEY_SECRET"]), + auth=(None, chipflow_api_key), stream=True ) as log_resp: if log_resp.status_code == 200: diff --git a/tests/test_steps_silicon.py b/tests/test_steps_silicon.py index 76fe8175..3f9e7683 100644 --- a/tests/test_steps_silicon.py +++ b/tests/test_steps_silicon.py @@ -269,8 +269,7 @@ def test_run_cli_submit_missing_api_keys(self, mock_load_dotenv, mock_prepare): step.run_cli(args) # Verify error message - self.assertIn("CHIPFLOW_API_KEY_ID", str(cm.exception)) - self.assertIn("CHIPFLOW_API_KEY_SECRET", str(cm.exception)) + self.assertIn("CHIPFLOW_API_KEY", str(cm.exception)) # Verify dotenv was loaded mock_load_dotenv.assert_called_once()