Compare commits

...
34 Commits
Author SHA1 Message Date
admin dbcae04782 x
Python package / build (3.12.3) (pull_request) Successful in 2m19s
Python package / build (3.13) (pull_request) Successful in 2m20s
Python package / build (3.14) (pull_request) Successful in 2m30s
2026-10-11 19:32:35 +02:00
admin 56b6660c1f x
Python package / build (3.12.3) (pull_request) Successful in 2m22s
Python package / build (3.13) (pull_request) Successful in 2m19s
Python package / build (3.14) (pull_request) Successful in 2m25s
2026-10-11 17:20:09 +02:00
hermes 13d6d9f95d fix: push connectivity tester to org1
Python package / build (3.12.3) (pull_request) Successful in 2m46s
Python package / build (3.13) (pull_request) Successful in 3m27s
Python package / build (3.14) (pull_request) Successful in 2m34s
2026-10-10 12:33:22 +00:00
hermes 0290b5bbac fix: align connectivity tester registry namespace
Python package / build (3.12.3) (pull_request) Successful in 3m3s
Python package / build (3.13) (pull_request) Successful in 2m30s
Python package / build (3.14) (pull_request) Successful in 2m34s
2026-10-10 10:19:55 +00:00
hermes b313a39e23 feat: push auto branches for actions 2026-10-09 10:51:57 +00:00
hermes 4fca3a4856 feat: fetch connectivity tester forks
Python package / build (3.12.3) (pull_request) Successful in 2m21s
Python package / build (3.13) (pull_request) Successful in 2m25s
Python package / build (3.14) (pull_request) Successful in 2m33s
2026-10-08 20:18:01 +00:00
hermes bee03bdb52 feat: use dedicated connectivity tester repository
Python package / build (3.12.3) (pull_request) Canceled after 0s
Python package / build (3.13) (pull_request) Canceled after 0s
Python package / build (3.14) (pull_request) Canceled after 0s
2026-10-08 20:01:52 +00:00
hermes 272a06a51c merge main: resolve connectivity tester conflicts
Python package / build (3.12.3) (pull_request) Successful in 2m43s
Python package / build (3.13) (pull_request) Successful in 3m16s
Python package / build (3.14) (pull_request) Successful in 2m10s
2026-09-29 17:57:30 +00:00
hermes bf4533c0fe fix(deploy): forward registry auth to swarm nodes
Python package / build (3.12.3) (pull_request) Successful in 3m13s
Python package / build (3.13) (pull_request) Successful in 2m44s
Python package / build (3.14) (pull_request) Successful in 2m42s
2026-09-29 17:22:59 +00:00
hermes ea7c00a02f fix(configs): inline WORKFLOW_* in GiteaActions* ctor; keep only GITEA_TOKEN in secret
Python package / build (3.12.3) (pull_request) Successful in 2m47s
Python package / build (3.13) (pull_request) Successful in 2m41s
Python package / build (3.14) (pull_request) Successful in 2m31s
The previous split between env vars and constructor args created two
sources of truth for the workflow target. Moving WORKFLOW_OWNER /
WORKFLOW_REPO / WORKFLOW_FILE / WORKFLOW_REF into the constructor
arguments makes the dispatch target obvious at the call site and
keeps the docker secret template minimal (only credentials it must
contain).

README.instruction.md now lists only GIT_USERNAME / GIT_PASSWORD /
GITEA_TOKEN in the `printf` block; WORKFLOW_* are documented in
AGENTS.md (already there) as stack-specific config knobs.
2026-09-19 09:57:47 +00:00
hermes ac935ca8ca docs(readme): add GITEA_TOKEN + Actions dispatch knobs to docker secret template
Python package / build (3.12.3) (pull_request) Successful in 2m29s
Python package / build (3.13) (pull_request) Successful in 2m31s
Python package / build (3.14) (pull_request) Successful in 2m31s
The brencher stack build-delegation pattern (see AGENTS.md) needs four
env vars to fire `GiteaActionsTrigger`:

- GITEA_TOKEN: Gitea PAT used to POST /dispatches and poll /runs
- WORKFLOW_REPO: owner/repo that hosts the workflow file (default: hermes/ansible)
- WORKFLOW_FILE: workflow filename (default: release.yml)
- WORKFLOW_REF: branch or tag the workflow is triggered on (default: master)

