Skip to content

Commit 00d3690

Browse files
authored
🐛✨ [Frontend] Improve latest version fetching workflow (#7054)
1 parent 72c7428 commit 00d3690

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed
Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,83 @@
1-
import os
21
import json
3-
2+
import os
3+
import random
4+
from pathlib import Path
45

56
output_folders = [
6-
"source-output", # dev output
7+
"source-output", # dev output
78
"build-output", # default production output
8-
"build-client" # I believe we create the production outputs here
9+
"build-client", # I believe we create the production outputs here
910
]
1011

1112

12-
def read_json_file(filename):
13+
def _get_applications_from_metadata():
1314
dirname = os.path.dirname(__file__)
14-
meta_filename = os.path.join(dirname, filename)
15-
with open(meta_filename, "r") as file:
15+
meta_filename = os.path.join(dirname, "apps_metadata.json")
16+
with open(meta_filename) as file:
1617
metadata = json.load(file)
1718
return metadata["applications"]
1819

1920

2021
def update_apps_metadata():
2122
dirname = os.path.dirname(__file__)
22-
applications = read_json_file("apps_metadata.json")
23+
applications = _get_applications_from_metadata()
2324
for i in applications:
2425
application = i.get("application")
2526
for output_folder in output_folders:
26-
filename = os.path.join(dirname, '..', output_folder, application, "index.html")
27-
if not os.path.isfile(filename):
28-
continue
29-
with open(filename, "r") as file:
30-
data = file.read()
27+
index_file_path = Path(dirname).joinpath(
28+
"..", output_folder, application, "index.html"
29+
)
30+
if os.path.isfile(index_file_path):
31+
print(f"Updating app metadata: {index_file_path.resolve()}")
3132
replacements = i.get("replacements")
3233
for key in replacements:
3334
replace_text = replacements[key]
34-
data = data.replace("${"+key+"}", replace_text)
35-
with open(filename, "w") as file:
36-
print(f"Updating app metadata: {filename}")
37-
file.write(data)
35+
index_file_path.write_text(
36+
index_file_path.read_text().replace(
37+
"${" + key + "}",
38+
replace_text,
39+
)
40+
)
41+
42+
43+
def _get_output_file_paths(filename):
44+
output_file_paths: list[Path] = []
45+
dirname = os.path.dirname(__file__)
46+
applications = _get_applications_from_metadata()
47+
for i in applications:
48+
application = i.get("application")
49+
for output_folder in output_folders:
50+
output_file_path = Path(dirname).joinpath(
51+
"..", output_folder, application, filename
52+
)
53+
if output_file_path.is_file():
54+
output_file_paths.append(output_file_path)
55+
return output_file_paths
56+
57+
58+
def add_no_cache_param(vcs_ref_client):
59+
index_file_paths = _get_output_file_paths("index.html")
60+
for index_file_path in index_file_paths:
61+
print(f"Updating vcs_ref_client: {index_file_path.resolve()}")
62+
index_file_path.write_text(
63+
index_file_path.read_text().replace(
64+
"${boot_params}",
65+
"nocache=" + vcs_ref_client,
66+
)
67+
)
68+
69+
boot_file_paths = _get_output_file_paths("boot.js")
70+
for boot_file_path in boot_file_paths:
71+
print(f"Updating addNoCacheParam URL_PARAMETERS: {boot_file_path.resolve()}")
72+
boot_file_path.write_text(
73+
boot_file_path.read_text().replace(
74+
"addNoCacheParam : false",
75+
"addNoCacheParam : true",
76+
)
77+
)
3878

3979

4080
if __name__ == "__main__":
4181
update_apps_metadata()
82+
vcs_ref_client = os.getenv("VCS_REF_CLIENT", str(random.random()))
83+
add_no_cache_param(vcs_ref_client)

services/static-webserver/client/source/boot/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
</head>
6868
<body>
6969
${preBootJs}
70-
<script type="text/javascript" src="${appPath}boot.js"></script>
70+
<script type="text/javascript" src="${appPath}boot.js?${boot_params}"></script>
7171
</body>
7272
<script>
7373
window.markerConfig = {

0 commit comments

Comments
 (0)