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.

<!--start release-notes-assistant-->

## Release notes
<!--URL:https://codeberg.org/forgejo/forgejo-->
- Features
  - [PR](https://codeberg.org/forgejo/forgejo/pulls/11216): <!--number 11216 --><!--line 0 --><!--description bGluayBDSSBqb2IgdG8gaXRzIGRlZmluaW5nIHdvcmtmbG93IGZpbGU=-->link CI job to its defining workflow file<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11216
Reviewed-by: Andreas Ahlenstorf <aahlenst@noreply.codeberg.org>
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Co-authored-by: Antonin Delpeuch <antonin@delpeuch.eu>
Co-committed-by: Antonin Delpeuch <antonin@delpeuch.eu>
This commit is contained in:
Antonin Delpeuch 2026-02-20 03:11:29 +01:00 committed by Mathieu Fenniak
parent 515b27707e
commit 45db3c98a3
11 changed files with 40 additions and 3 deletions

View file

@ -104,6 +104,14 @@ func (run *ActionRun) Link() string {
return fmt.Sprintf("%s/actions/runs/%d", run.Repo.Link(), run.Index) 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 // RefLink return the url of run's ref
func (run *ActionRun) RefLink() string { func (run *ActionRun) RefLink() string {
refName := git.RefName(run.Ref) refName := git.RefName(run.Ref)

View file

@ -45,6 +45,14 @@ func TestSetDefaultConcurrencyGroup(t *testing.T) {
assert.Equal(t, "refs/heads/main_testing_pull_request__auto", run.ConcurrencyGroup) 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) { func TestRepoNumOpenActions(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase()) require.NoError(t, unittest.PrepareTestDatabase())
err := cache.Init() err := cache.Init()

View file

@ -462,6 +462,7 @@
"actions.runs.status_no_select": "All status", "actions.runs.status_no_select": "All status",
"actions.runs.no_results": "No results matched.", "actions.runs.no_results": "No results matched.",
"actions.runs.no_workflows": "There are no workflows yet.", "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.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.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.", "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.",

View file

@ -82,6 +82,7 @@ func View(ctx *app_context.Context) {
ctx.Data["AttemptNumber"] = attemptNumber ctx.Data["AttemptNumber"] = attemptNumber
ctx.Data["WorkflowName"] = workflowName ctx.Data["WorkflowName"] = workflowName
ctx.Data["WorkflowURL"] = ctx.Repo.RepoLink + "/actions?workflow=" + 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) viewResponse := getViewResponse(ctx, &ViewRequest{}, runIndex, jobIndex, attemptNumber)
if ctx.Written() { if ctx.Written() {
@ -205,6 +206,7 @@ type ViewCommit struct {
LocaleCommit string `json:"localeCommit"` LocaleCommit string `json:"localeCommit"`
LocalePushedBy string `json:"localePushedBy"` LocalePushedBy string `json:"localePushedBy"`
LocaleWorkflow string `json:"localeWorkflow"` LocaleWorkflow string `json:"localeWorkflow"`
LocaleAllRuns string `json:"localeAllRuns"`
ShortSha string `json:"shortSHA"` ShortSha string `json:"shortSHA"`
Link string `json:"link"` Link string `json:"link"`
Pusher ViewUser `json:"pusher"` 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"), LocaleCommit: ctx.Locale.TrString("actions.runs.commit"),
LocalePushedBy: ctx.Locale.TrString("actions.runs.pushed_by"), LocalePushedBy: ctx.Locale.TrString("actions.runs.pushed_by"),
LocaleWorkflow: ctx.Locale.TrString("actions.runs.workflow"), LocaleWorkflow: ctx.Locale.TrString("actions.runs.workflow"),
LocaleAllRuns: ctx.Locale.TrString("actions.runs.all_runs_link"),
ShortSha: base.ShortSha(run.CommitSHA), ShortSha: base.ShortSha(run.CommitSHA),
Link: fmt.Sprintf("%s/commit/%s", run.Repo.Link(), run.CommitSHA), Link: fmt.Sprintf("%s/commit/%s", run.Repo.Link(), run.CommitSHA),
Pusher: pusher, Pusher: pusher,

View file

@ -168,6 +168,7 @@ func baseExpectedViewResponse() *ViewResponse {
LocaleCommit: "actions.runs.commit", LocaleCommit: "actions.runs.commit",
LocalePushedBy: "actions.runs.pushed_by", LocalePushedBy: "actions.runs.pushed_by",
LocaleWorkflow: "actions.runs.workflow", LocaleWorkflow: "actions.runs.workflow",
LocaleAllRuns: "actions.runs.all_runs_link",
ShortSha: "c2d72f5484", ShortSha: "c2d72f5484",
Link: "/user5/repo4/commit/c2d72f548424103f01ee1dc02889c1e2bff816b0", Link: "/user5/repo4/commit/c2d72f548424103f01ee1dc02889c1e2bff816b0",
Pusher: ViewUser{ Pusher: ViewUser{

View file

@ -10,6 +10,7 @@
data-actions-url="{{.ActionsURL}}" data-actions-url="{{.ActionsURL}}"
data-workflow-name="{{.WorkflowName}}" data-workflow-name="{{.WorkflowName}}"
data-workflow-url="{{.WorkflowURL}}" data-workflow-url="{{.WorkflowURL}}"
data-workflow-source-url="{{.WorkflowSourceURL}}"
data-initial-post-response="{{.InitialData}}" data-initial-post-response="{{.InitialData}}"
data-initial-artifacts-response="{{.InitialArtifactsData}}" data-initial-artifacts-response="{{.InitialArtifactsData}}"
data-locale-approve="{{ctx.Locale.Tr "repo.pulls.poster_manage_approval"}}" data-locale-approve="{{ctx.Locale.Tr "repo.pulls.poster_manage_approval"}}"

View file

@ -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'})); 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) { async function completeDynamicRefresh(page: Page) {
// Ensure that the reloading indicator isn't active, indicating that dynamic refresh is done. // 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|$)/); await expect(page.locator('#reloading-indicator')).not.toHaveClass(/(^|\s)is-loading(\s|$)/);

View file

@ -153,7 +153,7 @@ func TestActionViewsView(t *testing.T) {
re = regexp.MustCompile(pattern) re = regexp.MustCompile(pattern)
actualClean = re.ReplaceAllString(actualClean, `"time_since_started_html":"_time_"`) 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") 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) re = regexp.MustCompile(pattern)
actualClean = re.ReplaceAllString(actualClean, `"time_since_started_html":"_time_"`) 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") htmlDoc.AssertAttrEqual(t, selector, "data-initial-artifacts-response", "{\"artifacts\":[]}\n")
} }

View file

@ -65,6 +65,7 @@ const defaultTestProps = {
locale: testLocale, locale: testLocale,
workflowName: 'workflow name', workflowName: 'workflow name',
workflowURL: 'https://example.com/example-org/example-repo/actions?workflow=test.yml', 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 () => { test('load multiple steps on a finished action', async () => {

View file

@ -49,6 +49,10 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
workflowSourceURL: {
type: String,
required: true,
},
locale: { locale: {
type: Object, type: Object,
required: true, required: true,
@ -96,6 +100,7 @@ export default {
localeCommit: '', localeCommit: '',
localePushedBy: '', localePushedBy: '',
localeWorkflow: '', localeWorkflow: '',
localeAllRuns: '',
shortSHA: '', shortSHA: '',
link: '', link: '',
pusher: { pusher: {
@ -488,7 +493,7 @@ export default {
</div> </div>
<div class="action-summary"> <div class="action-summary">
{{ run.commit.localeWorkflow }} {{ run.commit.localeWorkflow }}
<a class="muted" :href="workflowURL">{{ workflowName }}</a> <a class="muted" :href="workflowSourceURL">{{ workflowName }}</a> <span>(<a class="muted" :href="workflowURL">{{ run.commit.localeAllRuns }}</a>)</span>
</div> </div>
<div class="ui error message pre-execution-error" v-if="run.preExecutionError"> <div class="ui error message pre-execution-error" v-if="run.preExecutionError">
<div class="header"> <div class="header">

View file

@ -24,6 +24,7 @@ export async function initRepositoryActionView() {
actionsURL: el.getAttribute('data-actions-url'), actionsURL: el.getAttribute('data-actions-url'),
workflowName: el.getAttribute('data-workflow-name'), workflowName: el.getAttribute('data-workflow-name'),
workflowURL: el.getAttribute('data-workflow-url'), workflowURL: el.getAttribute('data-workflow-url'),
workflowSourceURL: el.getAttribute('data-workflow-source-url'),
locale: { locale: {
approve: el.getAttribute('data-locale-approve'), approve: el.getAttribute('data-locale-approve'),
cancel: el.getAttribute('data-locale-cancel'), cancel: el.getAttribute('data-locale-cancel'),