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 {