Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions chipflow_lib/steps/silicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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"],
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions tests/test_steps_silicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading