@@ -7,12 +7,14 @@ import (
77 "context"
88 "errors"
99 "fmt"
10+ "strings"
1011
1112 actions_model "code.gitea.io/gitea/models/actions"
1213 "code.gitea.io/gitea/models/db"
1314 "code.gitea.io/gitea/modules/graceful"
1415 "code.gitea.io/gitea/modules/queue"
1516
17+ "github.com/nektos/act/pkg/jobparser"
1618 "xorm.io/builder"
1719)
1820
@@ -76,12 +78,15 @@ func checkJobsOfRun(ctx context.Context, runID int64) error {
7678type jobStatusResolver struct {
7779 statuses map [int64 ]actions_model.Status
7880 needs map [int64 ][]int64
81+ jobMap map [int64 ]* actions_model.ActionRunJob
7982}
8083
8184func newJobStatusResolver (jobs actions_model.ActionJobList ) * jobStatusResolver {
8285 idToJobs := make (map [string ][]* actions_model.ActionRunJob , len (jobs ))
86+ jobMap := make (map [int64 ]* actions_model.ActionRunJob )
8387 for _ , job := range jobs {
8488 idToJobs [job .JobID ] = append (idToJobs [job .JobID ], job )
89+ jobMap [job .ID ] = job
8590 }
8691
8792 statuses := make (map [int64 ]actions_model.Status , len (jobs ))
@@ -97,6 +102,7 @@ func newJobStatusResolver(jobs actions_model.ActionJobList) *jobStatusResolver {
97102 return & jobStatusResolver {
98103 statuses : statuses ,
99104 needs : needs ,
105+ jobMap : jobMap ,
100106 }
101107}
102108
@@ -135,7 +141,20 @@ func (r *jobStatusResolver) resolve() map[int64]actions_model.Status {
135141 if allSucceed {
136142 ret [id ] = actions_model .StatusWaiting
137143 } else {
138- ret [id ] = actions_model .StatusSkipped
144+ // If a job's "if" condition is "always()", the job should always run even if some of its dependencies did not succeed.
145+ // See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idneeds
146+ always := false
147+ if wfJobs , _ := jobparser .Parse (r .jobMap [id ].WorkflowPayload ); len (wfJobs ) == 1 {
148+ _ , wfJob := wfJobs [0 ].Job ()
149+ expr := strings .TrimSpace (strings .TrimSuffix (strings .TrimPrefix (wfJob .If .Value , "${{" ), "}}" ))
150+ always = expr == "always()"
151+ }
152+
153+ if always {
154+ ret [id ] = actions_model .StatusWaiting
155+ } else {
156+ ret [id ] = actions_model .StatusSkipped
157+ }
139158 }
140159 }
141160 }
0 commit comments