5
from dataclasses import asdict, dataclass, field
6
from pathlib import Path
7
from typing import Dict, Iterable, List, Literal, Set
8
from typing_extensions import TypedDict
10
import generate_binary_build_matrix
14
Arch = Literal["windows", "linux", "macos"]
16
GITHUB_DIR = Path(__file__).resolve().parent.parent
18
LABEL_CIFLOW_TRUNK = "ciflow/trunk"
19
LABEL_CIFLOW_UNSTABLE = "ciflow/unstable"
20
LABEL_CIFLOW_BINARIES = "ciflow/binaries"
21
LABEL_CIFLOW_PERIODIC = "ciflow/periodic"
22
LABEL_CIFLOW_BINARIES_LIBTORCH = "ciflow/binaries_libtorch"
23
LABEL_CIFLOW_BINARIES_CONDA = "ciflow/binaries_conda"
24
LABEL_CIFLOW_BINARIES_WHEEL = "ciflow/binaries_wheel"
30
run_on_canary: bool = False
31
labels: Set[str] = field(default_factory=set)
33
isolated_workflow: bool = False
34
unstable: bool = False
36
def __post_init__(self) -> None:
37
if not self.isolated_workflow:
38
if LABEL_CIFLOW_PERIODIC not in self.labels:
40
LABEL_CIFLOW_TRUNK if not self.unstable else LABEL_CIFLOW_UNSTABLE
44
class Config(TypedDict):
50
class BinaryBuildWorkflow:
52
build_configs: List[Dict[str, str]]
56
build_environment: str = ""
58
ciflow_config: CIFlowConfig = field(default_factory=CIFlowConfig)
59
is_scheduled: str = ""
60
branches: str = "nightly"
62
cross_compile_arm64: bool = False
63
macos_runner: str = "macos-14-xlarge"
65
def __post_init__(self) -> None:
67
self.build_environment = (
68
f"{self.os}-binary-{self.package_type}-{self.abi_version}"
71
self.build_environment = f"{self.os}-binary-{self.package_type}"
73
def generate_workflow_file(self, workflow_template: jinja2.Template) -> None:
76
/ f"workflows/generated-{self.build_environment}-{self.branches}.yml"
78
with open(output_file_path, "w") as output_file:
79
GENERATED = "generated"
80
output_file.writelines([f"# @{GENERATED} DO NOT EDIT MANUALLY\n"])
82
content = workflow_template.render(asdict(self))
83
except Exception as e:
84
print(f"Failed on template: {workflow_template}", file=sys.stderr)
86
output_file.write(content)
87
if content[-1] != "\n":
88
output_file.write("\n")
89
print(output_file_path)
96
MACOS_ARM64 = "macos-arm64"
97
LINUX_AARCH64 = "linux-aarch64"
98
LINUX_S390X = "linux-s390x"
101
LINUX_BINARY_BUILD_WORFKLOWS = [
103
os=OperatingSystem.LINUX,
104
package_type="manywheel",
105
build_configs=generate_binary_build_matrix.generate_wheels_matrix(
106
OperatingSystem.LINUX
108
ciflow_config=CIFlowConfig(
109
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_WHEEL},
110
isolated_workflow=True,
114
os=OperatingSystem.LINUX,
115
package_type="conda",
116
build_configs=generate_binary_build_matrix.generate_conda_matrix(
117
OperatingSystem.LINUX
119
ciflow_config=CIFlowConfig(
120
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_CONDA},
121
isolated_workflow=True,
125
os=OperatingSystem.LINUX,
126
package_type="libtorch",
127
abi_version=generate_binary_build_matrix.CXX11_ABI,
128
build_configs=generate_binary_build_matrix.generate_libtorch_matrix(
129
OperatingSystem.LINUX,
130
generate_binary_build_matrix.CXX11_ABI,
131
libtorch_variants=["shared-with-deps"],
133
ciflow_config=CIFlowConfig(
134
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_LIBTORCH},
135
isolated_workflow=True,
139
os=OperatingSystem.LINUX,
140
package_type="libtorch",
141
abi_version=generate_binary_build_matrix.PRE_CXX11_ABI,
142
build_configs=generate_binary_build_matrix.generate_libtorch_matrix(
143
OperatingSystem.LINUX,
144
generate_binary_build_matrix.PRE_CXX11_ABI,
145
libtorch_variants=["shared-with-deps"],
147
ciflow_config=CIFlowConfig(
148
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_LIBTORCH},
149
isolated_workflow=True,
154
LINUX_BINARY_SMOKE_WORKFLOWS = [
156
os=OperatingSystem.LINUX,
157
package_type="manywheel",
158
build_configs=generate_binary_build_matrix.generate_wheels_matrix(
159
OperatingSystem.LINUX,
160
arches=["11.8", "12.1", "12.4"],
161
python_versions=["3.9"],
166
os=OperatingSystem.LINUX,
167
package_type="libtorch",
168
abi_version=generate_binary_build_matrix.CXX11_ABI,
169
build_configs=generate_binary_build_matrix.generate_libtorch_matrix(
170
OperatingSystem.LINUX,
171
generate_binary_build_matrix.CXX11_ABI,
173
libtorch_variants=["shared-with-deps"],
178
os=OperatingSystem.LINUX,
179
package_type="libtorch",
180
abi_version=generate_binary_build_matrix.PRE_CXX11_ABI,
181
build_configs=generate_binary_build_matrix.generate_libtorch_matrix(
182
OperatingSystem.LINUX,
183
generate_binary_build_matrix.PRE_CXX11_ABI,
185
libtorch_variants=["shared-with-deps"],
191
WINDOWS_BINARY_BUILD_WORKFLOWS = [
193
os=OperatingSystem.WINDOWS,
194
package_type="wheel",
195
build_configs=generate_binary_build_matrix.generate_wheels_matrix(
196
OperatingSystem.WINDOWS
198
ciflow_config=CIFlowConfig(
199
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_WHEEL},
200
isolated_workflow=True,
204
os=OperatingSystem.WINDOWS,
205
package_type="conda",
206
build_configs=generate_binary_build_matrix.generate_conda_matrix(
207
OperatingSystem.WINDOWS
209
ciflow_config=CIFlowConfig(
210
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_CONDA},
211
isolated_workflow=True,
215
os=OperatingSystem.WINDOWS,
216
package_type="libtorch",
217
abi_version=generate_binary_build_matrix.RELEASE,
218
build_configs=generate_binary_build_matrix.generate_libtorch_matrix(
219
OperatingSystem.WINDOWS,
220
generate_binary_build_matrix.RELEASE,
221
libtorch_variants=["shared-with-deps"],
223
ciflow_config=CIFlowConfig(
224
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_LIBTORCH},
225
isolated_workflow=True,
229
os=OperatingSystem.WINDOWS,
230
package_type="libtorch",
231
abi_version=generate_binary_build_matrix.DEBUG,
232
build_configs=generate_binary_build_matrix.generate_libtorch_matrix(
233
OperatingSystem.WINDOWS,
234
generate_binary_build_matrix.DEBUG,
235
libtorch_variants=["shared-with-deps"],
237
ciflow_config=CIFlowConfig(
238
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_LIBTORCH},
239
isolated_workflow=True,
244
WINDOWS_BINARY_SMOKE_WORKFLOWS = [
246
os=OperatingSystem.WINDOWS,
247
package_type="libtorch",
248
abi_version=generate_binary_build_matrix.RELEASE,
249
build_configs=generate_binary_build_matrix.generate_libtorch_matrix(
250
OperatingSystem.WINDOWS,
251
generate_binary_build_matrix.RELEASE,
253
libtorch_variants=["shared-with-deps"],
256
ciflow_config=CIFlowConfig(
257
isolated_workflow=True,
261
os=OperatingSystem.WINDOWS,
262
package_type="libtorch",
263
abi_version=generate_binary_build_matrix.DEBUG,
264
build_configs=generate_binary_build_matrix.generate_libtorch_matrix(
265
OperatingSystem.WINDOWS,
266
generate_binary_build_matrix.DEBUG,
268
libtorch_variants=["shared-with-deps"],
271
ciflow_config=CIFlowConfig(
272
isolated_workflow=True,
277
MACOS_BINARY_BUILD_WORKFLOWS = [
279
os=OperatingSystem.MACOS_ARM64,
280
package_type="libtorch",
281
abi_version=generate_binary_build_matrix.CXX11_ABI,
282
build_configs=generate_binary_build_matrix.generate_libtorch_matrix(
283
OperatingSystem.MACOS,
284
generate_binary_build_matrix.CXX11_ABI,
285
libtorch_variants=["shared-with-deps"],
287
cross_compile_arm64=False,
288
macos_runner="macos-14-xlarge",
289
ciflow_config=CIFlowConfig(
290
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_LIBTORCH},
291
isolated_workflow=True,
295
os=OperatingSystem.MACOS_ARM64,
296
package_type="wheel",
297
build_configs=generate_binary_build_matrix.generate_wheels_matrix(
298
OperatingSystem.MACOS_ARM64
300
cross_compile_arm64=False,
301
macos_runner="macos-14-xlarge",
302
ciflow_config=CIFlowConfig(
303
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_WHEEL},
304
isolated_workflow=True,
308
os=OperatingSystem.MACOS_ARM64,
309
package_type="conda",
310
cross_compile_arm64=False,
311
macos_runner="macos-14-xlarge",
312
build_configs=generate_binary_build_matrix.generate_conda_matrix(
313
OperatingSystem.MACOS_ARM64
315
ciflow_config=CIFlowConfig(
316
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_CONDA},
317
isolated_workflow=True,
322
AARCH64_BINARY_BUILD_WORKFLOWS = [
324
os=OperatingSystem.LINUX_AARCH64,
325
package_type="manywheel",
326
build_configs=generate_binary_build_matrix.generate_wheels_matrix(
327
OperatingSystem.LINUX_AARCH64
329
ciflow_config=CIFlowConfig(
330
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_WHEEL},
331
isolated_workflow=True,
336
S390X_BINARY_BUILD_WORKFLOWS = [
338
os=OperatingSystem.LINUX_S390X,
339
package_type="manywheel",
340
build_configs=generate_binary_build_matrix.generate_wheels_matrix(
341
OperatingSystem.LINUX_S390X
343
ciflow_config=CIFlowConfig(
344
labels={LABEL_CIFLOW_BINARIES, LABEL_CIFLOW_BINARIES_WHEEL},
345
isolated_workflow=True,
352
jinja_env = jinja2.Environment(
353
variable_start_string="!{{",
354
loader=jinja2.FileSystemLoader(str(GITHUB_DIR.joinpath("templates"))),
355
undefined=jinja2.StrictUndefined,
359
template_and_workflows = [
361
jinja_env.get_template("linux_binary_build_workflow.yml.j2"),
362
LINUX_BINARY_BUILD_WORFKLOWS,
365
jinja_env.get_template("linux_binary_build_workflow.yml.j2"),
366
AARCH64_BINARY_BUILD_WORKFLOWS,
369
jinja_env.get_template("linux_binary_build_workflow.yml.j2"),
370
S390X_BINARY_BUILD_WORKFLOWS,
373
jinja_env.get_template("linux_binary_build_workflow.yml.j2"),
374
LINUX_BINARY_SMOKE_WORKFLOWS,
377
jinja_env.get_template("windows_binary_build_workflow.yml.j2"),
378
WINDOWS_BINARY_BUILD_WORKFLOWS,
381
jinja_env.get_template("windows_binary_build_workflow.yml.j2"),
382
WINDOWS_BINARY_SMOKE_WORKFLOWS,
385
jinja_env.get_template("macos_binary_build_workflow.yml.j2"),
386
MACOS_BINARY_BUILD_WORKFLOWS,
390
existing_workflows = GITHUB_DIR.glob("workflows/generated-*")
391
for w in existing_workflows:
394
except Exception as e:
395
print(f"Error occurred when deleting file {w}: {e}")
397
for template, workflows in template_and_workflows:
399
if not isinstance(workflows, Iterable):
401
f"How is workflows not iterable? {workflows}"
403
for workflow in workflows:
404
workflow.generate_workflow_file(workflow_template=template)
407
if __name__ == "__main__":