Skip to content

Commit 3901562

Browse files
committed
Deps signature checking: enhance messages
1 parent 6ee7a79 commit 3901562

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

cmake/make_deps.py

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@
3535
"macOS-X64": "macos-13",
3636
}
3737

38+
39+
class Colors:
40+
HEADER = "\033[95m"
41+
OKBLUE = "\033[94m"
42+
OKCYAN = "\033[96m"
43+
OKGREEN = "\033[92m"
44+
WARNING = "\033[93m"
45+
FAIL = "\033[91m"
46+
ENDC = "\033[0m"
47+
BOLD = "\033[1m"
48+
UNDERLINE = "\033[4m"
49+
50+
3851
def find_platform():
3952
"""Find current platform."""
4053
system = platform.system()
@@ -69,7 +82,7 @@ def build_url(user, release):
6982
"releases",
7083
"download",
7184
f"v{release}",
72-
f"luxcore-deps-{suffix}.zip"
85+
f"luxcore-deps-{suffix}.zip",
7386
)
7487

7588
return "/".join(url)
@@ -115,31 +128,39 @@ def download(url, destdir):
115128
"""Download file from url into destdir."""
116129
# Download artifact
117130
destdir = Path(destdir)
118-
filename = urlparse(url).path.split('/')[-1]
131+
filename = urlparse(url).path.split("/")[-1]
119132
filepath = destdir / filename
120133
local_filename, _ = urlretrieve(url, filename=filepath)
121134

122135
# Check attestation
123136
logger.info("Checking '%s'", local_filename)
124-
gh_cmd = [
125-
shutil.which("gh"),
126-
"attestation",
127-
"verify",
128-
"-oLuxCoreRender",
129-
filepath,
130-
]
131-
with subprocess.Popen(
132-
gh_cmd,
133-
stdout=subprocess.PIPE,
134-
stderr=subprocess.STDOUT,
135-
text=True,
136-
) as proc:
137-
if (msg := proc.stdout.read()):
138-
logger.info(msg)
139-
140-
if proc.returncode:
141-
logger.error("SIGNATURE ERROR")
142137

138+
gh_app = shutil.which("gh")
139+
if not gh_app:
140+
logger.error(Colors.FAIL + "SIGNATURE CHECKING ERROR" + Colors.ENDC)
141+
msg = "Cannot find 'gh'application - Dependencies origin cannot be checked."
142+
logger.error(Colors.FAIL + msg + Colors.ENDC)
143+
else:
144+
gh_cmd = [
145+
gh_app,
146+
"attestation",
147+
"verify",
148+
"-oLuxCoreRender",
149+
"--format",
150+
"json",
151+
filepath,
152+
]
153+
try:
154+
gh_output = subprocess.check_output(gh_cmd, text=True)
155+
except subprocess.CalledProcessError as err:
156+
logger.error(Colors.FAIL + "SIGNATURE CHECKING ERROR" + Colors.ENDC)
157+
logger.error("gh return code: %s", err.returncode)
158+
logger.error(err.output)
159+
else:
160+
logger.info(Colors.OKGREEN + "'%s': found certificate - OK" + Colors.ENDC, filename)
161+
signature, *_ = json.loads(gh_output)
162+
certificate = signature["verificationResult"]["signature"]["certificate"]
163+
logger.debug(json.dumps(certificate, indent=2))
143164

144165
# Unzip
145166
with ZipFile(local_filename) as downloaded:
@@ -178,15 +199,14 @@ def copy_conf(dest):
178199
shutil.copy(source, dest)
179200

180201

181-
182202
def main(call_args=None):
183203
"""Entry point."""
184204
global OUTPUT_DIR
185205

186206
# Set-up logger
187207
logger.setLevel(logging.INFO)
188208
logging.basicConfig(level=logging.INFO)
189-
logger.info("BEGIN")
209+
logger.info(Colors.OKBLUE + "BEGIN" + Colors.ENDC)
190210

191211
# Get settings
192212
logger.info("Reading settings")
@@ -258,7 +278,6 @@ def main(call_args=None):
258278
else:
259279
logger.info("Using local dependency set ('%s')", args.local)
260280

261-
262281
# Clean
263282
logger.info("Cleaning local cache")
264283
res = run_conan(["remove", "-c", "*"], capture_output=True)
@@ -286,9 +305,7 @@ def main(call_args=None):
286305

287306
# Installing profiles
288307
logger.info("Installing profiles")
289-
run_conan(
290-
["config", "install-pkg", f"luxcoreconf/{release}@luxcore/luxcore"]
291-
)
308+
run_conan(["config", "install-pkg", f"luxcoreconf/{release}@luxcore/luxcore"])
292309

293310
# Generate & deploy
294311
# About release/debug mixing, see https://github.com/conan-io/conan/issues/12656
@@ -315,7 +332,7 @@ def main(call_args=None):
315332
subprocess.run(["cmake", "--list-presets=build"])
316333
print("", flush=True)
317334

318-
logger.info("END")
335+
logger.info(Colors.OKBLUE + "END" + Colors.ENDC)
319336

320337

321338
if __name__ == "__main__":

0 commit comments

Comments
 (0)