-
Notifications
You must be signed in to change notification settings - Fork 262
/
artifact.bzl
129 lines (116 loc) · 3.89 KB
/
artifact.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
load("@prelude//python:toolchain.bzl", "PythonToolchainInfo")
load("//artifact:toolchain.bzl", "ArtifactToolchainInfo")
ArtifactInfo = provider(fields = {
"artifact": provider_field(typing.Any, default = None),
"metadata": provider_field(typing.Any, default = None),
"family": str,
"variant": str,
})
def artifact_publish_impl(ctx: AnalysisContext) -> list[[DefaultInfo, RunInfo]]:
cli_args = ctx.actions.declare_output("args.txt")
artifact_toolchain = ctx.attrs._artifact_toolchain[ArtifactToolchainInfo]
cmd = cmd_args(
ctx.attrs._python_toolchain[PythonToolchainInfo].interpreter,
artifact_toolchain.publish[DefaultInfo].default_outputs,
"--destination",
ctx.attrs.destination,
"--artifact-file",
ctx.attrs.artifact[ArtifactInfo].artifact,
"--metadata-file",
ctx.attrs.artifact[ArtifactInfo].metadata,
)
if ctx.attrs.cname:
cmd.add("--cname")
cmd.add(ctx.attrs.cname)
ctx.actions.write(cli_args.as_output(), cmd)
return [
DefaultInfo(default_output = cli_args),
RunInfo(args = cmd),
]
artifact_publish = rule(
impl = artifact_publish_impl,
attrs = {
"destination": attrs.string(
doc = """Destination [examples: {}].""".format(", ".join([
"s3://my-bucket",
"gcs://bucket-name",
"docker://docker.io",
])),
),
"artifact": attrs.dep(
providers = [ArtifactInfo],
doc = """The `artifact` to publish.""",
),
"cname": attrs.option(
attrs.string(),
default = None,
doc = """Hostname used when calculating canonical URLs.""",
),
"_python_toolchain": attrs.toolchain_dep(
default = "toolchains//:python",
providers = [PythonToolchainInfo],
),
"_artifact_toolchain": attrs.toolchain_dep(
default = "toolchains//:artifact",
providers = [ArtifactToolchainInfo],
),
},
)
def artifact_promote_impl(ctx: AnalysisContext) -> list[[DefaultInfo, RunInfo]]:
cli_args = ctx.actions.declare_output("args.txt")
artifact_toolchain = ctx.attrs._artifact_toolchain[ArtifactToolchainInfo]
cmd = cmd_args(
ctx.attrs._python_toolchain[PythonToolchainInfo].interpreter,
artifact_toolchain.promote[DefaultInfo].default_outputs,
"--destination",
ctx.attrs.destination,
"--channel",
ctx.attrs.channel,
"--family",
ctx.attrs.family,
"--variant",
ctx.attrs.variant,
)
if ctx.attrs.cname:
cmd.add("--cname")
cmd.add(ctx.attrs.cname)
ctx.actions.write(cli_args.as_output(), cmd)
return [
DefaultInfo(default_output = cli_args),
RunInfo(args = cmd),
]
artifact_promote = rule(
impl = artifact_promote_impl,
attrs = {
"destination": attrs.string(
doc = """Destination [examples: {}].""".format(", ".join([
"s3://my-bucket",
"gcs://bucket-name",
"docker://docker.io",
])),
),
"channel": attrs.string(
doc = """Release channel.""",
default = "stable",
),
"family": attrs.string(
doc = """Artifact family.""",
),
"variant": attrs.string(
doc = """Artifact variant.""",
),
"cname": attrs.option(
attrs.string(),
default = None,
doc = """Hostname used when calculating canonical URLs.""",
),
"_python_toolchain": attrs.toolchain_dep(
default = "toolchains//:python",
providers = [PythonToolchainInfo],
),
"_artifact_toolchain": attrs.toolchain_dep(
default = "toolchains//:artifact",
providers = [ArtifactToolchainInfo],
),
},
)