fix(steps/actions): accept Callable for ref to defer eval until progress()
Previous attempt to dispatch on the auto-* branch failed at module
load time: passing `ref=checkoutMerged.progress().remote_branch_name`
runs the whole CheckoutMerged pipeline before brencher has populated
self.env.id, raising BaseException('Environment not set for GitClone')
and preventing brencher from even importing connectivity_tester.
Add RefSource = Union[str, Callable[[], Optional[str]], None] mirroring
the existing InputsSource pattern. The Callable is only invoked from
within progress(), by which point the env is fully populated. The str
form is preserved for existing callers (e.g. WORKFLOW_REF='master').
This commit is contained in:
@@ -21,7 +21,7 @@ state = SharedStateHolderInMemory(unmerge=unmerge)
|
||||
checkoutMerged = CheckoutMerged(
|
||||
clone,
|
||||
desired_branches=state,
|
||||
push=False,
|
||||
push=True,
|
||||
git_user_email="rudolfss13@gmail.com",
|
||||
git_user_name="brencher_bot",
|
||||
)
|
||||
@@ -32,7 +32,6 @@ GITEA_TOKEN = os.environ.get("GITEA_TOKEN", "")
|
||||
WORKFLOW_OWNER = "hermes"
|
||||
WORKFLOW_REPO = "ansible"
|
||||
WORKFLOW_FILE = "release.yml"
|
||||
WORKFLOW_REF = "master"
|
||||
|
||||
def _inputs() -> dict:
|
||||
return {"tag": "auto-" + checkoutMerged.progress().version}
|
||||
@@ -42,7 +41,7 @@ trigger_build = GiteaActionsTrigger(
|
||||
owner=WORKFLOW_OWNER,
|
||||
repo=WORKFLOW_REPO,
|
||||
workflow_file=WORKFLOW_FILE,
|
||||
ref=WORKFLOW_REF,
|
||||
ref=lambda: checkoutMerged.progress().remote_branch_name or "master",
|
||||
token=GITEA_TOKEN,
|
||||
inputs=_inputs,
|
||||
wd=checkoutMerged,
|
||||
|
||||
@@ -22,6 +22,7 @@ class GiteaActionsRun:
|
||||
|
||||
|
||||
InputsSource = Union[Dict[str, str], Callable[[], Dict[str, str]], None]
|
||||
RefSource = Union[str, Callable[[], Optional[str]], None]
|
||||
|
||||
|
||||
class GiteaActionsTrigger(AbstractStep[GiteaActionsRun]):
|
||||
@@ -32,7 +33,7 @@ class GiteaActionsTrigger(AbstractStep[GiteaActionsRun]):
|
||||
owner: str,
|
||||
repo: str,
|
||||
workflow_file: str,
|
||||
ref: str,
|
||||
ref: RefSource,
|
||||
token: str,
|
||||
inputs: InputsSource = None,
|
||||
wd: Optional[CheckoutMerged] = None,
|
||||
@@ -89,7 +90,8 @@ class GiteaActionsTrigger(AbstractStep[GiteaActionsRun]):
|
||||
resolved_inputs = self.inputs() or {}
|
||||
elif isinstance(self.inputs, dict):
|
||||
resolved_inputs = self.inputs
|
||||
body: Dict[str, Any] = {"ref": self.ref}
|
||||
ref = self.ref() if callable(self.ref) else self.ref
|
||||
body: Dict[str, Any] = {"ref": ref}
|
||||
if resolved_inputs:
|
||||
body["inputs"] = resolved_inputs
|
||||
url = (
|
||||
@@ -106,7 +108,7 @@ class GiteaActionsTrigger(AbstractStep[GiteaActionsRun]):
|
||||
"Workaround: trigger the workflow manually by pushing a tag matching "
|
||||
f"the workflow's `on.push.tags` filter, e.g. "
|
||||
f"`git push <repo> HEAD:refs/tags/auto-<sha>`. "
|
||||
f"Requested workflow: {self.owner}/{self.repo}/{self.workflow_file}@{self.ref}"
|
||||
f"Requested workflow: {self.owner}/{self.repo}/{self.workflow_file}@{ref}"
|
||||
) from e
|
||||
deadline = time.time() + self.poll_timeout_sec
|
||||
while time.time() < deadline:
|
||||
|
||||
Reference in New Issue
Block a user