Skip to content

Commit 6f2d188

Browse files
authored
[ci] Refactor BWC templating in Buildkite pipelines to handle more scenarios (#106084) (#106098)
(cherry picked from commit 6f8280c)
1 parent 057843e commit 6f2d188

File tree

1 file changed

+46
-17
lines changed

1 file changed

+46
-17
lines changed

build.gradle

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ ext.testArtifact = { p, String name = "test" ->
6666
};
6767
}
6868

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+
6980
tasks.register("updateCIBwcVersions") {
7081
def writeVersions = { File file, List<Version> versions ->
7182
file.text = ""
@@ -75,42 +86,60 @@ tasks.register("updateCIBwcVersions") {
7586
}
7687
}
7788

78-
def writeBuildkiteList = { String outputFilePath, String pipelineTemplatePath, List<Version> versions ->
89+
def writeBuildkitePipeline = { String outputFilePath, String pipelineTemplatePath, List<ListExpansion> listExpansions, List<StepExpansion> stepExpansions = [] ->
7990
def outputFile = file(outputFilePath)
8091
def pipelineTemplate = file(pipelineTemplatePath)
8192

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
8594

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+
}
9099

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)
94106
}
95107

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")])
97121
}
98122

99123
doLast {
100124
writeVersions(file(".ci/bwcVersions"), BuildParams.bwcVersions.allIndexCompatible)
101125
writeVersions(file(".ci/snapshotBwcVersions"), BuildParams.bwcVersions.unreleasedIndexCompatible)
102-
writeBuildkiteList(
126+
expandBwcList(
103127
".buildkite/pipelines/intake.yml",
104128
".buildkite/pipelines/intake.template.yml",
105129
BuildParams.bwcVersions.unreleasedIndexCompatible
106130
)
107-
writeBuildkiteSteps(
131+
writeBuildkitePipeline(
108132
".buildkite/pipelines/periodic.yml",
109133
".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+
]
112140
)
113-
writeBuildkiteSteps(
141+
142+
expandBwcSteps(
114143
".buildkite/pipelines/periodic-packaging.yml",
115144
".buildkite/pipelines/periodic-packaging.template.yml",
116145
".buildkite/pipelines/periodic-packaging.bwc.template.yml",

0 commit comments

Comments
 (0)