Skip to content

Commit 766d2dd

Browse files
committed
Fix: point latest.html to stable and testing.html to testing for releases
1 parent 33fb048 commit 766d2dd

File tree

3 files changed

+58
-49
lines changed

3 files changed

+58
-49
lines changed

_layouts/default.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
</head>
2121
<body>
2222
<div id="header">
23-
{% assign latest_stable = site.downloads | where_exp: "download", "download.id contains '/downloads/openttd-releases/'" | where_exp: "download", "download.name == 'stable'" | sort: "id" | last %}
24-
{% assign latest_testing = site.downloads | where_exp: "download", "download.id == '/downloads/openttd-releases/latest'" | last %}
23+
{% assign latest_stable = site.downloads | where_exp: "download", "download.id == '/downloads/openttd-releases/latest'" | last %}
24+
{% assign latest_testing = site.downloads | where_exp: "download", "download.id == '/downloads/openttd-releases/testing'" | last %}
2525
{% assign latest_nightly = site.downloads | where_exp: "download", "download.id == '/downloads/openttd-nightlies/latest'" | last %}
2626

2727
{% if latest_nightly.version == latest_stable.version or latest_nightly.version == latest_testing.version %}

fetch-downloads.py

+55-46
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
}
2525

2626
# Current supported types on the new infrastructure
27-
types = [
28-
"openttd-nightlies",
29-
"openttd-releases",
30-
]
31-
types_grouped_by_branch = [
32-
"openttd-pullrequests",
33-
]
27+
types = {
28+
"openttd-nightlies": "flatten",
29+
"openttd-releases": "stable-testing",
30+
"openttd-pullrequests": "name",
31+
}
3432

3533

3634
async def download(url):
@@ -103,15 +101,6 @@ async def get_old_versions_of_folder(folder):
103101
return versions
104102

105103

106-
async def get_latest(folder):
107-
# We use the non-CDN URL here, as we want the latest; not any edge-cached version
108-
latest = await download(f"https://openttd.ams3.digitaloceanspaces.com/{folder}/latest.txt")
109-
latest = latest.decode()
110-
111-
version, _, date = latest.partition(",")
112-
return version
113-
114-
115104
async def get_listing(folder):
116105
# We use the non-CDN URL here, as we want the latest; not any edge-cached version
117106
listing = await download(f"https://openttd.ams3.digitaloceanspaces.com/{folder}/listing.txt")
@@ -121,8 +110,8 @@ async def get_listing(folder):
121110
if not entry:
122111
continue
123112

124-
version, _, date = entry.partition(",")
125-
versions[version] = date
113+
version, date, name = entry.split(",", 3)
114+
versions[version] = (date, name)
126115

127116
return versions
128117

@@ -146,8 +135,9 @@ async def write_to_collection(type, version, manifest):
146135
f.write("---\n".encode())
147136

148137

149-
async def handle_version(folder, type, version, host, on_old_infrastructure="false", latest=None):
150-
print(f"Adding {type}/{version} to downloads collection ..")
138+
async def handle_version(folder, dest_folder, version, host, on_old_infrastructure="false",
139+
latest=None, latest_filenames=None):
140+
print(f"Adding {dest_folder}/{version} to downloads collection ..")
151141
manifest = await fetch_manifest(folder, version, host, on_old_infrastructure=on_old_infrastructure)
152142

153143
# Insert the version into the header; otherwise we don't know
@@ -156,11 +146,15 @@ async def handle_version(folder, type, version, host, on_old_infrastructure="fal
156146
manifest.insert(1, f"version: {version}")
157147
manifest = "\n".join(manifest)
158148

159-
await write_to_collection(type, version, manifest)
149+
await write_to_collection(dest_folder, version, manifest)
160150

161151
# If this is the current version, also copy the content to "latest"
162152
if version == latest:
163-
await write_to_collection(type, "latest", manifest)
153+
if latest_filenames is None:
154+
latest_filenames = ["latest"]
155+
156+
for latest_filename in latest_filenames:
157+
await write_to_collection(dest_folder, latest_filename, manifest)
164158

165159

166160
async def main():
@@ -191,41 +185,56 @@ async def main():
191185
latest=latest)
192186

