Skip to content

Commit

Permalink
Fix workflow matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
luismedel committed Dec 12, 2024
1 parent 80c3175 commit d7adf40
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 55 deletions.
6 changes: 3 additions & 3 deletions .bluish/bluish.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

var:
project_version: "0.9.1"
project_version: "0.9.2"
python_version: "3.12"

runs_on: docker://python:${{ python_version }}-alpine

jobs:
publish:

name: Publish the latest release of Bluish

runs_on: docker://python:${{ python_version }}-alpine

steps:
- name: Install required packages
uses: linux/install-packages
Expand Down
4 changes: 0 additions & 4 deletions .bluish/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ inputs:
- name: test
default: 1

runs_on:
host: docker://python:${{ python_version }}-slim
automount: true

jobs:
_prepare_lint:
name: Prepare linters
Expand Down
6 changes: 3 additions & 3 deletions src/bluish/nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ def prepare_value(value: Any) -> Any:
raise ValueError(f"Step {step_id} not found")
return _try_get_value(step, varname, raw)
elif root == "matrix":
job = cast(bluish.nodes.job.Job, _job(ctx))
if varname in job.matrix:
return prepare_value(job.matrix[varname])
matrix = getattr(ctx, "matrix", None) or getattr(ctx.parent, "matrix", None)
if matrix and (varname in matrix):
return prepare_value(matrix[varname])
elif root == "step":
return _try_get_value(_step(ctx), varname, raw)
elif root == "inputs":
Expand Down
85 changes: 40 additions & 45 deletions src/bluish/nodes/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ def is_true(v: Any) -> bool:
def dispatch(self) -> bluish.process.ProcessResult:
self.reset()

cleanup_host = False
if not self.runs_on_host:
self.runs_on_host = self.runs_on_host or bluish.process.prepare_host(
self.expand_expr(self.attrs.runs_on)
)
cleanup_host = True

self.status = bluish.core.ExecutionStatus.RUNNING

bluish.nodes.log_dict(
Expand All @@ -119,26 +112,10 @@ def dispatch(self) -> bluish.process.ProcessResult:
if self.status == bluish.core.ExecutionStatus.RUNNING:
self.status = bluish.core.ExecutionStatus.FINISHED

if cleanup_host:
bluish.process.cleanup_host(self.runs_on_host)
self.runs_on_host = None

def dispatch_job(
self, job: bluish.nodes.job.Job, no_deps: bool
) -> bluish.process.ProcessResult | None:
cleanup_host = False
if not self.runs_on_host:
self.runs_on_host = self.runs_on_host or bluish.process.prepare_host(
self.expand_expr(self.attrs.runs_on)
)
cleanup_host = True
result = self.__dispatch_job(job, no_deps, set())

if cleanup_host:
bluish.process.cleanup_host(self.runs_on_host)
self.runs_on_host = None

return result
return self.__dispatch_job(job, no_deps, set())

def __dispatch_job(
self, job: bluish.nodes.job.Job, no_deps: bool, visited_jobs: set[str]
Expand Down Expand Up @@ -167,27 +144,45 @@ def __dispatch_job(
return result

for wf_matrix in bluish.nodes._generate_matrices(self):
for job_matrix in bluish.nodes._generate_matrices(job):
job.reset()

if job.attrs.runs_on:
job.runs_on_host = bluish.process.prepare_host(
self.expand_expr(job.attrs.runs_on)
)
else:
job.runs_on_host = self.runs_on_host

job.matrix = {**wf_matrix, **job_matrix}

self.matrix = wf_matrix

cleanup_host = False
if not self.runs_on_host:
self.runs_on_host = self.runs_on_host or bluish.process.prepare_host(
self.expand_expr(self.attrs.runs_on)
)
cleanup_host = True

try:
for job_matrix in bluish.nodes._generate_matrices(job):
job.reset()

job.matrix = {**wf_matrix, **job_matrix}

if job.attrs.runs_on:
job.runs_on_host = bluish.process.prepare_host(
self.expand_expr(job.attrs.runs_on)
)
else:
job.runs_on_host = self.runs_on_host


try:
result = job.dispatch()
if result and result.failed:
return result
except:
raise
finally:
if job.runs_on_host and job.runs_on_host is not self.runs_on_host:
bluish.process.cleanup_host(job.runs_on_host)
job.runs_on_host = None
try:
result = job.dispatch()
if result and result.failed:
return result
except:
raise
finally:
if job.runs_on_host and job.runs_on_host is not self.runs_on_host:
bluish.process.cleanup_host(job.runs_on_host)
job.runs_on_host = None
except:
raise
finally:
if cleanup_host:
bluish.process.cleanup_host(self.runs_on_host)
self.runs_on_host = None

return bluish.process.ProcessResult()

0 comments on commit d7adf40

Please sign in to comment.