-
Notifications
You must be signed in to change notification settings - Fork 418
Expand file tree
/
Copy pathpublish_multi_request.py
More file actions
executable file
·97 lines (73 loc) · 2.54 KB
/
publish_multi_request.py
File metadata and controls
executable file
·97 lines (73 loc) · 2.54 KB
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
#!/usr/bin/env python3
import argparse
import requests
import os
import subprocess
import xml.etree.ElementTree as ET
from typing import Iterable
PUBLISH_TOKEN = os.environ["PUBLISH_TOKEN"]
VERSION = os.environ["GITHUB_SHA"]
RELEASE_DIR = "release"
#
# CONFIGURATION PARAMETERS
# Forks should change these to publish to their own infrastructure.
#
ROBUST_CDN_URL = "https://cdn.starlight.network/"
FORK_ID = os.environ.get("FORK_ID", "starlight")
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--fork-id", default=FORK_ID)
args = parser.parse_args()
fork_id = args.fork_id
session = requests.Session()
session.headers = {
"Authorization": f"Bearer {PUBLISH_TOKEN}",
}
print(f"Starting publish on Robust.Cdn for version {VERSION}")
data = {
"version": VERSION,
"engineVersion": get_engine_version(),
}
headers = {
"Content-Type": "application/json"
}
resp = session.post(f"{ROBUST_CDN_URL}fork/{fork_id}/publish/start", json=data, headers=headers)
resp.raise_for_status()
print("Publish successfully started, adding files...")
for file in get_files_to_publish():
print(f"Publishing {file}")
with open(file, "rb") as f:
headers = {
"Content-Type": "application/octet-stream",
"Robust-Cdn-Publish-File": os.path.basename(file),
"Robust-Cdn-Publish-Version": VERSION
}
resp = session.post(f"{ROBUST_CDN_URL}fork/{fork_id}/publish/file", data=f, headers=headers)
resp.raise_for_status()
print("Successfully pushed files, finishing publish...")
data = {
"version": VERSION
}
headers = {
"Content-Type": "application/json"
}
resp = session.post(f"{ROBUST_CDN_URL}fork/{fork_id}/publish/finish", json=data, headers=headers)
resp.raise_for_status()
print("SUCCESS!")
def get_files_to_publish() -> Iterable[str]:
for file in os.listdir(RELEASE_DIR):
yield os.path.join(RELEASE_DIR, file)
def get_engine_version():
try:
version_file = "RobustToolbox/MSBuild/Robust.Engine.Version.props"
tree = ET.parse(version_file)
root = tree.getroot()
version = root.find(".//Version")
if version is None or not version.text:
raise ValueError(f"Version not found in {version_file}")
return version.text.strip()
except Exception as e:
print(f"Error reading version from {version_file}: {e}")
raise
if __name__ == '__main__':
main()