-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
56 lines (42 loc) · 1.6 KB
/
main.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
import os
from glob import glob
from pathlib import Path
from package_publisher.cli_arguments import CliArguments
from package_publisher.core import PackagePublisher
from package_publisher.helpers import attestations_to_bundle
arguments = CliArguments()
artifacts_dir = arguments.get_artifacts_dir()
if artifacts_dir == "":
print(
"Error: Missing --artifacts-dir argument. Example: --artifacts-dir ./artifacts"
)
exit(1)
artifacts_glob = glob("{}/**/*".format(artifacts_dir), recursive=True)
file_paths = [path for path in artifacts_glob if os.path.isfile(path)]
attestations_dir = arguments.get_attestations_dir()
if attestations_dir != "":
attestations_glob = glob("{}/**/*".format(attestations_dir), recursive=True)
attestation_files = [path for path in attestations_glob if os.path.isfile(path)]
attestation_bundle_path = attestations_to_bundle(attestation_files)
else:
attestation_bundle_path = None
publisher = PackagePublisher(
registry=arguments.get_registry(),
attestation_bundle_path=attestation_bundle_path,
)
for file_path in file_paths:
print(
"Publishing {} → {}".format(
file_path.replace("{}/".format(artifacts_dir), ""), arguments.get_registry()
)
)
response = publisher.upload_package(
file_path=file_path,
)
print(" ✅ \033]1339;url={}\a".format(response["web_url"]))
print("")
if attestation_bundle_path is not None:
print("~~~ 🚚 Preview Attestation Bundle")
with open(attestation_bundle_path, "r", encoding="utf-8") as f:
print(f.read())
Path(attestation_bundle_path).unlink()