Skip to content

Commit

Permalink
test: add cargo xtask spec to configure bootc.spec
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaofeng Wang <[email protected]>
  • Loading branch information
henrywang committed Jul 3, 2024
1 parent f2de4ce commit 8d51287
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
16 changes: 5 additions & 11 deletions .packit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@ srpm_build_deps:

actions:
create-archive:
- bash -c "sed -i \"s/0.1/${PACKIT_PROJECT_VERSION}/\" contrib/packaging/bootc.spec"
- bash -c "mkdir -p target/man"
- bash -c "cargo run --features=docgen -- man --directory target/man"
- bash -c "git archive --format=tar --prefix=bootc-${PACKIT_PROJECT_VERSION}/ HEAD > contrib/packaging/${PACKIT_PROJECT_NAME_VERSION}.tar"
- bash -c "tar -r -C target -f contrib/packaging/${PACKIT_PROJECT_NAME_VERSION}.tar man"
- bash -c "cargo install cargo-vendor-filterer"
- bash -c "cargo vendor-filterer --prefix=vendor --format=tar contrib/packaging/${PACKIT_PROJECT_NAME_VERSION}-vendor.tar"
- bash -c "cat contrib/packaging/bootc.spec"
- bash -c "ls -1 contrib/packaging/${PACKIT_PROJECT_NAME_VERSION}.tar"
- bash -c "cargo xtask spec"
- bash -c "cat target/bootc.spec"
- bash -c "cp target/bootc* contrib/packaging/"
- bash -c "ls -1 target/bootc*.tar.zstd | grep -v 'vendor'"
fix-spec-file:
- bash -c "echo $PACKIT_RPMSPEC_RELEASE $PACKIT_PROJECT_VERSION $PACKIT_PROJECT_COMMIT $PACKIT_PROJECT_ARCHIVE"
- bash -c "sed -i \"s/https.*}.tar.zstd/${PACKIT_PROJECT_NAME_VERSION}.tar/\" contrib/packaging/bootc.spec"
- bash -c "sed -i \"s/https.*}-vendor.tar.zstd/${PACKIT_PROJECT_NAME_VERSION}-vendor.tar/\" contrib/packaging/bootc.spec"
- bash -c "cat contrib/packaging/bootc.spec"
- bash -c "ls -al contrib/packaging/"

jobs:
- job: copr_build
Expand Down
36 changes: 36 additions & 0 deletions xtask/src/xtask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const TASKS: &[(&str, fn(&Shell) -> Result<()>)] = &[
("man2markdown", man2markdown),
("package", package),
("package-srpm", package_srpm),
("spec", spec),
("custom-lints", custom_lints),
("test-tmt", test_tmt),
];
Expand Down Expand Up @@ -244,6 +245,41 @@ fn package(sh: &Shell) -> Result<()> {
Ok(())
}

fn update_spec(sh: &Shell) -> Result<Utf8PathBuf> {
let p = Utf8Path::new("target");
let pkg = impl_package(sh)?;
let srcpath = pkg.srcpath.file_name().unwrap();
let v = pkg.version;
let src_vendorpath = pkg.vendorpath.file_name().unwrap();
{
let specin = File::open(format!("contrib/packaging/{NAME}.spec"))
.map(BufReader::new)
.context("Opening spec")?;
let mut o = File::create(p.join(format!("{NAME}.spec"))).map(BufWriter::new)?;
for line in specin.lines() {
let line = line?;
if line.starts_with("Version:") {
writeln!(o, "# Replaced by cargo xtask spec")?;
writeln!(o, "Version: {v}")?;
} else if line.starts_with("Source0") {
writeln!(o, "Source0: {srcpath}")?;
} else if line.starts_with("Source1") {
writeln!(o, "Source1: {src_vendorpath}")?;
} else {
writeln!(o, "{}", line)?;
}
}
}
let spec_path = p.join(format!("{NAME}.spec"));
Ok(spec_path)
}

fn spec(sh: &Shell) -> Result<()> {
let s = update_spec(sh)?;
println!("Generated: {s}");
Ok(())
}

fn impl_srpm(sh: &Shell) -> Result<Utf8PathBuf> {
{
let _g = sh.push_dir("target");
Expand Down

0 comments on commit 8d51287

Please sign in to comment.