Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incomplete Actions status aggregations #32859

Merged
merged 4 commits into from
Dec 16, 2024

Conversation

wxiaoguang
Copy link
Contributor

fix #32857

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 16, 2024
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/frontend labels Dec 16, 2024
@wxiaoguang wxiaoguang force-pushed the fix-actions-status branch 3 times, most recently from d0e65df to de82336 Compare December 16, 2024 01:39
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 16, 2024
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Dec 16, 2024
@wxiaoguang wxiaoguang force-pushed the fix-actions-status branch 2 times, most recently from 4156015 to 28a0e75 Compare December 16, 2024 02:17
@wxiaoguang wxiaoguang merged commit d28a484 into go-gitea:main Dec 16, 2024
26 checks passed
@GiteaBot GiteaBot added this to the 1.24.0 milestone Dec 16, 2024
@wxiaoguang wxiaoguang deleted the fix-actions-status branch December 16, 2024 03:18
@wxiaoguang wxiaoguang modified the milestones: 1.24.0, 1.23.0 Dec 16, 2024
@TheFox0x7
Copy link
Contributor

@wxiaoguang why bundle skip with success? Aren't they two different states when combined?
A workflow where all jobs where skipped is aggregated to skip and when one job had a different status it's marked with that "stronger" status.
Sorry for being late on this, I thought there will be some kind of discussion before I'd start porting my PR but you beat me to it.

@wxiaoguang
Copy link
Contributor Author

wxiaoguang commented Dec 16, 2024

Sorry for being late on this, I thought there will be some kind of discussion before I'd start porting my PR but you beat me to it.

Sorry that I didn't know you have a PR to port 🤣 you can tell that in the issue then I won't do it next time.

why bundle skip with success? Aren't they two different states when combined?
A workflow where all jobs where skipped is aggregated to skip and when one job had a different status it's marked with that "stronger" status.

The reason is that "skipped" shouldn't affect "success", just like GitHub:

image

Update: "all jobs where skipped is aggregated to skip": I think it is right to treat it as "success" since nothing need to do (all skipped), so "success"? Does it make sense?

@wxiaoguang
Copy link
Contributor Author

Hmm, I see your demo https://github.com/TheFox0x7/repro/actions/workflows/skip.yaml

"skipped-only" is aggregated as "skipped".

So maybe we should follow it (add a allSkipped check and return early if allSkipped).

ps: I am not sure whether it would affect other logics, eg: if "all skipped", should that PR be considered as "mergeable"?

image

@TheFox0x7
Copy link
Contributor

Sorry that I didn't know you have a PR to port 🤣 you can tell that in the issue then I won't do it next time.

No worries, I should've mentioned that. I sort of assumed someone would click the closed (but not merged) PR in the downstream issue which I'll admit it's hardly obvious so that's fully on me.

I can check how the skipped status works here but I'll need a bit of time to do it. I'll try and demonstrate the waiting and blocked states as well (I think i manged to do it earlier but no promises on that).
Guessing only - I'd treat skip as "success" (or rather not a fail) for any operations.


written before your new comment
I do see your point, but on the other hand it's also not a success since it didn't run at all. Having all jobs skipped should be (IMO) displayed as such but not block anything (it's didn't fail after all).
To illustrate my point and looking only at completed jobs:

  • statuses are either Skipped or Success - they should be displayed accordingly but for any operations treated as if everything passed.
  • statuses have a cancel or failure in the mix, so they should be displayed as overall result

Here's a test written for my original PR (with one test case added for pure skips) ```go package actions

import (
"math/rand/v2"
"testing"

"github.com/stretchr/testify/assert"

)

func TestJobStatusAggregation(t *testing.T) {
testCases := []struct {
desc string
runStatuses []Status
expectedStatus Status
}{
{
desc: "All jobs lower than skipped - aggregate skip",
runStatuses: []Status{StatusUnknown, StatusSkipped},
expectedStatus: StatusSkipped,
},
{
desc: "All jobs skipped - aggregate skip",
runStatuses: []Status{StatusSkipped},
expectedStatus: StatusSkipped,
},
{
desc: "Job success, no fails - aggregate success",
runStatuses: []Status{StatusSuccess, StatusSkipped, StatusUnknown},
expectedStatus: StatusSuccess,
},
{
desc: "Any job failure - aggregate failure",
runStatuses: []Status{StatusSuccess, StatusFailure, StatusSkipped, StatusUnknown},
expectedStatus: StatusFailure,
},
{
desc: "Any job cancelled - aggregate cancelled",
runStatuses: []Status{StatusSuccess, StatusFailure, StatusCancelled, StatusSkipped, StatusUnknown},
expectedStatus: StatusCancelled,
},
{
desc: "Any job running - aggregate running",
runStatuses: []Status{StatusSuccess, StatusUnknown, StatusFailure, StatusCancelled, StatusSkipped, StatusWaiting, StatusRunning},
expectedStatus: StatusRunning,
},
{
desc: "No jobs running, jobs waiting - aggregate waiting",
runStatuses: []Status{StatusSuccess, StatusFailure, StatusCancelled, StatusUnknown, StatusSkipped, StatusWaiting},
expectedStatus: StatusWaiting,
},
{
desc: "jobs blocked, jobs waiting - aggregate waiting",
runStatuses: []Status{StatusSuccess, StatusFailure, StatusCancelled, StatusSkipped, StatusWaiting, StatusBlocked},
expectedStatus: StatusWaiting,
},
{
desc: "jobs blocked, jobs running and waiting - aggregate running",
runStatuses: []Status{StatusSuccess, StatusFailure, StatusCancelled, StatusSkipped, StatusRunning, StatusWaiting, StatusBlocked},
expectedStatus: StatusRunning,
},
{
desc: "jobs blocked, finished or unknown - aggregate blocked",
runStatuses: []Status{StatusBlocked, StatusSuccess, StatusFailure, StatusCancelled, StatusSkipped},
expectedStatus: StatusBlocked,
},
{
desc: "job status unknown - aggregate unknown",
runStatuses: []Status{StatusUnknown},
expectedStatus: StatusUnknown,
},
}
for _, tC := range testCases {
mockedJobs := []*ActionRunJob{}
for _, v := range tC.runStatuses {
mockedJobs = append(mockedJobs, &ActionRunJob{Status: v})
}
// Safe guard function against order dependency
rand.Shuffle(len(mockedJobs), func(i, j int) {
mockedJobs[i], mockedJobs[j] = mockedJobs[j], mockedJobs[i]
})

	t.Run(tC.desc, func(t *testing.T) {
		status := AggregateJobStatus(mockedJobs)
		assert.Equal(t, tC.expectedStatus, status, "Expected %s, got %s", tC.expectedStatus.String(), status.String())
	})
}

}

</details>

@wxiaoguang
Copy link
Contributor Author

I think you are right, I didn't carefully study GitHub's behavior and only wrote the tests by my understanding.

I made a following up PR: Improve Actions status aggregations #32860 , does it look good to you? I think it is the same as your GitHub demo now.

@go-gitea go-gitea locked as resolved and limited conversation to collaborators Mar 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/frontend modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect job status agreggations
5 participants