@@ -7,12 +7,14 @@ import (
7
7
"context"
8
8
"errors"
9
9
"fmt"
10
+ "strings"
10
11
11
12
actions_model "code.gitea.io/gitea/models/actions"
12
13
"code.gitea.io/gitea/models/db"
13
14
"code.gitea.io/gitea/modules/graceful"
14
15
"code.gitea.io/gitea/modules/queue"
15
16
17
+ "github.com/nektos/act/pkg/jobparser"
16
18
"xorm.io/builder"
17
19
)
18
20
@@ -76,12 +78,15 @@ func checkJobsOfRun(ctx context.Context, runID int64) error {
76
78
type jobStatusResolver struct {
77
79
statuses map [int64 ]actions_model.Status
78
80
needs map [int64 ][]int64
81
+ jobMap map [int64 ]* actions_model.ActionRunJob
79
82
}
80
83
81
84
func newJobStatusResolver (jobs actions_model.ActionJobList ) * jobStatusResolver {
82
85
idToJobs := make (map [string ][]* actions_model.ActionRunJob , len (jobs ))
86
+ jobMap := make (map [int64 ]* actions_model.ActionRunJob )
83
87
for _ , job := range jobs {
84
88
idToJobs [job .JobID ] = append (idToJobs [job .JobID ], job )
89
+ jobMap [job .ID ] = job
85
90
}
86
91
87
92
statuses := make (map [int64 ]actions_model.Status , len (jobs ))
@@ -97,6 +102,7 @@ func newJobStatusResolver(jobs actions_model.ActionJobList) *jobStatusResolver {
97
102
return & jobStatusResolver {
98
103
statuses : statuses ,
99
104
needs : needs ,
105
+ jobMap : jobMap ,
100
106
}
101
107
}
102
108
@@ -135,7 +141,20 @@ func (r *jobStatusResolver) resolve() map[int64]actions_model.Status {
135
141
if allSucceed {
136
142
ret [id ] = actions_model .StatusWaiting
137
143
} 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
+ }
139
158
}
140
159
}
141
160
}
0 commit comments