mirror of
https://codeberg.org/forgejo/forgejo
synced 2025-09-17 03:02:55 +02:00
Adds a new dropdown to the job logs, visible only when a job has been retried at least once:  When an older run attempt from the dropdown is selected, displays the older run's logs:  Context on implementation & design decisions: - It is important that when a URL from an Action's log is shared, the person on the other side sees the exact same logs that were being viewed. For this reason, all log views are automatically redirected to a fully-qualified URL (including the *run*, *job*, and *attempt*), so that when they are shared there is a guarantee of stability in the viewed logs. - Individual jobs can be rerun any number of times independent of other jobs in the same workflow. This means there isn't a "set" of related jobs that were executed at the same time, and this led me to remove the display of current status of jobs on the left-hand side of the view. There isn't a logical set of job statuses to display here. Fixes #1043. Based upon @gmem's original work in #1416. ## 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. - [ ] 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 - [ ] I do not want this change to show in the release notes. - [x] 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/<pull request number>.md` to be be used for the release notes instead of the title. <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - User Interface features - [PR](https://codeberg.org/forgejo/forgejo/pulls/9017): <!--number 9017 --><!--line 0 --><!--description YWJpbGl0eSB0byB2aWV3IHByZXZpb3VzIGxvZ3MgZm9yIEFjdGlvbnMgcnVucyB0aGF0IGhhdmUgYmVlbiByZXRyaWVk-->ability to view previous logs for Actions runs that have been retried<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9017 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
153 lines
5.4 KiB
Go
153 lines
5.4 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
|
|
actions_model "forgejo.org/models/actions"
|
|
unit_model "forgejo.org/models/unit"
|
|
"forgejo.org/models/unittest"
|
|
user_model "forgejo.org/models/user"
|
|
files_service "forgejo.org/services/repository/files"
|
|
"forgejo.org/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func GetWorkflowRunRedirectURI(t *testing.T, repoURL, workflow string) string {
|
|
t.Helper()
|
|
|
|
req := NewRequest(t, "GET", fmt.Sprintf("%s/actions/workflows/%s/runs/latest", repoURL, workflow))
|
|
resp := MakeRequest(t, req, http.StatusTemporaryRedirect)
|
|
|
|
return resp.Header().Get("Location")
|
|
}
|
|
|
|
func TestActionsWebRouteLatestWorkflowRun(t *testing.T) {
|
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
|
|
// create the repo
|
|
repo, _, f := tests.CreateDeclarativeRepo(t, user2, "actionsTestRepo",
|
|
[]unit_model.Type{unit_model.TypeActions}, nil,
|
|
[]*files_service.ChangeRepoFile{
|
|
{
|
|
Operation: "create",
|
|
TreePath: ".gitea/workflows/workflow-1.yml",
|
|
ContentReader: strings.NewReader("name: workflow-1\non:\n push:\njobs:\n job-1:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
|
|
},
|
|
{
|
|
Operation: "create",
|
|
TreePath: ".gitea/workflows/workflow-2.yml",
|
|
ContentReader: strings.NewReader("name: workflow-2\non:\n push:\njobs:\n job-2:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
|
|
},
|
|
},
|
|
)
|
|
defer f()
|
|
|
|
repoURL := repo.HTMLURL()
|
|
|
|
t.Run("valid workflows", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
|
|
// two runs have been created
|
|
assert.Equal(t, 2, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
|
|
|
|
// Get the redirect URIs for both workflows
|
|
workflowOneURI := GetWorkflowRunRedirectURI(t, repoURL, "workflow-1.yml")
|
|
workflowTwoURI := GetWorkflowRunRedirectURI(t, repoURL, "workflow-2.yml")
|
|
|
|
// Verify that the two are different.
|
|
assert.NotEqual(t, workflowOneURI, workflowTwoURI)
|
|
|
|
// Verify that each points to the correct workflow.
|
|
workflowOne := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID, Index: 1})
|
|
err := workflowOne.LoadAttributes(t.Context())
|
|
require.NoError(t, err)
|
|
assert.Equal(t, workflowOneURI, workflowOne.HTMLURL())
|
|
|
|
workflowTwo := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID, Index: 2})
|
|
err = workflowTwo.LoadAttributes(t.Context())
|
|
require.NoError(t, err)
|
|
assert.Equal(t, workflowTwoURI, workflowTwo.HTMLURL())
|
|
})
|
|
|
|
t.Run("check if workflow page shows file name", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
|
|
// Get the redirect URI
|
|
workflow := "workflow-1.yml"
|
|
workflowOneURI := GetWorkflowRunRedirectURI(t, repoURL, workflow)
|
|
|
|
// Fetch the page that shows information about the run initiated by "workflow-1.yml".
|
|
// routers/web/repo/actions/view.go: data-workflow-url is constructed using data-workflow-name.
|
|
req := NewRequest(t, "GET", workflowOneURI)
|
|
intermediateRedirect := MakeRequest(t, req, http.StatusTemporaryRedirect)
|
|
|
|
finalURL := intermediateRedirect.Result().Header.Get("Location")
|
|
req = NewRequest(t, "GET", finalURL)
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
// Verify that URL of the workflow is shown correctly.
|
|
expectedURL := fmt.Sprintf("/user2/actionsTestRepo/actions?workflow=%s", workflow)
|
|
htmlDoc.AssertElement(t, fmt.Sprintf("#repo-action-view[data-workflow-url=\"%s\"]", expectedURL), true)
|
|
})
|
|
|
|
t.Run("existing workflow, non-existent branch", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
|
|
req := NewRequest(t, "GET", fmt.Sprintf("%s/actions/workflows/workflow-1.yml/runs/latest?branch=foobar", repoURL))
|
|
MakeRequest(t, req, http.StatusNotFound)
|
|
})
|
|
|
|
t.Run("non-existing workflow", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
|
|
req := NewRequest(t, "GET", fmt.Sprintf("%s/actions/workflows/workflow-3.yml/runs/latest", repoURL))
|
|
MakeRequest(t, req, http.StatusNotFound)
|
|
})
|
|
})
|
|
}
|
|
|
|
func TestActionsWebRouteLatestRun(t *testing.T) {
|
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
|
|
// create the repo
|
|
repo, _, f := tests.CreateDeclarativeRepo(t, user2, "",
|
|
[]unit_model.Type{unit_model.TypeActions}, nil,
|
|
[]*files_service.ChangeRepoFile{
|
|
{
|
|
Operation: "create",
|
|
TreePath: ".gitea/workflows/pr.yml",
|
|
ContentReader: strings.NewReader("name: test\non:\n push:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
|
|
},
|
|
},
|
|
)
|
|
defer f()
|
|
|
|
// a run has been created
|
|
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
|
|
|
|
// Hit the `/actions/runs/latest` route
|
|
req := NewRequest(t, "GET", fmt.Sprintf("%s/actions/runs/latest", repo.HTMLURL()))
|
|
resp := MakeRequest(t, req, http.StatusTemporaryRedirect)
|
|
|
|
// Verify that it redirects to the run we just created
|
|
workflow := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRun{RepoID: repo.ID})
|
|
err := workflow.LoadAttributes(t.Context())
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, workflow.HTMLURL(), resp.Header().Get("Location"))
|
|
})
|
|
}
|