nixosTests.forgejo{,-lts}: simplify workflow subtest (#398217)

authored by Adam C. Stephens and committed by GitHub 21dcd7bb 4db241de

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