Without GITEA_TOKEN the trigger step gets HTTP 401 from
/api/v1/repos/{owner}/{repo}/actions/runs; the pipeline halts at
trigger_build and the stack never deploys. Added the missing keys to
the secret-create `printf` block in README.instruction.md so the next
person wiring up a brencher stack doesn't have to discover this.

Defaults shown match the connectivity_tester stack wiring
(admin/brencher#65).
2026-09-19 08:32:55 +00:00
hermes 2b5c8952b3 fix(steps/git): use config_writer with force-fetch refspec
Python package / build (3.12.3) (pull_request) Successful in 2m30s
Python package / build (3.13) (pull_request) Successful in 2m43s
Python package / build (3.14) (pull_request) Successful in 2m37s
Default git fetch refspec refuses to update refs whose upstream SHA
diverges from the local copy. When a branch is force-pushed (e.g. our
smoke-test pushes of master, our re-applies of GITHUB_TOKEN fix), the
local remote-tracking ref points at the old SHA and git refuses to
overwrite it. This shows up as 'cannot lock ref ... is at <old> but
expected <new>' and fails the entire clone step.

Adding '+refs/heads/*:refs/remotes/<remote>/*' to each remote via
config.set_value(section, option, value) lets the fetch force-update
the remote-tracking refs. Each remote gets its own refspec; the
existing 'origin' branchNamePrefix refspec is preserved.
2026-09-18 21:55:24 +00:00
hermes 962b34e8ee Revert "fix(steps/git): use config_writer to set force-fetch refspec"
Python package / build (3.12.3) (pull_request) Canceled after 42s
Python package / build (3.13) (pull_request) Canceled after 0s
Python package / build (3.14) (pull_request) Canceled after 0s
This reverts commit 3dd0657733.
2026-09-18 21:54:20 +00:00
hermes 3dd0657733 fix(steps/git): use config_writer to set force-fetch refspec
Python package / build (3.12.3) (pull_request) Successful in 2m35s
Python package / build (3.13) (pull_request) Successful in 2m47s
Python package / build (3.14) (pull_request) Canceled after 35s
GitPython Remote does not expose a set_refspec method. Use
repo.config_writer() to set remote.<name>.fetch '+refs/heads/*:refs/remotes/<name>/*'.
This bypasses the default safety against updating remote-tracking refs
that diverge from their upstream (force-pushed branches).

Sets the refspec for every remote, not just 'origin', so multi-remote
configs like connectivity_tester (hermes/ansible + admin/ansible) pick
up force-pushed branches on either side.
2026-09-18 21:48:34 +00:00
hermes 0bb705fc3e Revert "fix(steps/git): use force-fetch refspec so force-pushed branches are picked up"
This reverts commit 53b8796319.
2026-09-18 21:48:09 +00:00
hermes 53b8796319 fix(steps/git): use force-fetch refspec so force-pushed branches are picked up
Python package / build (3.12.3) (pull_request) Successful in 2m43s
Python package / build (3.13) (pull_request) Successful in 2m30s
Python package / build (3.14) (pull_request) Successful in 2m37s
Default git fetch refspec refuses to update refs whose upstream SHA
diverges from the local copy. When a branch is force-pushed (e.g. our
smoke-test pushes of master, our re-applies of GITHUB_TOKEN fix), the
local remote-tracking ref points at the old SHA and git refuses to
overwrite it. This shows up as 'cannot lock ref ... is at <old> but
expected <new>' and fails the entire clone step.

Adding '+refs/heads/*:refs/remotes/<remote>/*' to each remote's refspec
lets the fetch force-update the remote-tracking refs. Each remote's
existing refspec is preserved; the force-refspec is appended only if
not already present.
2026-09-18 21:39:31 +00:00
hermes 4fd29c8ea1 fix(steps/actions): clearer error when POST /dispatches 500
Python package / build (3.12.3) (pull_request) Successful in 2m49s
Python package / build (3.13) (pull_request) Successful in 2m16s
Python package / build (3.14) (pull_request) Successful in 2m8s
Refines the trigger_build failure mode: instead of opaque urllib.error.HTTPError,
raises a RuntimeError explaining the gitea-side bug + the tag-push workaround
(documented in the runtime message).
2026-09-18 20:58:44 +00:00
hermes e067b8c035 fix(configs): WORKFLOW_REF=master (release/* doesn't trigger push)
Python package / build (3.12.3) (pull_request) Successful in 2m15s
Python package / build (3.13) (pull_request) Successful in 2m11s
Python package / build (3.14) (pull_request) Successful in 2m16s
2026-09-18 20:42:53 +00:00
hermes 0bb3d53c7a fix(steps/actions): accept callable inputs (resolve at dispatch time)
Python package / build (3.12.3) (pull_request) Successful in 2m12s
Python package / build (3.13) (pull_request) Successful in 2m5s
Python package / build (3.14) (pull_request) Successful in 2m14s
2026-09-18 13:10:39 +00:00
admin 2229acc7f2 docs(AGENTS): document Actions build delegation pattern
Python package / build (3.12.3) (pull_request) Failing after 2m15s
Python package / build (3.13) (pull_request) Failing after 2m1s
Python package / build (3.14) (pull_request) Failing after 1m59s
2026-09-17 19:27:42 +02:00
admin 0196bcda30 feat(configs): brencher dispatches Actions workflow instead of build+push; deploy pulls image from Gitea CR
Python package / build (3.12.3) (pull_request) Canceled after 36s
Python package / build (3.13) (pull_request) Canceled after 0s
Python package / build (3.14) (pull_request) Canceled after 0s
2026-09-17 19:27:12 +02:00
admin b187e19a6e feat(steps): DockerComposePull for pulling prebuilt image
Python package / build (3.12.3) (pull_request) Canceled after 0s
Python package / build (3.13) (pull_request) Canceled after 0s
Python package / build (3.14) (pull_request) Canceled after 0s
2026-09-17 19:27:07 +02:00
admin 6cbadb4087 feat(steps): GiteaActionsTrigger and GiteaActionsAwait for build dispatch 2026-09-17 19:27:02 +02:00
admin 07911759d2 feat(configs): use PACKAGE_PUSH_USERNAME/TOKEN for Gitea CR; drop legacy registry
Python package / build (3.12.3) (pull_request) Successful in 2m9s
Python package / build (3.13) (pull_request) Successful in 2m14s
Python package / build (3.14) (pull_request) Successful in 2m12s
2026-09-17 18:33:44 +02:00
admin 555b46b746 chore(configs/connectivity_tester): try pushing to Gitea Container Registry
Python package / build (3.12.3) (pull_request) Successful in 2m2s
Python package / build (3.13) (pull_request) Successful in 2m7s
Python package / build (3.14) (pull_request) Successful in 2m24s
publish=True + Gitea registry URL. push will fail with HTTP 401 until GITEA_REGISTRY_USERNAME/GITEA_REGISTRY_PASSWORD are wired in as brencher container env — that's the diagnostic to find out whether the bot token is actually allowed to push to gitea.rudolf.keenetic.link/hermes.
2026-09-15 20:25:42 +02:00
admin 5eef68a1e0 docs(brencher): add AGENTS.md checklist for new stacks
Python package / build (3.12.3) (pull_request) Successful in 2m1s
Python package / build (3.13) (pull_request) Successful in 2m17s
Python package / build (3.14) (pull_request) Successful in 2m13s
2026-09-15 13:58:24 +02:00
admin 055b7e2015 fix(configs/connectivity_tester): wire unmerge for self-deploy
Python package / build (3.12.3) (pull_request) Successful in 2m12s
Python package / build (3.13) (pull_request) Successful in 2m14s
Python package / build (3.14) (pull_request) Successful in 2m51s
Replace state=SharedStateHolderInMemory(unmerge=None) with a GitUnmerge(clone, dockerSwarmCheck)-backed state holder. Without this, desired_branches is always empty, and brencher's polling loop falls through to 'Empty branches set' on every cycle, so the stack only deploys when an operator PATCHes the environment through the UI. With the unmerge in place the swarm service's org.brencher.version label drives state.branches and the stack self-deploys on each polling cycle.
2026-09-15 13:34:31 +02:00
admin db9b3b4cc4 fix(configs/connectivity_tester): drop UrlCheck; DNS not configured yet
Python package / build (3.12.3) (pull_request) Successful in 2m29s
Python package / build (3.13) (pull_request) Successful in 2m23s
Python package / build (3.14) (pull_request) Successful in 2m33s
Tracked in admin/brencher#68.
2026-09-15 08:15:31 +02:00
hermes ce2f5f6210 fix(configs): drop unmerge step from pipeline
Python package / build (3.12.3) (pull_request) Successful in 2m45s
Python package / build (3.13) (pull_request) Successful in 2m52s
Python package / build (3.14) (pull_request) Successful in 2m50s
Same fix as hermes_infra.py — pass unmerge=None to SharedStateHolderInMemory
and skip the unmerge step entirely. Having unmerge=None in the pipeline
violates mypy's type signature (Pipeline expects AbstractStep, None
is not assignable), causing the brencher image build to fail at the
mypy step.

This is the same workaround as hermes_infra (PR #83): the stack is
managed via direct pushes, not via UI state, so unmerge is not needed.
2026-09-14 20:40:29 +00:00
hermes 175d1f933e fix(configs): use unmerge=None for connectivity_tester
Python package / build (3.12.3) (pull_request) Failing after 2m23s
Python package / build (3.13) (pull_request) Failing after 2m23s
Python package / build (3.14) (pull_request) Failing after 2m24s
Without an entry in the brencher UI state.branches for connectivity_tester,
GitUnmerge.progress() returns an empty set and the pipeline raises
'Expected exactly one version, got: set()'. This stalls the brencher
loop, blocking other stacks (including brencher self-deploy) from being
processed.

Same workaround as hermes_infra.py (which uses unmerge=None because
its stacks are managed via direct pushes, not via UI).
2026-09-14 17:45:09 +00:00
hermes 2d51cd71f3 chore(compose): add connectivity_tester to PROFILES env
Python package / build (3.12.3) (pull_request) Successful in 2m25s
Python package / build (3.13) (pull_request) Successful in 2m55s
Python package / build (3.14) (pull_request) Successful in 2m47s
Without this, brencher's _discover_environments() does not see the
connectivity_tester.py module on next restart. Adding to the comma-
separated PROFILES env wires it in.

Also undo the misplaced relocation from 4586136: clone remote and
docker_compose_path point back at admin/ansible (the compose lives in
admin/ansible#39, not in brencher).
2026-09-14 17:26:56 +00:00
hermes 45861362c2 feat(configs): relocate connectivity_tester stack into brencher repo
Python package / build (3.12.3) (pull_request) Failing after 2m18s
Python package / build (3.13) (pull_request) Failing after 2m7s
Python package / build (3.14) (pull_request) Failing after 2m6s
Move compose + Python service + Dockerfile into backend/configs/connectivity_tester/
so the stack can be deployed from a single repo (no cross-repo compose
lookup at deploy time). The brencher config now points at
admin/brencher instead of admin/ansible, and at the new in-repo
compose path.
2026-09-14 17:03:41 +00:00
hermes 8b8bbbb230 feat(configs): wire DockerComposeBuild into connectivity_tester pipeline
Python package / build (3.12.3) (pull_request) Successful in 2m20s
Python package / build (3.13) (pull_request) Successful in 2m17s
Python package / build (3.14) (pull_request) Successful in 2m19s
admin/ansible#39 has a build section in stack-compose.yml, so the
image must be built locally — buildDocker=None would fail with
'No such image' on deploy. Added a proper DockerComposeBuild step
between checkout and deploy. Image tagged auto-<merge-sha> locally;
no registry push (publish=False).
2026-09-14 13:07:39 +00:00
hermes 1f7ca6609d feat(configs): add connectivity_tester stack
Python package / build (3.12.3) (pull_request) Canceled after 1m30s
Python package / build (3.13) (pull_request) Canceled after 0s
Python package / build (3.14) (pull_request) Canceled after 0s
Long-running Swarm service that runs TCP probes against an allow-list of
internal+external endpoints and a negative-list (cloud metadata etc.)
every 10 minutes. Logs structured PASS/FAIL per check.

Stack lives in admin/ansible under connectivity_tester/. One task per
node via mode: global. Resolves Org1/hermes-voice-gateway#5
(connectivity testing blocker for #3).
2026-09-14 13:05:12 +00:00
5 changed files with 242 additions and 36 deletions
+13 -11
View File
@@ -7,11 +7,13 @@ from steps.docker import DockerSwarmCheck, DockerSwarmDeploy
from steps.git import CheckoutMerged, GitClone, GitUnmerge
from steps.shared_state import SharedStateHolderInMemory
clone = GitClone(remotes=[
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/ansible"},
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/ansible"},
],
credEnvPrefix="GITEA",
clone = GitClone(
remotes=[
{"name": "gitea_hermes", "url": "https://gitea.rudolf.keenetic.link/hermes/swarm_connectivity_tester"},
{"name": "gitea_admin", "url": "https://gitea.rudolf.keenetic.link/admin/swarm_connectivity_tester"},
{"name": "gitea_org1", "url": "https://gitea.rudolf.keenetic.link/org1/swarm_connectivity_tester"},
],
credEnvPrefix="GITEA",
)
dockerSwarmCheck = DockerSwarmCheck(stack_name="connectivity_tester")
@@ -22,7 +24,7 @@ state = SharedStateHolderInMemory(unmerge=unmerge)
checkoutMerged = CheckoutMerged(
clone,
desired_branches=state,
push="gitea_admin",
push="gitea_org1",
git_user_email="rudolfss13@gmail.com",
git_user_name="brencher_bot",
)
@@ -30,8 +32,8 @@ checkoutMerged = CheckoutMerged(
GITEA_API = os.environ.get("GITEA_API", "https://gitea.rudolf.keenetic.link/api/v1")
GITEA_TOKEN = os.environ.get("GITEA_TOKEN", "")
WORKFLOW_OWNER = "admin"
WORKFLOW_REPO = "ansible"
WORKFLOW_OWNER = "org1"
WORKFLOW_REPO = "swarm_connectivity_tester"
WORKFLOW_FILE = "release.yml"
def _inputs() -> dict:
@@ -53,7 +55,7 @@ await_build = GiteaActionsAwait(
owner=WORKFLOW_OWNER,
repo=WORKFLOW_REPO,
token=GITEA_TOKEN,
run=lambda: trigger_build.progress(),
run=trigger_build,
)
deployDocker = DockerSwarmDeploy(
@@ -62,10 +64,10 @@ deployDocker = DockerSwarmDeploy(
stackChecker=dockerSwarmCheck,
envs=lambda: {
"version": "auto-" + checkoutMerged.progress().version,
"registry_owner": "admin",
"registry_owner": "org1",
},
stack_name="connectivity_tester",
docker_compose_path="connectivity_tester/stack-compose.yml",
docker_compose_path="stack-compose.yml",
)
logUrls = SimpleLog(message={
+63 -25
View File
@@ -51,6 +51,8 @@ class GiteaActionsTrigger(AbstractStep[GiteaActionsRun]):
self.wd = wd
self.poll_timeout_sec = poll_timeout_sec
self.poll_interval_sec = poll_interval_sec
self._last_request_key: tuple[Optional[str], tuple[tuple[str, str], ...]] | None = None
self._last_run: GiteaActionsRun | None = None
def _http(self, method: str, url: str, body: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
data = None
@@ -84,13 +86,40 @@ class GiteaActionsTrigger(AbstractStep[GiteaActionsRun]):
)
def progress(self) -> GiteaActionsRun:
latest = self._list_recent_runs()
if self.env.dry:
logger.info("DRY RUN: Skipping Gitea Actions workflow dispatch.")
return GiteaActionsRun(
run_id=0,
status="dry-run",
conclusion=None,
html_url="",
)
resolved_inputs: Dict[str, str] = {}
if callable(self.inputs):
resolved_inputs = self.inputs() or {}
elif isinstance(self.inputs, dict):
resolved_inputs = self.inputs
ref = self.ref() if callable(self.ref) else self.ref
request_key = (ref, tuple(sorted(resolved_inputs.items())))
latest = self._list_recent_runs()
if latest is not None and latest.status != "completed":
logger.info("Gitea Actions run %s is already active; reusing it.", latest.run_id)
self._last_request_key = request_key
self._last_run = latest
return latest
if (
self._last_request_key == request_key
and self._last_run is not None
and latest is not None
and latest.run_id == self._last_run.run_id
and latest.conclusion == "success"
):
logger.info("Gitea Actions run %s already succeeded; reusing it.", latest.run_id)
return latest
body: Dict[str, Any] = {"ref": ref}
if resolved_inputs:
body["inputs"] = resolved_inputs
@@ -116,6 +145,8 @@ class GiteaActionsTrigger(AbstractStep[GiteaActionsRun]):
if current is None or (latest is not None and current.run_id == latest.run_id):
time.sleep(self.poll_interval_sec)
continue
self._last_request_key = request_key
self._last_run = current
return current
raise TimeoutError(
f"Gitea Actions did not pick up a new run within {self.poll_timeout_sec}s"
@@ -130,7 +161,7 @@ class GiteaActionsAwait(AbstractStep[GiteaActionsRun]):
owner: str,
repo: str,
token: str,
run: Callable[[], GiteaActionsRun],
run: Union[AbstractStep[GiteaActionsRun], Callable[[], GiteaActionsRun]],
poll_timeout_sec: int = 1800,
poll_interval_sec: int = 10,
**kwargs: Any) -> None:
@@ -150,28 +181,35 @@ class GiteaActionsAwait(AbstractStep[GiteaActionsRun]):
return json.loads(r.read().decode())
def progress(self) -> GiteaActionsRun:
run = self._run()
deadline = time.time() + self.poll_timeout_sec
while time.time() < deadline:
data = self._http(
"GET",
f"{self.api_base}/repos/{self.owner}/{self.repo}/actions/runs/{run.run_id}",
if self.env.dry:
logger.info("DRY RUN: Skipping wait for Gitea Actions workflow.")
return GiteaActionsRun(
run_id=0,
status="dry-run",
conclusion=None,
html_url="",
)
status = data.get("status", "")
conclusion = data.get("conclusion")
if status == "completed":
if conclusion != "success":
raise RuntimeError(
f"Gitea Actions run {run.run_id} concluded with {conclusion}: "
f"{run.html_url}"
)
return GiteaActionsRun(
run_id=run.run_id,
status=status,
conclusion=conclusion,
html_url=run.html_url,
)
time.sleep(self.poll_interval_sec)
raise TimeoutError(
f"Gitea Actions run {run.run_id} did not complete within {self.poll_timeout_sec}s"
run = self._run.progress() if isinstance(self._run, AbstractStep) else self._run()
data = self._http(
"GET",
f"{self.api_base}/repos/{self.owner}/{self.repo}/actions/runs/{run.run_id}",
)
status = data.get("status", "")
conclusion = data.get("conclusion")
if status != "completed":
raise RuntimeError(
f"Gitea Actions run {run.run_id} is not completed: {status}: "
f"{run.html_url}"
)
if conclusion != "success":
raise RuntimeError(
f"Gitea Actions run {run.run_id} concluded with {conclusion}: "
f"{run.html_url}"
)
return GiteaActionsRun(
run_id=run.run_id,
status=status,
conclusion=conclusion,
html_url=run.html_url,
)
+1
View File
@@ -296,6 +296,7 @@ class DockerSwarmDeploy(AbstractStep[str]):
# Deploy stack to Docker Swarm
cmd = [
"docker", "stack", "deploy",
"--with-registry-auth",
"--detach=false",
"--prune",
"-c", tmp_compose_path,
+49
View File
@@ -0,0 +1,49 @@
import json
import logging
import os
import re
import subprocess
from typing import Any, Callable, Dict
import yaml
from enironment import AbstractStep
from steps.git import GitClone
logger = logging.getLogger(__name__)
class DockerComposePull(AbstractStep[Dict[str, str]]):
"""Pull images referenced by a docker-compose file from a remote registry."""
def __init__(self,
wd: GitClone,
docker_compose_path: str,
envs: Callable[[], Dict[str, Any]],
**kwargs: Any) -> None:
super().__init__(**kwargs)
self.wd = wd
self.envs = envs
self.docker_compose_path = docker_compose_path
def progress(self) -> Dict[str, str]:
env = self.envs()
compose_path = os.path.join(self.wd.progress(), self.docker_compose_path)
with open(compose_path, "r") as f:
content = f.read()
content = re.sub(r"\$\{([^}]+)\}", lambda m: env.get(m.group(1), ""), content)
compose = yaml.safe_load(content)
for svc in compose.get("services", {}).values():
if "build" in svc:
del svc["build"]
tmp_path = compose_path + ".pull.yml"
with open(tmp_path, "w") as f:
yaml.safe_dump(compose, f)
try:
subprocess.run(
["docker", "compose", "-f", tmp_path, "pull"],
check=True,
cwd=self.wd.progress(),
)
finally:
os.unlink(tmp_path)
return {name: svc.get("image", "") for name, svc in compose.get("services", {}).items()}
+116
View File
@@ -0,0 +1,116 @@
from typing import Any
import pytest
from enironment import AbstractStep, Environment
from steps.actions import GiteaActionsAwait, GiteaActionsRun, GiteaActionsTrigger
from steps.shared_state import SharedStateHolderInMemory
class FixedRun(AbstractStep[GiteaActionsRun]):
def __init__(self) -> None:
super().__init__()
self.calls = 0
def progress(self) -> GiteaActionsRun:
self.calls += 1
return GiteaActionsRun(42, "queued", None, "http://example/run/42")
def _environment(*steps: AbstractStep[Any], dry: bool) -> Environment:
return Environment(
id="actions-test",
state=SharedStateHolderInMemory(unmerge=None),
pipeline=list(steps),
)
def _trigger() -> GiteaActionsTrigger:
return GiteaActionsTrigger(
api_base="https://gitea.example/api/v1",
owner="owner",
repo="repo",
workflow_file="release.yml",
ref="main",
token="token",
)
def test_trigger_skips_dispatch_in_dry_run() -> None:
trigger = _trigger()
env = _environment(trigger, dry=True)
env.state.set_dry(True)
trigger._http = lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("HTTP call")) # type: ignore[method-assign]
result = trigger.progress()
assert result.status == "dry-run"
assert result.run_id == 0
def test_trigger_reuses_active_run(monkeypatch: pytest.MonkeyPatch) -> None:
trigger = _trigger()
env = _environment(trigger, dry=False)
runs = iter([
None,
GiteaActionsRun(42, "in_progress", None, "http://example/run/42"),
GiteaActionsRun(42, "in_progress", None, "http://example/run/42"),
])
dispatches = 0
def fake_http(method: str, url: str, body: dict[str, Any] | None = None) -> dict[str, Any]:
nonlocal dispatches
if method == "POST":
dispatches += 1
return {}
monkeypatch.setattr(trigger, "_list_recent_runs", lambda: next(runs))
monkeypatch.setattr(trigger, "_http", fake_http)
trigger.poll_interval_sec = 0
trigger.poll_timeout_sec = 1
first = trigger.progress()
second = trigger.progress()
assert first.run_id == 42
assert second.run_id == 42
assert dispatches == 1
def test_await_skips_polling_in_dry_run() -> None:
run = FixedRun()
await_step = GiteaActionsAwait(
api_base="https://gitea.example/api/v1",
owner="owner",
repo="repo",
token="token",
run=run,
)
env = _environment(run, await_step, dry=True)
env.state.set_dry(True)
await_step._http = lambda *args, **kwargs: (_ for _ in ()).throw(AssertionError("HTTP call")) # type: ignore[method-assign]
result = await_step.progress()
assert result.status == "dry-run"
assert run.calls == 0
def test_await_raises_when_run_is_not_completed(monkeypatch: pytest.MonkeyPatch) -> None:
run = FixedRun()
await_step = GiteaActionsAwait(
api_base="https://gitea.example/api/v1",
owner="owner",
repo="repo",
token="token",
run=run,
)
env = _environment(run, await_step, dry=False)
monkeypatch.setattr(
await_step,
"_http",
lambda *args, **kwargs: {"status": "in_progress", "conclusion": None},
)
with pytest.raises(RuntimeError, match="is not completed"):
await_step.progress()