Skip to content

Commit 8f8709e

Browse files
author
RedZapdos123
committed
ci: stub webdriver download in CI to avoid timeouts
Signed-off-by: RedZapdos123 <redzapdos123@example.com>
1 parent 9253549 commit 8f8709e

1 file changed

Lines changed: 44 additions & 10 deletions

File tree

plotly_static/build.rs

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,53 @@ fn setup_driver(config: &WebdriverDownloadConfig) -> Result<()> {
174174
match config.driver_name {
175175
CHROMEDRIVER_NAME => {
176176
let driver_info = ChromedriverInfo::new(webdriver_bin.clone(), browser_path);
177-
runtime
178-
.block_on(async { download_with_retry(&driver_info, false, true, 1).await })
179-
.with_context(|| {
180-
format!("Failed to download and install {}", config.driver_name)
181-
})?;
177+
let dl_res = runtime
178+
.block_on(async { download_with_retry(&driver_info, false, true, 1).await });
179+
if let Err(e) = dl_res {
180+
// In CI environments (GitHub Actions) network or permission restrictions
181+
// can cause the download to fail or hang. Create a CI-friendly stub
182+
// webdriver so the build proceeds quickly; runtime usage that needs a
183+
// real driver will fail later when executed, but this avoids long
184+
// download timeouts in CI.
185+
if std::env::var("GITHUB_ACTIONS").is_ok() {
186+
println!("cargo:warning=webdriver download failed in CI: {e:?}; creating stub webdriver at {webdriver_bin:?}");
187+
// create an empty executable file as a stub
188+
if let Err(ioe) = std::fs::write(&webdriver_bin, b"#!/bin/sh\necho stub") {
189+
return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("Failed to write stub webdriver: {ioe:?}")).into());
190+
}
191+
#[cfg(unix)]
192+
{
193+
use std::os::unix::fs::PermissionsExt;
194+
let mut perms = std::fs::metadata(&webdriver_bin)?.permissions();
195+
perms.set_mode(0o755);
196+
std::fs::set_permissions(&webdriver_bin, perms)?;
197+
}
198+
} else {
199+
return Err(anyhow!("Failed to download and install chromedriver").context(e));
200+
}
201+
}
182202
}
183203
GECKODRIVER_NAME => {
184204
let driver_info = GeckodriverInfo::new(webdriver_bin.clone(), browser_path);
185-
runtime
186-
.block_on(async { download_with_retry(&driver_info, false, true, 1).await })
187-
.with_context(|| {
188-
format!("Failed to download and install {}", config.driver_name)
189-
})?;
205+
let dl_res = runtime
206+
.block_on(async { download_with_retry(&driver_info, false, true, 1).await });
207+
if let Err(e) = dl_res {
208+
if std::env::var("GITHUB_ACTIONS").is_ok() {
209+
println!("cargo:warning=webdriver download failed in CI: {e:?}; creating stub webdriver at {webdriver_bin:?}");
210+
if let Err(ioe) = std::fs::write(&webdriver_bin, b"#!/bin/sh\necho stub") {
211+
return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("Failed to write stub webdriver: {ioe:?}")).into());
212+
}
213+
#[cfg(unix)]
214+
{
215+
use std::os::unix::fs::PermissionsExt;
216+
let mut perms = std::fs::metadata(&webdriver_bin)?.permissions();
217+
perms.set_mode(0o755);
218+
std::fs::set_permissions(&webdriver_bin, perms)?;
219+
}
220+
} else {
221+
return Err(anyhow!("Failed to download and install geckodriver").context(e));
222+
}
223+
}
190224
}
191225
_ => return Err(anyhow!("Unsupported driver type: {}", config.driver_name)),
192226
}

0 commit comments

Comments
 (0)