Skip to content

Commit c9d026f

Browse files
authored
Merge pull request #583 from mozilla/Pat/pre-commit-hook
Pat/Pre-commit hook
2 parents f43464a + 4996695 commit c9d026f

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

pre-commit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
#
88
# To enable this hook, rename this file to "pre-commit".
99

10+
pytest test_local_executables_updated.py
11+
if [[ $? -ne 0 ]]; then
12+
echo "Please update your firefox/geckodriver!"
13+
exit 1
14+
fi
15+
1016
if git rev-parse --verify HEAD >/dev/null 2>&1
1117
then
1218
against=HEAD

test_local_executables_updated.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import subprocess
2+
import sys
3+
4+
import pytest
5+
import requests
6+
from selenium.webdriver import Firefox
7+
8+
GD_URL = "https://api.github.com/repos/mozilla/geckodriver/releases/latest"
9+
10+
11+
@pytest.fixture()
12+
def prefs_list():
13+
prefs = []
14+
return prefs
15+
16+
17+
@pytest.fixture()
18+
def suite_id():
19+
return ("-1", "None")
20+
21+
22+
def test_local_executables_updated(driver: Firefox, version):
23+
"""
24+
Test if the local firefox and geckodriver version are up-to-date.
25+
"""
26+
# Check firefox version
27+
latest_fx_ver = subprocess.check_output(
28+
[sys.executable, "./collect_executables.py", "-n"], text=True
29+
).split("-")[0]
30+
local_fx_ver = version[16:]
31+
if latest_fx_ver != local_fx_ver:
32+
print("You are not running the latest firefox version!!!")
33+
raise RuntimeError(
34+
f"Latest fx version is {latest_fx_ver} but you are running {local_fx_ver}"
35+
)
36+
37+
# Check geckodriver version
38+
latest_gd_ver = get_latest_geckodriver_version()
39+
local_gd_ver = driver.capabilities["moz:geckodriverVersion"]
40+
if latest_gd_ver != local_gd_ver:
41+
print("You are not running the latest geckodriver version!!!")
42+
print(f"Latest version is {latest_gd_ver} but you are running {local_gd_ver}")
43+
raise RuntimeError(
44+
f"Update geckodriver here: https://github.com/mozilla/geckodriver/releases/"
45+
)
46+
47+
48+
def get_latest_geckodriver_version():
49+
return requests.get(GD_URL).json()["tag_name"][1:]

0 commit comments

Comments
 (0)