Skip to content

Commit

Permalink
build(pd): fail if asset zipfiles aren't complete
Browse files Browse the repository at this point in the history
Updates the build.rs file for pd to error out if the frontend asset
bundles are incomplete, by checking for a small filesize. That isn't a
super durable method, but it's a cheap check and easy to update in the
future.

Closes #4703.
  • Loading branch information
conorsch committed Aug 6, 2024
1 parent 0c812ff commit 027df2a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions crates/bin/pd/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
use std::io::Read;
use std::path::Path;

use anyhow::Context;

fn main() -> anyhow::Result<()> {
check_frontend_asset_zipfiles()?;
setup_testnet_config()?;
Ok(())
}

// Check that the zip files for bundled frontend code are functional.
// If git-lfs is not configured on the build host, the zip files will
// be plaintext lfs pointer files.
fn check_frontend_asset_zipfiles() -> anyhow::Result<()> {
// Declare a minimum filesize, below which we'll assume the zip file is
// actually a git-lfs pointer.
const MINIMUM_FILESIZE_BYTES: usize = 500;
// Build paths to the zip files in the local build env.
let zipfiles = vec![
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../assets/minifront.zip"),
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../../assets/node-status.zip"),
];
for zipfile in zipfiles {
let mut bytes = Vec::new();
let f = std::fs::File::open(&zipfile).context(format!(
"failed to open zip file of frontend code: {}",
&zipfile.display()
))?;
let mut reader = std::io::BufReader::new(f);
reader.read_to_end(&mut bytes).context(format!(
"failed to read zip file of frontend code: {}",
zipfile.display()
))?;
if bytes.len() < MINIMUM_FILESIZE_BYTES {
anyhow::bail!(
format!(
"asset zip file {} is smaller than {} bytes; install git-lfs, run 'git lfs pull', and retry the build",
zipfile.display(),
MINIMUM_FILESIZE_BYTES
)
);
}
}
Ok(())
}

// Set build-time environment variables to point to the latest testnet's config files.
fn setup_testnet_config() -> anyhow::Result<()> {
// Get the path to the testnets directory, in a platform-agnostic manner
Expand Down

0 comments on commit 027df2a

Please sign in to comment.