From 9553870be49d78466246da1a7755d3c3aedef7fb Mon Sep 17 00:00:00 2001 From: Esteban Borai Date: Mon, 27 May 2024 10:05:23 -0400 Subject: [PATCH 1/3] feat(smdk): publish support for readme --- .../src/publish.rs | 29 ++++++++-- tests/cli/smdk_smoke_tests/smdk-basic.bats | 54 +++++++++++-------- 2 files changed, 58 insertions(+), 25 deletions(-) diff --git a/crates/smartmodule-development-kit/src/publish.rs b/crates/smartmodule-development-kit/src/publish.rs index 3cc9f1823c..9987dde73a 100644 --- a/crates/smartmodule-development-kit/src/publish.rs +++ b/crates/smartmodule-development-kit/src/publish.rs @@ -47,6 +47,10 @@ pub struct PublishCmd { #[arg(long, env=ENV_SMDK_NOWASI, hide_short_help = true)] nowasi: bool, + + /// Relative path to this connector package README + #[clap(long, default_value = "./README.md")] + readme: PathBuf, } impl PublishCmd { @@ -101,7 +105,13 @@ impl PublishCmd { Self::cleanup(&hubdir)?; - init_package_template(&package_info, self.nowasi)?; + init_package_template( + &package_info, + &InitPackageTemplateOptions { + readme: &self.readme, + nowasi: self.nowasi, + }, + )?; check_package_meta_visiblity(&package_info)?; Ok(hubdir) @@ -170,7 +180,15 @@ pub fn package_push(opts: &PublishCmd, pkgpath: &str, access: &HubAccess) -> Res Ok(()) } -pub fn init_package_template(package_info: &PackageInfo, nowasi: bool) -> Result<()> { +pub struct InitPackageTemplateOptions<'a> { + pub nowasi: bool, + pub readme: &'a PathBuf, +} + +pub fn init_package_template( + package_info: &PackageInfo, + options: &InitPackageTemplateOptions, +) -> Result<()> { let sm_toml_path = find_smartmodule_toml(package_info)?; let sm_metadata = SmartModuleMetadata::from_toml(&sm_toml_path)?; @@ -202,7 +220,7 @@ pub fn init_package_template(package_info: &PackageInfo, nowasi: bool) -> Result })?, ); - let wasmpath = if nowasi { + let wasmpath = if options.nowasi { package_info.target_wasm32_path()? } else { package_info.target_wasm32_wasi_path()? @@ -216,6 +234,11 @@ pub fn init_package_template(package_info: &PackageInfo, nowasi: bool) -> Result })?, ); + let readme_path = options.readme.canonicalize()?; + let readme_md_relative_path = package_meta_relative_path(&package_meta_path, &readme_path); + pm.manifest + .push(readme_md_relative_path.unwrap_or_else(|| readme_path.to_string_lossy().to_string())); + println!("Creating package {}", pm.pkg_name()); pm.write(&package_meta_path)?; diff --git a/tests/cli/smdk_smoke_tests/smdk-basic.bats b/tests/cli/smdk_smoke_tests/smdk-basic.bats index 178bd79c95..af92f2e57f 100644 --- a/tests/cli/smdk_smoke_tests/smdk-basic.bats +++ b/tests/cli/smdk_smoke_tests/smdk-basic.bats @@ -75,10 +75,20 @@ smdk_via_stdin() { # Package without existing package-meta run $SMDK_BIN publish --pack assert_success - + # Package with package-meta created before run $SMDK_BIN publish --pack assert_success + + # Validates SmartModule Exists + run $SMDK_BIN publish --pack --readme ./README.md + assert_line --index 0 "Error: No such file or directory (os error 2)" + assert_failure + + # Packages with specified README + echo "# My SmartModule" > README.md + run $SMDK_BIN publish --pack --readme ./README.md + assert_success } @test "Generate and test filter - (stable fluvio-smartmodule / no params)" { @@ -149,7 +159,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -190,11 +200,11 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" - assert_success + assert_success # Test with verbose run $SMDK_BIN test --verbose --text '["foo", "bar"]' @@ -205,7 +215,7 @@ smdk_via_stdin() { # Test without verbose run $SMDK_BIN test --text '["foo", "bar"]' - refute_output --partial "2 records outputed" + refute_output --partial "2 records outputed" assert_output --partial "foo" assert_output --partial "bar" assert_success @@ -240,7 +250,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -281,7 +291,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -324,7 +334,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -364,7 +374,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -399,7 +409,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -434,7 +444,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -506,7 +516,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -546,7 +556,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -587,7 +597,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -602,7 +612,7 @@ smdk_via_stdin() { # Test with without verbose run smdk_via_stdin '["foo", "bar"]' - refute_output --partial "2 records outputed" + refute_output --partial "2 records outputed" assert_output --partial "foo" assert_output --partial "bar" assert_success @@ -636,7 +646,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -677,7 +687,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -720,7 +730,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -760,7 +770,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -795,7 +805,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -830,7 +840,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" @@ -865,7 +875,7 @@ smdk_via_stdin() { cd $SM_PACKAGE_NAME run $SMDK_BIN build refute_output --partial "could not compile" - + # Load run $SMDK_BIN load assert_output --partial "Creating SmartModule: $SM_PACKAGE_NAME" From 830d6ee3fce75136060ae3b7b2e15c3016ddbcf5 Mon Sep 17 00:00:00 2001 From: Esteban Borai Date: Tue, 28 May 2024 16:56:49 -0400 Subject: [PATCH 2/3] fix: use correct paths --- .../src/publish.rs | 4 ++ tests/cli/smdk_smoke_tests/smdk-basic.bats | 42 +++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/crates/smartmodule-development-kit/src/publish.rs b/crates/smartmodule-development-kit/src/publish.rs index 9987dde73a..df431b8162 100644 --- a/crates/smartmodule-development-kit/src/publish.rs +++ b/crates/smartmodule-development-kit/src/publish.rs @@ -57,6 +57,10 @@ impl PublishCmd { pub(crate) fn process(&self) -> Result<()> { let access = HubAccess::default_load(&self.remote)?; + if !self.readme.exists() { + return Err(anyhow!("README file not found at {:?}", self.readme)); + } + match (self.pack, self.push) { (false, false) | (true, true) => { let hubdir = self.run_in_cargo_project()?; diff --git a/tests/cli/smdk_smoke_tests/smdk-basic.bats b/tests/cli/smdk_smoke_tests/smdk-basic.bats index af92f2e57f..c352cad3f2 100644 --- a/tests/cli/smdk_smoke_tests/smdk-basic.bats +++ b/tests/cli/smdk_smoke_tests/smdk-basic.bats @@ -23,6 +23,7 @@ setup_file() { # Create a workspace to facilitate dependency sharing between test cases SMs cd $TEST_DIR echo '[workspace]' > Cargo.toml + echo 'resolver = "2"' >> Cargo.toml echo >> Cargo.toml echo 'members = [' >> Cargo.toml echo ']' >> Cargo.toml @@ -79,16 +80,49 @@ smdk_via_stdin() { # Package with package-meta created before run $SMDK_BIN publish --pack assert_success +} + +@test "Package with README" { + LABEL=package + SMDK_SM_TYPE=filter + PARAMS_FLAG=--no-params + SM_CRATE_PATH_FLAG= + SM_PACKAGE_NAME=$LABEL-$SMDK_SM_TYPE-$PROJECT_NAME_PREFIX + SMDK_SM_PUBLIC=false + + # Add SM to workspace + cd $TEST_DIR + sed -i -e $'/members/a\\\n "'$SM_PACKAGE_NAME'",' Cargo.toml + + # Generate + run $SMDK_BIN generate \ + $PARAMS_FLAG \ + $SM_CRATE_PATH_FLAG \ + $TESTING_GROUP_NAME_FLAG \ + --sm-type $SMDK_SM_TYPE \ + --sm-public $SMDK_SM_PUBLIC \ + --silent \ + $SM_PACKAGE_NAME + assert_success + + # Build + cd $SM_PACKAGE_NAME + run $SMDK_BIN build + refute_output --partial "could not compile" + + # Remove README from Template on Purpose + rm "$TEST_DIR/$SM_PACKAGE_NAME/README.md" # Validates SmartModule Exists - run $SMDK_BIN publish --pack --readme ./README.md - assert_line --index 0 "Error: No such file or directory (os error 2)" + run $SMDK_BIN publish --pack + assert_output --partial 'Error: README file not found at "./README.md"' assert_failure # Packages with specified README - echo "# My SmartModule" > README.md - run $SMDK_BIN publish --pack --readme ./README.md + echo "# My SmartModule" > "$TEST_DIR/$SM_PACKAGE_NAME/README.md" + run $SMDK_BIN publish --pack assert_success + } @test "Generate and test filter - (stable fluvio-smartmodule / no params)" { From 7a0827a823e999ecc6bace1c2e9876d4c6c93809 Mon Sep 17 00:00:00 2001 From: Esteban Borai Date: Tue, 28 May 2024 18:46:56 -0400 Subject: [PATCH 3/3] chore: extend name --- tests/cli/smdk_smoke_tests/smdk-basic.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli/smdk_smoke_tests/smdk-basic.bats b/tests/cli/smdk_smoke_tests/smdk-basic.bats index c352cad3f2..97b01f150a 100644 --- a/tests/cli/smdk_smoke_tests/smdk-basic.bats +++ b/tests/cli/smdk_smoke_tests/smdk-basic.bats @@ -87,7 +87,7 @@ smdk_via_stdin() { SMDK_SM_TYPE=filter PARAMS_FLAG=--no-params SM_CRATE_PATH_FLAG= - SM_PACKAGE_NAME=$LABEL-$SMDK_SM_TYPE-$PROJECT_NAME_PREFIX + SM_PACKAGE_NAME="$LABEL-$SMDK_SM_TYPE-$PROJECT_NAME_PREFIX-readme-tests" SMDK_SM_PUBLIC=false # Add SM to workspace