-
Notifications
You must be signed in to change notification settings - Fork 272
/
build_manifest.py
153 lines (135 loc) · 5.13 KB
/
build_manifest.py
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
from manifests.build.build_manifest_1_0 import BuildManifest_1_0
from manifests.build.build_manifest_1_1 import BuildManifest_1_1
from manifests.component_manifest import Component, ComponentManifest, Components
"""
A BuildManifest is an immutable view of the outputs from a build step
The manifest contains information about the product that was built (in the `build` section),
and the components that made up the build in the `components` section.
The format for schema version 1.2 is:
schema-version: "1.2"
build:
name: string
version: string
platform: linux, darwin or windows
architecture: x64 or arm64
distribution: tar, zip, deb and rpm
id: build id
components:
- name: string
repository: URL of git repository
ref: git ref that was built (sha, branch, or tag)
commit_id: The actual git commit ID that was built (i.e. the resolved "ref")
artifacts:
maven:
- maven/relative/path/to/artifact
- ...
plugins:
- plugins/relative/path/to/artifact
- ...
libs:
- libs/relative/path/to/artifact
- ...
- ...
"""
class BuildManifest(ComponentManifest['BuildManifest', 'BuildComponents']):
VERSIONS = {
"1.0": BuildManifest_1_0,
"1.1": BuildManifest_1_1,
# "1.2" : current
}
SCHEMA = {
"build": {
"required": True,
"type": "dict",
"schema": {
"platform": {"required": True, "type": "string"}, # added in 1.2
"architecture": {"required": True, "type": "string"},
"distribution": {"type": "string"},
"id": {"required": True, "type": "string"},
"name": {"required": True, "type": "string"},
"version": {"required": True, "type": "string"},
},
},
"schema-version": {"required": True, "type": "string", "allowed": ["1.2"]},
"components": {
"type": "list",
"schema": {
"type": "dict",
"schema": {
"artifacts": {
"type": "dict",
"schema": {
"maven": {"type": "list"},
"plugins": {"type": "list"},
"dist": {"type": "list"}, # replaced "build" in 1.1
"core-plugins": {"type": "list"},
"libs": {"type": "list"},
},
},
"commit_id": {"required": True, "type": "string"},
"name": {"required": True, "type": "string"},
"ref": {"required": True, "type": "string"},
"repository": {"required": True, "type": "string"},
"version": {"required": True, "type": "string"},
},
},
},
}
def __init__(self, data: dict) -> None:
super().__init__(data)
self.build = self.Build(data["build"])
self.components = BuildComponents(data.get("components", [])) # type: ignore[assignment]
def __to_dict__(self) -> dict:
return {
"schema-version": "1.2",
"build": self.build.__to_dict__(),
"components": self.components.__to_dict__()
}
class Build:
def __init__(self, data: dict) -> None:
self.name: str = data["name"]
self.version: str = data["version"]
self.platform: str = data["platform"]
self.architecture: str = data["architecture"]
self.distribution: str = data.get('distribution', None)
self.id: str = data["id"]
def __to_dict__(self) -> dict:
return {
"name": self.name,
"version": self.version,
"platform": self.platform,
"architecture": self.architecture,
"distribution": self.distribution,
"id": self.id
}
@property
def filename(self) -> str:
return self.name.lower().replace(" ", "-")
class BuildComponents(Components['BuildComponent']):
@classmethod
def __create__(self, data: dict) -> 'BuildComponent':
return BuildComponent(data)
class BuildComponent(Component):
def __init__(self, data: dict) -> None:
super().__init__(data)
self.repository = data["repository"]
self.ref = data["ref"]
self.commit_id = data["commit_id"]
self.artifacts = data.get("artifacts", {})
self.version = data["version"]
def __to_dict__(self) -> dict:
return {
"name": self.name,
"repository": self.repository,
"ref": self.ref,
"commit_id": self.commit_id,
"artifacts": self.artifacts,
"version": self.version,
}
BuildManifest.VERSIONS = {"1.0": BuildManifest_1_0, "1.1": BuildManifest_1_1, "1.2": BuildManifest}