diff --git a/backend/steps/actions.py b/backend/steps/actions.py index fc0b7ca..f06c54b 100644 --- a/backend/steps/actions.py +++ b/backend/steps/actions.py @@ -5,7 +5,7 @@ import time import urllib.error import urllib.request from dataclasses import dataclass -from typing import Any, Callable, Dict, Optional +from typing import Any, Callable, Dict, Optional, Union from enironment import AbstractStep from steps.git import CheckoutMerged @@ -21,6 +21,9 @@ class GiteaActionsRun: html_url: str +InputsSource = Union[Dict[str, str], Callable[[], Dict[str, str]], None] + + class GiteaActionsTrigger(AbstractStep[GiteaActionsRun]): """Trigger a Gitea Actions workflow via the dispatches API.""" @@ -31,7 +34,7 @@ class GiteaActionsTrigger(AbstractStep[GiteaActionsRun]): workflow_file: str, ref: str, token: str, - inputs: Optional[Dict[str, str]] = None, + inputs: InputsSource = None, wd: Optional[CheckoutMerged] = None, poll_timeout_sec: int = 1800, poll_interval_sec: int = 10, @@ -43,7 +46,7 @@ class GiteaActionsTrigger(AbstractStep[GiteaActionsRun]): self.workflow_file = workflow_file self.ref = ref self.token = token - self.inputs = inputs or {} + self.inputs = inputs self.wd = wd self.poll_timeout_sec = poll_timeout_sec self.poll_interval_sec = poll_interval_sec @@ -78,9 +81,14 @@ class GiteaActionsTrigger(AbstractStep[GiteaActionsRun]): def progress(self) -> GiteaActionsRun: latest = self._list_recent_runs() + resolved_inputs: Dict[str, str] = {} + if callable(self.inputs): + resolved_inputs = self.inputs() or {} + elif isinstance(self.inputs, dict): + resolved_inputs = self.inputs body: Dict[str, Any] = {"ref": self.ref} - if self.inputs: - body["inputs"] = self.inputs + if resolved_inputs: + body["inputs"] = resolved_inputs url = ( f"{self.api_base}/repos/{self.owner}/{self.repo}" f"/actions/workflows/{self.workflow_file}/dispatches"