mirror of
https://codeberg.org/forgejo/forgejo
synced 2025-09-17 01:12:52 +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>
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"forgejo.org/models/db"
|
|
"forgejo.org/models/unittest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestActionRunJob_ItRunsOn(t *testing.T) {
|
|
actionJob := ActionRunJob{RunsOn: []string{"ubuntu"}}
|
|
agentLabels := []string{"ubuntu", "node-20"}
|
|
|
|
assert.True(t, actionJob.ItRunsOn(agentLabels))
|
|
assert.False(t, actionJob.ItRunsOn([]string{}))
|
|
|
|
actionJob.RunsOn = append(actionJob.RunsOn, "node-20")
|
|
|
|
assert.True(t, actionJob.ItRunsOn(agentLabels))
|
|
|
|
agentLabels = []string{"ubuntu"}
|
|
|
|
assert.False(t, actionJob.ItRunsOn(agentLabels))
|
|
|
|
actionJob.RunsOn = []string{}
|
|
|
|
assert.False(t, actionJob.ItRunsOn(agentLabels))
|
|
}
|
|
|
|
func TestActionRunJob_HTMLURL(t *testing.T) {
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
tests := []struct {
|
|
id int64
|
|
expected string
|
|
}{
|
|
{
|
|
id: 192,
|
|
expected: "https://try.gitea.io/user5/repo4/actions/runs/187/jobs/0/attempt/1",
|
|
},
|
|
{
|
|
id: 393,
|
|
expected: "https://try.gitea.io/user2/repo1/actions/runs/187/jobs/1/attempt/1",
|
|
},
|
|
{
|
|
id: 394,
|
|
expected: "https://try.gitea.io/user2/repo1/actions/runs/187/jobs/2/attempt/2",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(fmt.Sprintf("id=%d", tt.id), func(t *testing.T) {
|
|
var job ActionRunJob
|
|
has, err := db.GetEngine(t.Context()).Where("id=?", tt.id).Get(&job)
|
|
require.NoError(t, err)
|
|
require.True(t, has, "load ActionRunJob from fixture")
|
|
|
|
err = job.LoadAttributes(t.Context())
|
|
require.NoError(t, err)
|
|
|
|
url, err := job.HTMLURL(t.Context())
|
|
require.NoError(t, err)
|
|
assert.Equal(t, tt.expected, url)
|
|
})
|
|
}
|
|
}
|