From e311aa7cae9c377d2fe71c2080b75ea6d3fc4d14 Mon Sep 17 00:00:00 2001 From: Mathieu Fenniak Date: Fri, 5 Sep 2025 19:31:22 +0200 Subject: [PATCH] fix: action view 'Re-run all jobs' leaves UI on the last attempt, not the new attempt (#9172) In #9017, the ability to view older logs of an action run was added. However, the 'Re-run all jobs' button was not updated in any way. When viewing the logs for attempt 1 and clicking 'Re-run all jobs', the UI would continue to show the logs for attempt 1. Before #9017 the behavior would have begun to view the logs from the re-run operation. There are two commits in this PR: - Update the `Rerun` view handler so that it redirects the user to the next attempt number for the job. - The next attempt number isn't actually persisted to the DB until the rerun is picked up from a worker. By pure coincidence, viewing an out-of-range attempt number was fully functional because it also happened to be viewing a job that wasn't picked up by a worker, and fell into those code paths. However, as there were no automated tests around this codepath and it felt fragile, new tests have been added around the template render, backend data fetch, and frontend UI component, to ensure it continues to work in this corner-case in the future. ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [x] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [x] I do not want this change to show in the release notes. (_Note_: This is a fix for an unreleased regression, no need for release notes.) - [ ] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9172 Reviewed-by: Earl Warren Co-authored-by: Mathieu Fenniak Co-committed-by: Mathieu Fenniak --- models/fixtures/action_run_job.yml | 15 ++++ routers/web/repo/actions/view.go | 48 +++++++++++- routers/web/repo/actions/view_test.go | 80 ++++++++++++++++++++ tests/integration/actions_view_test.go | 34 ++++++++- web_src/js/components/RepoActionView.test.js | 65 ++++++++++++++++ 5 files changed, 239 insertions(+), 3 deletions(-) diff --git a/models/fixtures/action_run_job.yml b/models/fixtures/action_run_job.yml index 9455ac3c41..00f9998ba9 100644 --- a/models/fixtures/action_run_job.yml +++ b/models/fixtures/action_run_job.yml @@ -128,3 +128,18 @@ runs_on: '["fedora"]' started: 1683636528 stopped: 1683636626 +- + id: 396 + run_id: 794 + repo_id: 4 + owner_id: 1 + commit_sha: 985f0301dba5e7b34be866819cd15ad3d8f508ee + is_fork_pull_request: 0 + name: job_2 + attempt: 1 + job_id: job_2 + task_id: null + status: 5 + runs_on: '["fedora"]' + started: 1683636528 + stopped: 1683636626 diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index d9255aaa55..b5e73e9d33 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -336,6 +336,11 @@ func getViewResponse(ctx *context_module.Context, req *ViewRequest, runIndex, jo } var task *actions_model.ActionTask + // TaskID will be set only when the ActionRunJob has been picked by a runner, resulting in an ActionTask being + // created representing the specific task. If current.TaskID is not set, then the user is attempting to view a job + // that hasn't been picked up by a runner... in this case we're not going to try to fetch the specific attempt. + // This helps to support the UI displaying a useful and error-free page when viewing a job that is queued but not + // picked, or an attempt that is queued for rerun but not yet picked. if current.TaskID > 0 { var err error task, err = actions_model.GetTaskByJobAttempt(ctx, current.ID, attemptNumber) @@ -357,6 +362,7 @@ func getViewResponse(ctx *context_module.Context, req *ViewRequest, runIndex, jo } resp.State.CurrentJob.Steps = make([]*ViewJobStep, 0) // marshal to '[]' instead of 'null' in json resp.Logs.StepsLog = make([]*ViewStepLog, 0) // marshal to '[]' instead of 'null' in json + // As noted above with TaskID; task will be nil when the job hasn't be picked yet... if task != nil { taskAttempts, err := task.GetAllAttempts(ctx) if err != nil { @@ -452,6 +458,12 @@ func getViewResponse(ctx *context_module.Context, req *ViewRequest, runIndex, jo return resp } +// When used with the JS `linkAction` handler (typically a