@@ -66,6 +66,17 @@ ext.testArtifact = { p, String name = "test" ->
66
66
};
67
67
}
68
68
69
+ class StepExpansion {
70
+ String templatePath
71
+ List<Version > versions
72
+ String variable
73
+ }
74
+
75
+ class ListExpansion {
76
+ List<Version > versions
77
+ String variable
78
+ }
79
+
69
80
tasks. register(" updateCIBwcVersions" ) {
70
81
def writeVersions = { File file , List<Version > versions ->
71
82
file. text = " "
@@ -75,42 +86,60 @@ tasks.register("updateCIBwcVersions") {
75
86
}
76
87
}
77
88
78
- def writeBuildkiteList = { String outputFilePath , String pipelineTemplatePath , List<Version > versions ->
89
+ def writeBuildkitePipeline = { String outputFilePath , String pipelineTemplatePath , List<ListExpansion > listExpansions , List< StepExpansion > stepExpansions = [] ->
79
90
def outputFile = file(outputFilePath)
80
91
def pipelineTemplate = file(pipelineTemplatePath)
81
92
82
- def listString = " [" + versions. collect { " \" ${ it} \" " }. join(" , " ) + " ]"
83
- outputFile. text = " # This file is auto-generated. See ${ pipelineTemplatePath} \n " + pipelineTemplate. text. replaceAll(' \\ $BWC_LIST' , listString)
84
- }
93
+ def pipeline = pipelineTemplate. text
85
94
86
- def writeBuildkiteSteps = { String outputFilePath , String pipelineTemplatePath , String stepTemplatePath , List< Version > versions ->
87
- def outputFile = file(outputFilePath)
88
- def pipelineTemplate = file(pipelineTemplatePath )
89
- def stepTemplate = file(stepTemplatePath)
95
+ listExpansions . each { expansion ->
96
+ def listString = " [ " + expansion . versions . collect { " \" ${ it } \" " } . join( " , " ) + " ] "
97
+ pipeline = pipeline . replaceAll( ' \\ $ ' + expansion . variable, listString )
98
+ }
90
99
91
- def steps = " "
92
- versions. each {
93
- steps + = " \n " + stepTemplate. text. replaceAll(' \\ $BWC_VERSION' , it. toString())
100
+ stepExpansions. each { expansion ->
101
+ def steps = " "
102
+ expansion. versions. each {
103
+ steps + = " \n " + file(expansion. templatePath). text. replaceAll(' \\ $BWC_VERSION' , it. toString())
104
+ }
105
+ pipeline = pipeline. replaceAll(' *\\ $' + expansion. variable, steps)
94
106
}
95
107
96
- outputFile. text = " # This file is auto-generated. See ${ pipelineTemplatePath} \n " + pipelineTemplate. text. replaceAll(' *\\ $BWC_STEPS' , steps)
108
+ outputFile. text = " # This file is auto-generated. See ${ pipelineTemplatePath} \n " + pipeline
109
+ }
110
+
111
+ // Writes a Buildkite pipelime from a template, and replaces $BWC_LIST with an array of versions
112
+ // Useful for writing a list of versions in a matrix configuration
113
+ def expandBwcList = { String outputFilePath , String pipelineTemplatePath , List<Version > versions ->
114
+ writeBuildkitePipeline(outputFilePath, pipelineTemplatePath, [new ListExpansion (versions : versions, variable : " BWC_LIST" )])
115
+ }
116
+
117
+ // Writes a Buildkite pipeline from a template, and replaces $BWC_STEPS with a list of steps, one for each version
118
+ // Useful when you need to configure more versions than are allowed in a matrix configuration
119
+ def expandBwcSteps = { String outputFilePath , String pipelineTemplatePath , String stepTemplatePath , List<Version > versions ->
120
+ writeBuildkitePipeline(outputFilePath, pipelineTemplatePath, [], [new StepExpansion (templatePath : stepTemplatePath, versions : versions, variable : " BWC_STEPS" )])
97
121
}
98
122
99
123
doLast {
100
124
writeVersions(file(" .ci/bwcVersions" ), BuildParams . bwcVersions. allIndexCompatible)
101
125
writeVersions(file(" .ci/snapshotBwcVersions" ), BuildParams . bwcVersions. unreleasedIndexCompatible)
102
- writeBuildkiteList (
126
+ expandBwcList (
103
127
" .buildkite/pipelines/intake.yml" ,
104
128
" .buildkite/pipelines/intake.template.yml" ,
105
129
BuildParams . bwcVersions. unreleasedIndexCompatible
106
130
)
107
- writeBuildkiteSteps (
131
+ writeBuildkitePipeline (
108
132
" .buildkite/pipelines/periodic.yml" ,
109
133
" .buildkite/pipelines/periodic.template.yml" ,
110
- " .buildkite/pipelines/periodic.bwc.template.yml" ,
111
- BuildParams . bwcVersions. allIndexCompatible
134
+ [
135
+ new ListExpansion (versions : BuildParams . bwcVersions. unreleasedIndexCompatible, variable : " BWC_LIST" ),
136
+ ],
137
+ [
138
+ new StepExpansion (templatePath : " .buildkite/pipelines/periodic.bwc.template.yml" , versions : BuildParams . bwcVersions. allIndexCompatible, variable : " BWC_STEPS" ),
139
+ ]
112
140
)
113
- writeBuildkiteSteps(
141
+
142
+ expandBwcSteps(
114
143
" .buildkite/pipelines/periodic-packaging.yml" ,
115
144
" .buildkite/pipelines/periodic-packaging.template.yml" ,
116
145
" .buildkite/pipelines/periodic-packaging.bwc.template.yml" ,
0 commit comments