forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpinned_browsers.py
executable file
·233 lines (195 loc) · 6.82 KB
/
pinned_browsers.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env python
import codecs
import hashlib
import json
import urllib3
# Find the current stable versions of each browser we
# support and the sha256 of these. That's useful for
# updating `//commmon:repositories.bzl`
http = urllib3.PoolManager()
def calculate_hash(url):
h = hashlib.sha256()
r = http.request('GET', url, preload_content=False)
for b in iter(lambda: r.read(4096), b""):
h.update(b)
return h.hexdigest()
def chromedriver():
r = http.request('GET', 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE')
v = r.data.decode('utf-8')
content = ""
linux = 'https://chromedriver.storage.googleapis.com/%s/chromedriver_linux64.zip' % v
sha = calculate_hash(linux)
content = content + """
http_archive(
name = "linux_chromedriver",
url = "%s",
sha256 = "%s",
build_file_content = "exports_files([\\"chromedriver\\"])",
)
""" % (linux, sha)
mac = 'https://chromedriver.storage.googleapis.com/%s/chromedriver_mac64.zip' % v
sha = calculate_hash(mac)
content = content + """
http_archive(
name = "mac_chromedriver",
url = "%s",
sha256 = "%s",
build_file_content = "exports_files([\\"chromedriver\\"])",
)
""" % (mac, sha)
return content
def chrome():
# Find the current latest stable revision
r = http.request('GET', 'https://omahaproxy.appspot.com/all.json?channel=stable&os=linux')
max_version = int(json.loads(r.data)[0]['versions'][0]['branch_base_position'])
min_version = max_version - 1500
# count down from most recent to a version which has something for everyone
for v in range(max_version, min_version, -1):
r = http.request(
'HEAD',
'https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/%s/chrome-linux.zip' % v)
if r.status != 200:
continue
r = http.request(
'HEAD',
'https://storage.googleapis.com/chromium-browser-snapshots/Mac/%s/chrome-mac.zip' % v)
if r.status != 200:
continue
content = ""
linux = 'https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/%s/chrome-linux.zip' % v
sha = calculate_hash(linux)
content = content + """
http_archive(
name = "linux_chrome",
url = "%s",
sha256 = "%s",
build_file_content = "exports_files([\\"chrome-linux\\"])",
)
""" % (linux, sha)
mac = 'https://storage.googleapis.com/chromium-browser-snapshots/Mac/%s/chrome-mac.zip' % v
sha = calculate_hash(mac)
content = content + """
http_archive(
name = "mac_chrome",
url = "%s",
sha256 = "%s",
strip_prefix = "chrome-mac",
build_file_content = "exports_files([\\"Chromium.app\\"])",
)
""" % (mac, sha)
return content
raise RuntimeError("Cannot find stable chrome")
def edge():
r = http.request('GET', 'https://msedgedriver.azureedge.net/LATEST_STABLE')
v = r.data.decode('utf-16').strip()
content = ""
edge = "https://officecdn-microsoft-com.akamaized.net/pr/C1297A47-86C4-4C1F-97FA-950631F94777/MacAutoupdate/MicrosoftEdge-%s.pkg?platform=Mac&Consent=0&channel=Stable" % v
sha = calculate_hash(edge)
content = content + """
pkg_archive(
name = "mac_edge",
url = "%s",
sha256 = "%s",
move = {
"MicrosoftEdge-%s.pkg/Payload/Microsoft Edge.app": "Edge.app",
},
build_file_content = "exports_files([\\"Edge.app\\"])",
)
""" % (edge, sha, v)
return content
def edgedriver():
r = http.request('GET', 'https://msedgedriver.azureedge.net/LATEST_STABLE')
v = r.data.decode('utf-16').strip()
content = ""
linux = "https://msedgedriver.azureedge.net/%s/edgedriver_linux64.zip" % v
sha = calculate_hash(linux)
content = content + """
http_archive(
name = "linux_edgedriver",
url = "%s",
sha256 = "%s",
build_file_content = "exports_files([\\"msedgedriver\\"])",
)
""" % (linux, sha)
mac = "https://msedgedriver.azureedge.net/%s/edgedriver_mac64.zip" % v
sha = calculate_hash(mac)
content = content + """
http_archive(
name = "mac_edgedriver",
url = "%s",
sha256 = "%s",
build_file_content = "exports_files([\\"msedgedriver\\"])",
)
""" % (mac, sha)
return content
def geckodriver():
content = ""
r = http.request('GET', 'https://api.github.com/repos/mozilla/geckodriver/releases/latest')
for a in json.loads(r.data)['assets']:
if a['name'].endswith('-linux64.tar.gz'):
url = a['browser_download_url']
sha = calculate_hash(url)
content = content + \
"""
http_archive(
name = "linux_geckodriver",
url = "%s",
sha256 = "%s",
build_file_content = "exports_files([\\"geckodriver\\"])",
)
""" % (url, sha)
if a['name'].endswith('-macos.tar.gz'):
url = a['browser_download_url']
sha = calculate_hash(url)
content = content + \
"""
http_archive(
name = "mac_geckodriver",
url = "%s",
sha256 = "%s",
build_file_content = "exports_files([\\"geckodriver\\"])",
)
""" % (url, sha)
return content
def firefox():
r = http.request('GET', 'https://product-details.mozilla.org/1.0/firefox_versions.json')
v = json.loads(r.data)['LATEST_FIREFOX_VERSION']
content = ""
linux = "https://ftp.mozilla.org/pub/firefox/releases/%s/linux-x86_64/en-US/firefox-%s.tar.bz2" % (v, v)
sha = calculate_hash(linux)
content = content + """
http_archive(
name = "linux_firefox",
url = "%s",
sha256 = "%s",
build_file_content = "exports_files([\\"firefox\\"])",
)
""" % (linux, sha)
mac = "https://ftp.mozilla.org/pub/firefox/releases/%s/mac/en-US/Firefox%%20%s.dmg" % (v, v)
sha = calculate_hash(mac)
content = content + """
dmg_archive(
name = "mac_firefox",
url = "%s",
sha256 = "%s",
build_file_content = "exports_files([\\"Firefox.app\\"])",
)
""" % (mac, sha)
return content
if __name__ == '__main__':
content = """
# This file has been generated using `bazel run scripts:pinned_browsers`
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//common/private:dmg_archive.bzl", "dmg_archive")
load("//common/private:drivers.bzl", "local_drivers")
load("//common/private:pkg_archive.bzl", "pkg_archive")
def pin_browsers():
local_drivers()
"""
content = content + firefox()
content = content + geckodriver()
content = content + edge()
content = content + edgedriver()
content = content + chrome()
content = content + chromedriver()
print(content)