Skip to content

Commit

Permalink
Fix false valued variables
Browse files Browse the repository at this point in the history
  • Loading branch information
luismedel committed Nov 15, 2024
1 parent c82ae0a commit c93d8d2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .bluish/bluish.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

var:
project_version: "0.7.2"
project_version: "0.7.3"
python_version: "3.12"

jobs:
Expand Down
10 changes: 7 additions & 3 deletions src/bluish/contexts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,14 @@ def prepare_value(value: Any) -> Any:
member_result = _try_get_value(ctx, f".{name}", raw=raw)
var_result = _try_get_value(ctx, f"var.{name}", raw=raw)

if var_result and member_result:
if var_result is not None and member_result is not None:
raise ValueError(f"Ambiguous value reference: {name}")
elif var_result is not None:
return var_result
elif member_result is not None:
return member_result
else:
return var_result or member_result or None
return None

root, varname = name.split(".", maxsplit=1)

Expand Down Expand Up @@ -354,7 +358,7 @@ def can_dispatch(context: InputOutputNode) -> bool:
return context.attrs._if
elif not isinstance(context.attrs._if, str):
raise ValueError("Condition must be a bool or a string")

print(context.expand_expr(context.attrs._if))
return bool(context.expand_expr(context.attrs._if))


Expand Down
8 changes: 6 additions & 2 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def test_depends_on_ignored() -> None:

def test_conditions() -> None:
wf = create_workflow("""
var:
true_var: true
false_var: false
jobs:
# check == false at the job level
job1:
Expand All @@ -201,7 +205,7 @@ def test_conditions() -> None:
job4:
name: "Job 4"
steps:
- if: ${{ true }}
- if: ${{ true_var }}
shell: python
run: |
print("This is Job 4")
Expand All @@ -210,7 +214,7 @@ def test_conditions() -> None:
job5:
name: "Job 5"
steps:
- if: ${{ false }}
- if: ${{ false_var }}
shell: python
run: |
print("This will not be printed")
Expand Down

0 comments on commit c93d8d2

Please sign in to comment.