#ci #xtask #distribution #bundle #cicero #path #file-path

build cicero_distribution

Bundle distribution files in CI code

3 releases (breaking)

new 0.3.0 Feb 9, 2025
0.2.0 Feb 1, 2025
0.1.0 Sep 7, 2024

#523 in Build Utils

Download history 4/week @ 2024-10-30 4/week @ 2024-11-06 1/week @ 2024-11-13 1/week @ 2024-12-04 1/week @ 2024-12-11 115/week @ 2025-01-29 133/week @ 2025-02-05

248 downloads per month
Used in cicero

Apache-2.0

29KB
411 lines

Unstable: Cicero Distibution

Need to pack multiple files into an archive?
Cicero provides an API for specifying the file structure and then deferring to your functions to provide the contents:

use std::{fs, path::Path};
use cicero_distribution::Distribution;
use cicero_path::repo_path;

fn main() -> anyhow::Result<()> {
    let distribution = Distribution::new("myproject")?;

    distribution
        .add_file_from_path("README.md", repo_path!("README.md"))?
        .add_file("myproject", |file| build_backend_executable(file))?;

    distribution
        .dir("public")?
        .add_all(|dir| build_frontend(dir))?;

    let archive_path = distribution.bundle_as_tar_gz()?;
    Ok(())
}

fn build_frontend(out_dir: &Path) -> anyhow::Result<()> {
    let build_out_dir: &Path = unimplemented!();
    fs::rename(build_out_dir, out_dir)?;
    Ok(())
}

fn build_backend_executable(out_file: &Path) -> anyhow::Result<()> {
    let build_out_file: &Path = unimplemented!();
    fs::rename(build_out_file, out_file)?;
    Ok(())
}

Advantages to this approach:

  1. File structure is documented and trivially correct.
  2. Conflicts due to two code locations modifying the same files are practically eliminated.
  3. Obvious where to jump into the code to change a portion of the distribution.
  4. Less path wrangling. Your function has the complete path passed to it. No need to modify it further.
  5. Your functions become naturally testable. You can pass a temporary path (e.g. from assert_fs) instead and assert on that.

Mind that this API may still see larger changes, as more features are implemented.

Dependencies

~0.7–9.5MB
~107K SLoC