nixosTests.forgejo{,-lts}: simplify workflow subtest

This is substantially less hacky and less fragile than the previous
approach that used htmlq to parse the raw html returned by the frontend
and then compared the extracted status against a hardcoded list of known
translated statuses.

Back when this subtest was added, there simply was no API endpoint to
gather this information yet. I had this in my out of tree variant of
Forgejo for a while now.

Requires Forgejo v8.0.0+

Changed files
+10 -16
nixos
tests
+10 -16
nixos/tests/forgejo.nix
···
pkgs.gnupg
pkgs.jq
pkgs.file
-
pkgs.htmlq
];
services.openssh.enable = true;
···
client.succeed("git -C /tmp/repo push origin main")
def poll_workflow_action_status(_) -> bool:
-
output = server.succeed(
-
"curl --fail http://localhost:3000/test/repo/actions | "
-
+ 'htmlq ".flex-item-leading span" --attribute "data-tooltip-content"'
-
).strip()
-
# values taken from https://codeberg.org/forgejo/forgejo/src/commit/af47c583b4fb3190fa4c4c414500f9941cc02389/options/locale/locale_en-US.ini#L3649-L3661
-
if output in [ "Failure", "Canceled", "Skipped", "Blocked" ]:
-
raise Exception(f"Workflow status is '{output}', which we consider failed.")
-
server.log(f"Command returned '{output}', which we consider failed.")
-
elif output in [ "Unknown", "Waiting", "Running", "" ]:
-
server.log(f"Workflow status is '{output}'. Waiting some more...")
-
return False
-
elif output in [ "Success" ]:
-
return True
-
raise Exception(f"Workflow status is '{output}', which we don't know. Value mappings likely need updating.")
with server.nested("Waiting for the workflow run to be successful"):
-
retry(poll_workflow_action_status)
with subtest("Testing backup service"):
server.succeed("${serverSystem}/specialisation/dump/bin/switch-to-configuration test")
···
pkgs.gnupg
pkgs.jq
pkgs.file
];
services.openssh.enable = true;
···
client.succeed("git -C /tmp/repo push origin main")
def poll_workflow_action_status(_) -> bool:
+
try:
+
response = server.succeed("curl --fail http://localhost:3000/api/v1/repos/test/repo/actions/tasks")
+
status = json.loads(response).get("workflow_runs")[0].get("status")
+
except IndexError:
+
status = "???"
+
server.log(f"Workflow status: {status}")
+
if status == "failure":
+
raise Exception("Workflow failed")
+
return status == "success"
with server.nested("Waiting for the workflow run to be successful"):
+
retry(poll_workflow_action_status, 60)
with subtest("Testing backup service"):
server.succeed("${serverSystem}/specialisation/dump/bin/switch-to-configuration test")