Skip to content

Commit 4b33f5f

Browse files
authored
html2print: minor cleanups on windows (#29)
1 parent e751953 commit 4b33f5f

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Mark the file as binary, so that Git won't not convert the line endings.
2+
# Otherwise, the file becomes unreadable for bash inside Docker (on Windows platforms).
3+
entrypoint.sh -text
4+

.github/workflows/ci-windows.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,7 @@ jobs:
2828
shell: powershell
2929

3030
- name: Check Chrome Version
31-
run: '& "C:\Program Files\Google\Chrome\Application\chrome.exe" --version'
32-
shell: powershell
33-
34-
- name: Add Chrome to PATH
35-
run: |
36-
$chromePath = "C:\Program Files\Google\Chrome\Application"
37-
echo "Adding $chromePath to PATH"
38-
echo "$chromePath" | Out-File -Append -Encoding utf8 $env:GITHUB_PATH
39-
shell: powershell
40-
41-
- name: Verify Chrome Installation
42-
run: chrome --version
31+
run: '(Get-Item "C:\Program Files\Google\Chrome\Application\chrome.exe").VersionInfo'
4332
shell: powershell
4433

4534
- name: Upgrade pip

html2print/html2print.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,18 @@ def _download_chromedriver(
109109
path_to_cached_chrome_driver: str,
110110
) -> str:
111111
url = "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
112-
response = ChromeDriverManager.send_http_get_request(url).json()
112+
response = ChromeDriverManager.send_http_get_request(url)
113+
if response is None:
114+
raise RuntimeError(
115+
"Could not download known-good-versions-with-downloads.json"
116+
)
117+
118+
response = response.json()
119+
if response is None:
120+
raise RuntimeError(
121+
"Could not parse known-good-versions-with-downloads.json"
122+
)
123+
assert isinstance(response, dict)
113124

114125
matching_versions = [
115126
item
@@ -118,7 +129,7 @@ def _download_chromedriver(
118129
]
119130

120131
if not matching_versions:
121-
raise Exception(
132+
raise RuntimeError(
122133
f"No compatible ChromeDriver found for Chrome version {chrome_major_version}"
123134
)
124135

@@ -142,6 +153,11 @@ def _download_chromedriver(
142153
)
143154
response = ChromeDriverManager.send_http_get_request(driver_url)
144155

156+
if response is None:
157+
raise RuntimeError(
158+
f"Could not download ChromeDriver from {driver_url}"
159+
)
160+
145161
Path(path_to_driver_cache_dir).mkdir(parents=True, exist_ok=True)
146162
zip_path = os.path.join(path_to_driver_cache_dir, "chromedriver.zip")
147163
print( # noqa: T201
@@ -179,6 +195,9 @@ def send_http_get_request(url: str) -> Response:
179195
f"html2print: "
180196
f"failed to get response for URL: {url} with error: {last_error}"
181197
)
198+
raise RuntimeError(
199+
f"GET request failed after 3 attempts: {url}"
200+
) from last_error
182201

183202
@staticmethod
184203
def get_chrome_version() -> Optional[str]:

tests/integration/lit.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ config.suffixes = ['.itest', '.c']
2323
config.is_windows = lit_config.isWindows
2424
if not lit_config.isWindows:
2525
config.available_features.add('PLATFORM_IS_NOT_WINDOWS')
26+
27+
# In Linux CI, $HOME is required for Chrome as it needs to access things in ~/.local
28+
config.environment['HOME'] = os.environ.get('HOME', '/tmp')
29+
30+
# In Windows CI, %ProgramW6432% is required for Selenium to properly detect browsers
31+
config.environment['ProgramW6432'] = os.environ.get('ProgramW6432', '')

0 commit comments

Comments
 (0)