From 45db3c98a3d7c9c220f635f7d46e67d488030356 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Fri, 20 Feb 2026 03:11:29 +0100 Subject: [PATCH] feat: link CI job to its defining workflow file (#11216) Fixes #11036. This adds a link from a CI run to the file that its workflow was taken from. | Before | After | |---------|---------| | ![screenshot](/attachments/49741492-c98b-4a9a-b8bf-f6628698e008) | ![image](/attachments/8ec7dd76-d4ba-4f58-a63a-dd7886e16aae) | Before: * the `test.yml` link points to the list of other runs (`/org123/repo2/actions?workflow=test.yml`) After: * the `test.yml` link points to the workflow definition (`/org123/repo2/src/commit/55b048363c8cfa7d9e8b5cade5c75681bd0c7328/.forgejo/workflows/test.yml`) * the `all runs` link points to the list of other runs (`/org123/repo2/actions?workflow=test.yml`) I have tried to retain the existing link to the list of workflow runs (moving it to a separate link), but I am not sure if this link should be retained at all and if so how. ## Checklist ### 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... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [x] 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] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change. - [ ] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change. ## Release notes - Features - [PR](https://codeberg.org/forgejo/forgejo/pulls/11216): link CI job to its defining workflow file Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11216 Reviewed-by: Andreas Ahlenstorf Reviewed-by: Mathieu Fenniak Co-authored-by: Antonin Delpeuch Co-committed-by: Antonin Delpeuch --- models/actions/run.go | 8 ++++++++ models/actions/run_test.go | 8 ++++++++ options/locale_next/locale_en-US.json | 1 + routers/web/repo/actions/view.go | 3 +++ routers/web/repo/actions/view_test.go | 1 + templates/repo/actions/view.tmpl | 1 + tests/e2e/actions.test.e2e.ts | 8 ++++++++ tests/integration/actions_view_test.go | 4 ++-- web_src/js/components/RepoActionView.test.js | 1 + web_src/js/components/RepoActionView.vue | 7 ++++++- web_src/js/features/repo-action-view.ts | 1 + 11 files changed, 40 insertions(+), 3 deletions(-) diff --git a/models/actions/run.go b/models/actions/run.go index f411c5d5e5..c4e4a40eb2 100644 --- a/models/actions/run.go +++ b/models/actions/run.go @@ -104,6 +104,14 @@ func (run *ActionRun) Link() string { return fmt.Sprintf("%s/actions/runs/%d", run.Repo.Link(), run.Index) } +// WorkflowPath returns the path in the git repo to the workflow file that this run was based on +func (run *ActionRun) WorkflowPath() string { + if run.WorkflowDirectory == "" { + return run.WorkflowID + } + return run.WorkflowDirectory + "/" + run.WorkflowID +} + // RefLink return the url of run's ref func (run *ActionRun) RefLink() string { refName := git.RefName(run.Ref) diff --git a/models/actions/run_test.go b/models/actions/run_test.go index e3e2bd46ad..f027512c75 100644 --- a/models/actions/run_test.go +++ b/models/actions/run_test.go @@ -45,6 +45,14 @@ func TestSetDefaultConcurrencyGroup(t *testing.T) { assert.Equal(t, "refs/heads/main_testing_pull_request__auto", run.ConcurrencyGroup) } +func TestGetWorkflowPath(t *testing.T) { + run := ActionRun{ + WorkflowID: "ci.yml", + WorkflowDirectory: ".some/path/to/workflows", + } + assert.Equal(t, ".some/path/to/workflows/ci.yml", run.WorkflowPath()) +} + func TestRepoNumOpenActions(t *testing.T) { require.NoError(t, unittest.PrepareTestDatabase()) err := cache.Init() diff --git a/options/locale_next/locale_en-US.json b/options/locale_next/locale_en-US.json index 8127dbf4b9..9bd18cd565 100644 --- a/options/locale_next/locale_en-US.json +++ b/options/locale_next/locale_en-US.json @@ -462,6 +462,7 @@ "actions.runs.status_no_select": "All status", "actions.runs.no_results": "No results matched.", "actions.runs.no_workflows": "There are no workflows yet.", + "actions.runs.all_runs_link": "all runs", "actions.workflow.job_parsing_error": "Unable to parse jobs in workflow: %v", "actions.workflow.event_detection_error": "Unable to parse supported events in workflow: %v", "actions.workflow.persistent_incomplete_matrix": "Unable to evaluate `strategy.matrix` of job %[1]s due to a `needs` expression that was invalid. It may reference a job that is not in it's 'needs' list (%[2]s), or an output that doesn't exist on one of those jobs.", diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 68466ee848..caa35d37be 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -82,6 +82,7 @@ func View(ctx *app_context.Context) { ctx.Data["AttemptNumber"] = attemptNumber ctx.Data["WorkflowName"] = workflowName ctx.Data["WorkflowURL"] = ctx.Repo.RepoLink + "/actions?workflow=" + workflowName + ctx.Data["WorkflowSourceURL"] = ctx.Repo.RepoLink + "/src/commit/" + job.Run.CommitSHA + "/" + job.Run.WorkflowPath() viewResponse := getViewResponse(ctx, &ViewRequest{}, runIndex, jobIndex, attemptNumber) if ctx.Written() { @@ -205,6 +206,7 @@ type ViewCommit struct { LocaleCommit string `json:"localeCommit"` LocalePushedBy string `json:"localePushedBy"` LocaleWorkflow string `json:"localeWorkflow"` + LocaleAllRuns string `json:"localeAllRuns"` ShortSha string `json:"shortSHA"` Link string `json:"link"` Pusher ViewUser `json:"pusher"` @@ -333,6 +335,7 @@ func getViewResponse(ctx *app_context.Context, req *ViewRequest, runIndex, jobIn LocaleCommit: ctx.Locale.TrString("actions.runs.commit"), LocalePushedBy: ctx.Locale.TrString("actions.runs.pushed_by"), LocaleWorkflow: ctx.Locale.TrString("actions.runs.workflow"), + LocaleAllRuns: ctx.Locale.TrString("actions.runs.all_runs_link"), ShortSha: base.ShortSha(run.CommitSHA), Link: fmt.Sprintf("%s/commit/%s", run.Repo.Link(), run.CommitSHA), Pusher: pusher, diff --git a/routers/web/repo/actions/view_test.go b/routers/web/repo/actions/view_test.go index 48ebdf4cdc..c636570c7e 100644 --- a/routers/web/repo/actions/view_test.go +++ b/routers/web/repo/actions/view_test.go @@ -168,6 +168,7 @@ func baseExpectedViewResponse() *ViewResponse { LocaleCommit: "actions.runs.commit", LocalePushedBy: "actions.runs.pushed_by", LocaleWorkflow: "actions.runs.workflow", + LocaleAllRuns: "actions.runs.all_runs_link", ShortSha: "c2d72f5484", Link: "/user5/repo4/commit/c2d72f548424103f01ee1dc02889c1e2bff816b0", Pusher: ViewUser{ diff --git a/templates/repo/actions/view.tmpl b/templates/repo/actions/view.tmpl index 6adc91417c..04aced83d1 100644 --- a/templates/repo/actions/view.tmpl +++ b/templates/repo/actions/view.tmpl @@ -10,6 +10,7 @@ data-actions-url="{{.ActionsURL}}" data-workflow-name="{{.WorkflowName}}" data-workflow-url="{{.WorkflowURL}}" + data-workflow-source-url="{{.WorkflowSourceURL}}" data-initial-post-response="{{.InitialData}}" data-initial-artifacts-response="{{.InitialArtifactsData}}" data-locale-approve="{{ctx.Locale.Tr "repo.pulls.poster_manage_approval"}}" diff --git a/tests/e2e/actions.test.e2e.ts b/tests/e2e/actions.test.e2e.ts index 8981d037d3..97af63dd54 100644 --- a/tests/e2e/actions.test.e2e.ts +++ b/tests/e2e/actions.test.e2e.ts @@ -126,6 +126,14 @@ test('workflow dispatch box not available for unauthenticated users', async ({pa await screenshot(page, page.locator('div.ui.container').filter({hasText: 'All workflows'})); }); +test('job run links to its defining file and all other runs from the same file', async ({page}) => { + await page.goto('/user2/test_workflows/actions/runs/1'); + await expect(page.locator('.action-summary a').getByText('test-dispatch.yml', {exact: true})) + .toHaveAttribute('href', '/user2/test_workflows/src/commit/774f93df12d14931ea93259ae93418da4482fcc1/.forgejo/workflows/test-dispatch.yml'); + await expect(page.locator('.action-summary a').getByText('all runs', {exact: true})) + .toHaveAttribute('href', '/user2/test_workflows/actions?workflow=test-dispatch.yml'); +}); + async function completeDynamicRefresh(page: Page) { // Ensure that the reloading indicator isn't active, indicating that dynamic refresh is done. await expect(page.locator('#reloading-indicator')).not.toHaveClass(/(^|\s)is-loading(\s|$)/); diff --git a/tests/integration/actions_view_test.go b/tests/integration/actions_view_test.go index b3f40f17ff..6314ce1e4f 100644 --- a/tests/integration/actions_view_test.go +++ b/tests/integration/actions_view_test.go @@ -153,7 +153,7 @@ func TestActionViewsView(t *testing.T) { re = regexp.MustCompile(pattern) actualClean = re.ReplaceAllString(actualClean, `"time_since_started_html":"_time_"`) - return assert.JSONEq(t, "{\"state\":{\"run\":{\"preExecutionError\":\"\",\"link\":\"/user5/repo4/actions/runs/187\",\"title\":\"update actions\",\"titleHTML\":\"update actions\",\"status\":\"success\",\"canCancel\":false,\"canApprove\":false,\"canRerun\":false,\"canDeleteArtifact\":false,\"done\":true,\"jobs\":[{\"id\":192,\"name\":\"job_2\",\"status\":\"success\",\"canRerun\":false,\"duration\":\"_duration_\"}],\"commit\":{\"localeCommit\":\"Commit\",\"localePushedBy\":\"pushed by\",\"localeWorkflow\":\"Workflow\",\"shortSHA\":\"c2d72f5484\",\"link\":\"/user5/repo4/commit/c2d72f548424103f01ee1dc02889c1e2bff816b0\",\"pusher\":{\"displayName\":\"user1\",\"link\":\"/user1\"},\"branch\":{\"name\":\"master\",\"link\":\"/user5/repo4/src/branch/master\",\"isDeleted\":false}}},\"currentJob\":{\"title\":\"job_2\",\"details\":[\"Success\"],\"steps\":[{\"summary\":\"Set up job\",\"duration\":\"_duration_\",\"status\":\"success\"},{\"summary\":\"Complete job\",\"duration\":\"_duration_\",\"status\":\"success\"}],\"allAttempts\":[{\"number\":3,\"time_since_started_html\":\"_time_\",\"status\":\"running\",\"status_diagnostics\":[\"Running\"]},{\"number\":2,\"time_since_started_html\":\"_time_\",\"status\":\"success\",\"status_diagnostics\":[\"Success\"]},{\"number\":1,\"time_since_started_html\":\"_time_\",\"status\":\"success\",\"status_diagnostics\":[\"Success\"]}]}},\"logs\":{\"stepsLog\":[]}}\n", actualClean) + return assert.JSONEq(t, "{\"state\":{\"run\":{\"preExecutionError\":\"\",\"link\":\"/user5/repo4/actions/runs/187\",\"title\":\"update actions\",\"titleHTML\":\"update actions\",\"status\":\"success\",\"canCancel\":false,\"canApprove\":false,\"canRerun\":false,\"canDeleteArtifact\":false,\"done\":true,\"jobs\":[{\"id\":192,\"name\":\"job_2\",\"status\":\"success\",\"canRerun\":false,\"duration\":\"_duration_\"}],\"commit\":{\"localeCommit\":\"Commit\",\"localePushedBy\":\"pushed by\",\"localeWorkflow\":\"Workflow\",\"localeAllRuns\":\"all runs\",\"shortSHA\":\"c2d72f5484\",\"link\":\"/user5/repo4/commit/c2d72f548424103f01ee1dc02889c1e2bff816b0\",\"pusher\":{\"displayName\":\"user1\",\"link\":\"/user1\"},\"branch\":{\"name\":\"master\",\"link\":\"/user5/repo4/src/branch/master\",\"isDeleted\":false}}},\"currentJob\":{\"title\":\"job_2\",\"details\":[\"Success\"],\"steps\":[{\"summary\":\"Set up job\",\"duration\":\"_duration_\",\"status\":\"success\"},{\"summary\":\"Complete job\",\"duration\":\"_duration_\",\"status\":\"success\"}],\"allAttempts\":[{\"number\":3,\"time_since_started_html\":\"_time_\",\"status\":\"running\",\"status_diagnostics\":[\"Running\"]},{\"number\":2,\"time_since_started_html\":\"_time_\",\"status\":\"success\",\"status_diagnostics\":[\"Success\"]},{\"number\":1,\"time_since_started_html\":\"_time_\",\"status\":\"success\",\"status_diagnostics\":[\"Success\"]}]}},\"logs\":{\"stepsLog\":[]}}\n", actualClean) }) htmlDoc.AssertAttrEqual(t, selector, "data-initial-artifacts-response", "{\"artifacts\":[{\"name\":\"multi-file-download\",\"size\":2048,\"status\":\"completed\"}]}\n") } @@ -185,7 +185,7 @@ func TestActionViewsViewAttemptOutOfRange(t *testing.T) { re = regexp.MustCompile(pattern) actualClean = re.ReplaceAllString(actualClean, `"time_since_started_html":"_time_"`) - return assert.JSONEq(t, "{\"state\":{\"run\":{\"preExecutionError\":\"\",\"link\":\"/user5/repo4/actions/runs/190\",\"title\":\"job output\",\"titleHTML\":\"job output\",\"status\":\"success\",\"canCancel\":false,\"canApprove\":false,\"canRerun\":false,\"canDeleteArtifact\":false,\"done\":false,\"jobs\":[{\"id\":396,\"name\":\"job_2\",\"status\":\"waiting\",\"canRerun\":false,\"duration\":\"_duration_\"}],\"commit\":{\"localeCommit\":\"Commit\",\"localePushedBy\":\"pushed by\",\"localeWorkflow\":\"Workflow\",\"shortSHA\":\"c2d72f5484\",\"link\":\"/user5/repo4/commit/c2d72f548424103f01ee1dc02889c1e2bff816b0\",\"pusher\":{\"displayName\":\"user1\",\"link\":\"/user1\"},\"branch\":{\"name\":\"test\",\"link\":\"/user5/repo4/src/branch/test\",\"isDeleted\":true}}},\"currentJob\":{\"title\":\"job_2\",\"details\":[\"Waiting for a runner with the following label: fedora\"],\"steps\":[],\"allAttempts\":null}},\"logs\":{\"stepsLog\":[]}}\n", actualClean) + return assert.JSONEq(t, "{\"state\":{\"run\":{\"preExecutionError\":\"\",\"link\":\"/user5/repo4/actions/runs/190\",\"title\":\"job output\",\"titleHTML\":\"job output\",\"status\":\"success\",\"canCancel\":false,\"canApprove\":false,\"canRerun\":false,\"canDeleteArtifact\":false,\"done\":false,\"jobs\":[{\"id\":396,\"name\":\"job_2\",\"status\":\"waiting\",\"canRerun\":false,\"duration\":\"_duration_\"}],\"commit\":{\"localeCommit\":\"Commit\",\"localePushedBy\":\"pushed by\",\"localeWorkflow\":\"Workflow\",\"localeAllRuns\":\"all runs\",\"shortSHA\":\"c2d72f5484\",\"link\":\"/user5/repo4/commit/c2d72f548424103f01ee1dc02889c1e2bff816b0\",\"pusher\":{\"displayName\":\"user1\",\"link\":\"/user1\"},\"branch\":{\"name\":\"test\",\"link\":\"/user5/repo4/src/branch/test\",\"isDeleted\":true}}},\"currentJob\":{\"title\":\"job_2\",\"details\":[\"Waiting for a runner with the following label: fedora\"],\"steps\":[],\"allAttempts\":null}},\"logs\":{\"stepsLog\":[]}}\n", actualClean) }) htmlDoc.AssertAttrEqual(t, selector, "data-initial-artifacts-response", "{\"artifacts\":[]}\n") } diff --git a/web_src/js/components/RepoActionView.test.js b/web_src/js/components/RepoActionView.test.js index db6c4035e8..12c201916f 100644 --- a/web_src/js/components/RepoActionView.test.js +++ b/web_src/js/components/RepoActionView.test.js @@ -65,6 +65,7 @@ const defaultTestProps = { locale: testLocale, workflowName: 'workflow name', workflowURL: 'https://example.com/example-org/example-repo/actions?workflow=test.yml', + workflowSourceURL: 'https://example.com/example-org/example-repo/src/commit/023babec384/.forgejo/workflows/test.yml', }; test('load multiple steps on a finished action', async () => { diff --git a/web_src/js/components/RepoActionView.vue b/web_src/js/components/RepoActionView.vue index 9e9fe81ab8..3b44cee907 100644 --- a/web_src/js/components/RepoActionView.vue +++ b/web_src/js/components/RepoActionView.vue @@ -49,6 +49,10 @@ export default { type: String, required: true, }, + workflowSourceURL: { + type: String, + required: true, + }, locale: { type: Object, required: true, @@ -96,6 +100,7 @@ export default { localeCommit: '', localePushedBy: '', localeWorkflow: '', + localeAllRuns: '', shortSHA: '', link: '', pusher: { @@ -488,7 +493,7 @@ export default {
diff --git a/web_src/js/features/repo-action-view.ts b/web_src/js/features/repo-action-view.ts index a85ec4e01a..946927bf06 100644 --- a/web_src/js/features/repo-action-view.ts +++ b/web_src/js/features/repo-action-view.ts @@ -24,6 +24,7 @@ export async function initRepositoryActionView() { actionsURL: el.getAttribute('data-actions-url'), workflowName: el.getAttribute('data-workflow-name'), workflowURL: el.getAttribute('data-workflow-url'), + workflowSourceURL: el.getAttribute('data-workflow-source-url'), locale: { approve: el.getAttribute('data-locale-approve'), cancel: el.getAttribute('data-locale-cancel'),