@@ -126,7 +126,6 @@ jobs:
126
126
token := getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeWriteRepository , auth_model .AccessTokenScopeWriteUser )
127
127
128
128
apiRepo := createActionsTestRepo (t , token , "actions-jobs-with-needs" , false )
129
-
130
129
runner := newMockRunner ()
131
130
runner .registerAsRepoRunner (t , user2 .Name , apiRepo .Name , "mock-runner" , []string {"ubuntu-latest" })
132
131
@@ -163,6 +162,113 @@ jobs:
163
162
})
164
163
}
165
164
165
+ func TestJobNeedsMatrix (t * testing.T ) {
166
+ testCases := []struct {
167
+ treePath string
168
+ fileContent string
169
+ execPolicies map [string ]* taskExecPolicy
170
+ expectedOutputs map [string ]map [string ]string // jobID(string) => output(map[string]string)
171
+ }{
172
+ {
173
+ treePath : ".gitea/workflows/jobs-outputs-with-matrix.yml" ,
174
+ fileContent : `name: jobs-outputs-with-matrix
175
+ on:
176
+ push:
177
+ paths:
178
+ - '.gitea/workflows/jobs-outputs-with-matrix.yml'
179
+ jobs:
180
+ job1:
181
+ runs-on: ubuntu-latest
182
+ outputs:
183
+ output_1: ${{ steps.gen_output.outputs.output_1 }}
184
+ output_2: ${{ steps.gen_output.outputs.output_2 }}
185
+ output_3: ${{ steps.gen_output.outputs.output_3 }}
186
+ strategy:
187
+ matrix:
188
+ version: [1, 2, 3]
189
+ steps:
190
+ - name: Generate output
191
+ id: gen_output
192
+ run: |
193
+ version="${{ matrix.version }}"
194
+ echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
195
+ job2:
196
+ runs-on: ubuntu-latest
197
+ needs: [job1]
198
+ steps:
199
+ - run: echo '${{ toJSON(needs.job1.outputs) }}'
200
+ ` ,
201
+ execPolicies : map [string ]* taskExecPolicy {
202
+ "job1 (1)" : {
203
+ result : runnerv1 .Result_RESULT_SUCCESS ,
204
+ outputs : map [string ]string {
205
+ "output_1" : "1" ,
206
+ "output_2" : "" ,
207
+ "output_3" : "" ,
208
+ },
209
+ },
210
+ "job1 (2)" : {
211
+ result : runnerv1 .Result_RESULT_SUCCESS ,
212
+ outputs : map [string ]string {
213
+ "output_1" : "" ,
214
+ "output_2" : "2" ,
215
+ "output_3" : "" ,
216
+ },
217
+ },
218
+ "job1 (3)" : {
219
+ result : runnerv1 .Result_RESULT_SUCCESS ,
220
+ outputs : map [string ]string {
221
+ "output_1" : "" ,
222
+ "output_2" : "" ,
223
+ "output_3" : "3" ,
224
+ },
225
+ },
226
+ },
227
+ expectedOutputs : map [string ]map [string ]string {
228
+ "job1" : {
229
+ "output_1" : "1" ,
230
+ "output_2" : "2" ,
231
+ "output_3" : "3" ,
232
+ },
233
+ },
234
+ },
235
+ }
236
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
237
+ user2 := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 })
238
+ session := loginUser (t , user2 .Name )
239
+ token := getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeWriteRepository , auth_model .AccessTokenScopeWriteUser )
240
+
241
+ apiRepo := createActionsTestRepo (t , token , "actions-jobs-outputs-with-matrix" , false )
242
+ runner := newMockRunner ()
243
+ runner .registerAsRepoRunner (t , user2 .Name , apiRepo .Name , "mock-runner" , []string {"ubuntu-latest" })
244
+
245
+ for _ , tc := range testCases {
246
+ t .Run (fmt .Sprintf ("test %s" , tc .treePath ), func (t * testing.T ) {
247
+ opts := getWorkflowCreateFileOptions (user2 , apiRepo .DefaultBranch , fmt .Sprintf ("create %s" , tc .treePath ), tc .fileContent )
248
+ createWorkflowFile (t , token , user2 .Name , apiRepo .Name , tc .treePath , opts )
249
+
250
+ for i := 0 ; i < len (tc .execPolicies ); i ++ {
251
+ task := runner .fetchTask (t )
252
+ jobName := getTaskJobNameByTaskID (t , token , user2 .Name , apiRepo .Name , task .Id )
253
+ policy := tc .execPolicies [jobName ]
254
+ assert .NotNil (t , policy )
255
+ runner .execTask (t , task , policy )
256
+ }
257
+
258
+ job2Task := runner .fetchTask (t )
259
+ needs := job2Task .Needs
260
+ assert .Len (t , needs , len (tc .expectedOutputs ))
261
+ for jobID , outputs := range tc .expectedOutputs {
262
+ assert .Len (t , needs [jobID ].Outputs , len (outputs ))
263
+ for outputKey , outputValue := range outputs {
264
+ assert .Equal (t , outputValue , needs [jobID ].Outputs [outputKey ])
265
+ }
266
+ }
267
+ })
268
+ }
269
+ })
270
+ }
271
+
166
272
func createActionsTestRepo (t * testing.T , authToken , repoName string , isPrivate bool ) * api.Repository {
167
273
req := NewRequestWithJSON (t , "POST" , "/api/v1/user/repos" , & api.CreateRepoOption {
168
274
Name : repoName ,
0 commit comments