193187
# Support for new infrastructure; those are hosted on the DigitalOcean CDN (Spaces)
194-
for type in types:
195-
latest = await get_latest(type)
196-
versions = await get_listing(type)
197-
for version, data in versions.items():
198-
os.makedirs(f"_downloads/{type}", exist_ok=True)
199-
await handle_version(
200-
type,
201-
type,
202-
version,
203-
"https://proxy.binaries.openttd.org",
204-
latest=latest)
205-
206-
for type in types_grouped_by_branch:
188+
for type, method in types.items():
207189
version_grouped = defaultdict(list)
208-
latest_grouped = defaultdict(str)
190+
latest_grouped = defaultdict(lambda: ["", ""])
209191
versions = await get_listing(type)
210192

211-
# Regroup the versions based on the branch (which is the second part in the name)
193+
# Regroup the versions based on the method
212194
for version, data in versions.items():
213-
(date, branch, tag) = version.split("-", 3)
195+
(date, name) = data
196+
197+
if method == "flatten":
198+
index = None
199+
else:
200+
index = name
214201

215-
version_grouped[branch].append((version, data))
216-
if latest_grouped[branch] < date:
217-
latest_grouped[branch] = version
202+
version_grouped[index].append(version)
203+
if latest_grouped[index][0] < date:
204+
latest_grouped[index] = (date, version)
218205

219206
# Now, based on the group, generate the files
220-
for branch in version_grouped.keys():
221-
for version, data in version_grouped[branch]:
222-
os.makedirs(f"_downloads/{type}/{branch}", exist_ok=True)
207+
for index in version_grouped.keys():
208+
for version in version_grouped[index]:
209+
if method == "name":
210+
dest_folder = f"{type}/{index}"
211+
else:
212+
dest_folder = type
213+
214+
if method == "stable-testing":
215+
if index == "stable":
216+
# Force 'latest' to always point to 'stable'
217+
latest_filenames = ["latest"]
218+
else:
219+
latest_filenames = ["testing"]
220+
221+
# In case testing is older than stable, stable becomes the testing
222+
if latest_grouped["testing"][0] < latest_grouped["stable"][0]:
223+
if index == "stable":
224+
latest_filenames.append("testing")
225+
else:
226+
latest_filenames = []
227+
else:
228+
latest_filenames = ["latest"]
229+
230+
os.makedirs(f"_downloads/{dest_folder}", exist_ok=True)
223231
await handle_version(
224232
type,
225-
f"{type}/{branch}",
233+
dest_folder,
226234
version,
227235
"https://proxy.binaries.openttd.org",
228-
latest=latest_grouped[branch])
236+
latest=latest_grouped[index][1],
237+
latest_filenames=latest_filenames)
229238

230239
await session.close()
231240

nginx.default.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ server {
7979

8080
# Download pages of the latest version
8181
location ~ ^/(\w\w/)?download-stable$ { return 301 $scheme://$http_host/downloads/openttd-releases/latest.html; }
82-
location ~ ^/(\w\w/)?download-testing$ { return 301 $scheme://$http_host/downloads/openttd-releases/latest.html; }
82+
location ~ ^/(\w\w/)?download-testing$ { return 301 $scheme://$http_host/downloads/openttd-releases/testing.html; }
8383
location ~ ^/(\w\w/)?download-trunk$ { return 301 $scheme://$http_host/downloads/openttd-nightlies/latest.html; }
8484
location ~ ^/(\w\w/)?download-catcodec$ { return 301 $scheme://$http_host/downloads/catcodec-releases/latest.html; }
8585
location ~ ^/(\w\w/)?download-grfcodec$ { return 301 $scheme://$http_host/downloads/grfcodec-releases/latest.html; }

0 commit comments

Comments
 (0)