From bc4f1f16c7d29314db5b1ad495a59708d56ab996 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Aug 28 2025 08:59:36 +0000 Subject: [PATCH 1/4] Return the koji task_id early --- diff --git a/roles/fedpkg-build-ng/tasks/main.yaml b/roles/fedpkg-build-ng/tasks/main.yaml index 8b39f09..7ed82f4 100644 --- a/roles/fedpkg-build-ng/tasks/main.yaml +++ b/roles/fedpkg-build-ng/tasks/main.yaml @@ -47,6 +47,7 @@ fedpkg --release {{ release }} build {% if scratch_build %} --scratch --arches {{ arches }} --skip-nvr-check --background {% endif %} --target {{ target }} + --nowait args: chdir: "{{ zuul.project.src_dir }}" register: fedpkg_build @@ -61,6 +62,10 @@ - fedpkg_build.stdout is not search("ServerOffline") ignore_errors: yes +- fail: + msg: "Build failed to submit:\n{{ fedpkg_build.stdout }}" + when: fedpkg_build is failure + - name: Get task ID set_fact: task_id: "{{ fedpkg_build.stdout | regex_replace('\n', ' ') | regex_replace('.*Created task: (\\d+).*$', '\\1') }}" @@ -73,6 +78,11 @@ - name: "Koji Task URL" url: "{{ koji_task_url_base }}{{ task_id }}" +- name: Wait for koji task to finish + command: koji watch-task {{ task_id }} + register: koji_watch_task + ignore_errors: yes + - block: - name: Download artifacts from Koji command: | @@ -93,9 +103,9 @@ - name: repo url: repo when: - - fedpkg_build is not failure + - koji_watch_task is not failure - fetch_artifacts - fail: msg: "Build failed - check build at {{ koji_task_url_base }}{{ task_id}}" - when: fedpkg_build is failure + when: koji_watch_task is failure From e165e87ba2a9f1993b894c5434df0c6faf2c581e Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Aug 28 2025 15:53:32 +0000 Subject: [PATCH 2/4] Add fedpkg-build-cleanup role --- diff --git a/roles/fedpkg-build-cleanup/tasks/main.yaml b/roles/fedpkg-build-cleanup/tasks/main.yaml new file mode 100644 index 0000000..bd3ba6c --- /dev/null +++ b/roles/fedpkg-build-cleanup/tasks/main.yaml @@ -0,0 +1,16 @@ +- assert: + fail_msg: "Expected task_id to be defined, but it wasn't" + that: task_id is defined + +- name: Get the current state of Koji task + command: koji taskinfo {{ task_id }} + register: koji_taskinfo + +- name: Get koji task state + set_fact: + task_state: "{{ koji_taskinfo.stdout | regex_search('State: (\\w+)') }}" + +# TODO: Do not cancel timed-out builds +- name: Cancel koji scratch build + command: koji cancel {{ task_id }} + when: task_state in ('open', 'assigned') diff --git a/roles/fedpkg-build-ng/tasks/main.yaml b/roles/fedpkg-build-ng/tasks/main.yaml index 7ed82f4..2d28034 100644 --- a/roles/fedpkg-build-ng/tasks/main.yaml +++ b/roles/fedpkg-build-ng/tasks/main.yaml @@ -42,6 +42,7 @@ - git branch -u origin/{{ pr_info.json.branch_from }} when: scratch_build +# TODO: Skip building if we already have a task from a previous timed-out run - name: Build package in Fedora build system {% if scratch_build %}(scratch build){% endif %} command: | fedpkg --release {{ release }} build From 58b6509a5ddeeaa3f40d69c2798bdd1ece812e26 Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Aug 29 2025 20:50:37 +0000 Subject: [PATCH 3/4] Do not cancel the task if it timedout --- diff --git a/roles/fedpkg-build-cleanup/tasks/main.yaml b/roles/fedpkg-build-cleanup/tasks/main.yaml index bd3ba6c..9510673 100644 --- a/roles/fedpkg-build-cleanup/tasks/main.yaml +++ b/roles/fedpkg-build-cleanup/tasks/main.yaml @@ -2,15 +2,18 @@ fail_msg: "Expected task_id to be defined, but it wasn't" that: task_id is defined -- name: Get the current state of Koji task - command: koji taskinfo {{ task_id }} - register: koji_taskinfo +- name: Cancel any running scratch builds + block: + - name: Get the current state of Koji task + command: koji taskinfo {{ task_id }} + register: koji_taskinfo -- name: Get koji task state - set_fact: - task_state: "{{ koji_taskinfo.stdout | regex_search('State: (\\w+)') }}" + - name: Get koji task state + set_fact: + task_state: "{{ koji_taskinfo.stdout | regex_search('State: (\\w+)') }}" -# TODO: Do not cancel timed-out builds -- name: Cancel koji scratch build - command: koji cancel {{ task_id }} - when: task_state in ('open', 'assigned') + - name: Cancel koji scratch build + command: koji cancel {{ task_id }} + when: task_state in ('open', 'assigned') + # Do not run this if the job was successful or it timed-out (koji_task_returned was not reached) + when: not (zuul_success | bool or koji_task_returned is not defined) diff --git a/roles/fedpkg-build-ng/tasks/main.yaml b/roles/fedpkg-build-ng/tasks/main.yaml index 2d28034..3d41bd5 100644 --- a/roles/fedpkg-build-ng/tasks/main.yaml +++ b/roles/fedpkg-build-ng/tasks/main.yaml @@ -84,6 +84,11 @@ register: koji_watch_task ignore_errors: yes +# If the job has timed-out we would not get to this point +- name: Note that watch-task did not timeout + set_fact: + koji_task_returned: true + - block: - name: Download artifacts from Koji command: | From 76f2bc4c16e1356a8fd85e4bfff5f5a349c95baa Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Sep 01 2025 09:59:35 +0000 Subject: [PATCH 4/4] Do nothing if task_id was not yet defined task_id is defined quite late, and the job might have been canceled before that. --- diff --git a/roles/fedpkg-build-cleanup/tasks/main.yaml b/roles/fedpkg-build-cleanup/tasks/main.yaml index 9510673..f51bc22 100644 --- a/roles/fedpkg-build-cleanup/tasks/main.yaml +++ b/roles/fedpkg-build-cleanup/tasks/main.yaml @@ -1,7 +1,3 @@ -- assert: - fail_msg: "Expected task_id to be defined, but it wasn't" - that: task_id is defined - - name: Cancel any running scratch builds block: - name: Get the current state of Koji task @@ -16,4 +12,6 @@ command: koji cancel {{ task_id }} when: task_state in ('open', 'assigned') # Do not run this if the job was successful or it timed-out (koji_task_returned was not reached) - when: not (zuul_success | bool or koji_task_returned is not defined) + when: > + task_id is defined and + not (zuul_success | bool or koji_task_returned is not defined)