-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
rebuild_all_rtd.py
49 lines (38 loc) · 1.41 KB
/
rebuild_all_rtd.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
"""
Run all builds for all active versions of all SunPy and SunPy subprojects on
RTD.
"""
import os
import requests
ORG_PROJECT = "sunpy"
BASE_URL = "https://readthedocs.org/api/v3/projects/"
HEADERS = {"Authorization": f"Token {os.environ['RTD_AUTH_TOKEN']}"}
# RTD removes the full stop from the project slug
WEBSITE_PROJECT = "sunpyorg"
def get_active_versions(project):
r = requests.get(f"{BASE_URL}{project}/versions", headers=HEADERS, params={"active": True})
if not r.ok:
print(f"Failed to get versions for {project}: {r}")
return []
r = r.json()
if "results" not in r:
print(project)
print(r)
return []
results = r["results"]
return [res["slug"] for res in results]
def get_all_subprojects(base_project):
r = requests.get(f"{BASE_URL}{base_project}/subprojects", headers=HEADERS)
r = r.json()
results = r["results"]
return [res["child"]["slug"] for res in results]
def rebuild_all_versions_for_project(project):
slugs = get_active_versions(project)
for slug in slugs:
r = requests.post(f"{BASE_URL}{project}/versions/{slug}/builds/", headers=HEADERS)
if r.status_code != 202:
print(f"{slug} failed to build with: {r}")
if __name__ == "__main__":
projects = [ORG_PROJECT, *get_all_subprojects(ORG_PROJECT), WEBSITE_PROJECT]
for project in projects:
rebuild_all_versions_for_project(project)