Skip to content

Commit cc5e970

Browse files
feat: PIPE-5084 Update job references to support serial groups (#325)
1 parent e2aae9e commit cc5e970

File tree

6 files changed

+91
-7
lines changed

6 files changed

+91
-7
lines changed

pkg/ast/workflow.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ type JobRef struct {
2525

2626
// StepName is the name of the job in the workflow,
2727
// not the job that will be executed
28-
StepName string
29-
StepNameRange protocol.Range
30-
Requires []Require
31-
Context []TextAndRange
32-
Type string
33-
TypeRange protocol.Range
34-
Parameters map[string]ParameterValue
28+
StepName string
29+
StepNameRange protocol.Range
30+
Requires []Require
31+
Context []TextAndRange
32+
Type string
33+
TypeRange protocol.Range
34+
Parameters map[string]ParameterValue
35+
SerialGroup string
36+
SerialGroupRange protocol.Range
3537

3638
PreSteps []Step
3739
PreStepsRange protocol.Range

pkg/parser/validate/workflow_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ workflows:
6464
`,
6565
Diagnostics: []protocol.Diagnostic{},
6666
},
67+
{
68+
Name: "Serial groups",
69+
YamlContent: `version: 2.1
70+
jobs:
71+
- deploy:
72+
type: no-op
73+
74+
workflows:
75+
someworkflow:
76+
jobs:
77+
- deploy:
78+
serial-group: deploy-group`,
79+
},
6780
}
6881

6982
CheckYamlErrors(t, testCases)

pkg/parser/workflows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ func (doc *YamlDocument) parseSingleJobReference(jobRefNode *sitter.Node) ast.Jo
212212
if alias != "" {
213213
res.StepName = alias
214214
}
215+
case "serial-group":
216+
res.SerialGroup = doc.GetNodeText(valueNode)
217+
res.SerialGroupRange = doc.NodeToRange(valueNode)
215218

216219
case "pre-steps":
217220
res.PreStepsRange = doc.NodeToRange(child)

pkg/parser/workflows_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ func TestYamlDocument_parseSingleJobReference(t *testing.T) {
4343
- test:
4444
requires:
4545
- setup: [success, canceled]`
46+
const jobRef7 = `
47+
- deploy:
48+
serial-group: deploy-group`
4649

4750
type fields struct {
4851
Content []byte
@@ -415,6 +418,59 @@ func TestYamlDocument_parseSingleJobReference(t *testing.T) {
415418
Parameters: make(map[string]ast.ParameterValue),
416419
},
417420
},
421+
{
422+
name: "Job reference with serial group",
423+
fields: fields{Content: []byte(jobRef7)},
424+
args: args{jobRefNode: getFirstChildOfType(GetRootNode([]byte(jobRef7)), "block_sequence_item")},
425+
want: ast.JobRef{
426+
JobName: "deploy",
427+
JobRefRange: protocol.Range{
428+
Start: protocol.Position{
429+
Line: 1,
430+
Character: 0,
431+
},
432+
End: protocol.Position{
433+
Line: 2,
434+
Character: 30,
435+
},
436+
},
437+
JobNameRange: protocol.Range{
438+
Start: protocol.Position{
439+
Line: 1,
440+
Character: 2,
441+
},
442+
End: protocol.Position{
443+
Line: 1,
444+
Character: 8,
445+
},
446+
},
447+
StepName: "deploy",
448+
StepNameRange: protocol.Range{
449+
Start: protocol.Position{
450+
Line: 1,
451+
Character: 2,
452+
},
453+
End: protocol.Position{
454+
Line: 1,
455+
Character: 8,
456+
},
457+
},
458+
Parameters: make(map[string]ast.ParameterValue),
459+
HasMatrix: false,
460+
MatrixParams: make(map[string][]ast.ParameterValue),
461+
SerialGroup: "deploy-group",
462+
SerialGroupRange: protocol.Range{
463+
Start: protocol.Position{
464+
Line: 2,
465+
Character: 18,
466+
},
467+
End: protocol.Position{
468+
Line: 2,
469+
Character: 30,
470+
},
471+
},
472+
},
473+
},
418474
}
419475
for _, tt := range tests {
420476
t.Run(tt.name, func(t *testing.T) {

pkg/services/testdata/noErrors.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ jobs:
8888
steps:
8989
- run: echo "Hello"
9090

91+
deploy:
92+
<<: *buildJob
93+
9194
workflows:
9295
test-build:
9396
jobs:
@@ -125,3 +128,6 @@ workflows:
125128
- jobWithAWS_OIDC
126129
- ccc/random-job
127130
- jobWithUnaccessibleOrb
131+
132+
- deploy:
133+
serial-group: << pipeline.project.slug >>/deploy-group

schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,10 @@
16761676
"type": "string"
16771677
}
16781678
}
1679+
},
1680+
"serial-group": {
1681+
"type": "string",
1682+
"minLength": 1
16791683
}
16801684
}
16811685
}

0 commit comments

Comments
 (0)