mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-28 11:14:54 -04:00
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 | |---------|---------| |  |  | 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:
parent
515b27707e
commit
45db3c98a3
11 changed files with 40 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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.",
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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"}}"
|
||||
|
|
|
|||
|
|
@ -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|$)/);
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 () => {
|
||||
|
|
|
|||
|
|
@ -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 {
|
|||
</div>
|
||||
<div class="action-summary">
|
||||
{{ 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 class="ui error message pre-execution-error" v-if="run.preExecutionError">
|
||||
<div class="header">
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
Loading…
Reference in a new issue