Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(smdk): publish support for readme #4032

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions crates/smartmodule-development-kit/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,20 @@ 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 {
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()?;
Expand Down Expand Up @@ -101,7 +109,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)
Expand Down Expand Up @@ -170,7 +184,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)?;

Expand Down Expand Up @@ -202,7 +224,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()?
Expand All @@ -216,6 +238,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)?;

Expand Down
88 changes: 66 additions & 22 deletions tests/cli/smdk_smoke_tests/smdk-basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,12 +76,55 @@ 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
}

@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-readme-tests"
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
assert_output --partial 'Error: README file not found at "./README.md"'
assert_failure

# Packages with specified README
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)" {
LABEL=default
SMDK_SM_TYPE=filter
Expand Down Expand Up @@ -149,7 +193,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"
Expand Down Expand Up @@ -190,11 +234,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"]'
Expand All @@ -205,7 +249,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
Expand Down Expand Up @@ -240,7 +284,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"
Expand Down Expand Up @@ -281,7 +325,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"
Expand Down Expand Up @@ -324,7 +368,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"
Expand Down Expand Up @@ -364,7 +408,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"
Expand Down Expand Up @@ -399,7 +443,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"
Expand Down Expand Up @@ -434,7 +478,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"
Expand Down Expand Up @@ -506,7 +550,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"
Expand Down Expand Up @@ -546,7 +590,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"
Expand Down Expand Up @@ -587,7 +631,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"
Expand All @@ -602,7 +646,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
Expand Down Expand Up @@ -636,7 +680,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"
Expand Down Expand Up @@ -677,7 +721,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"
Expand Down Expand Up @@ -720,7 +764,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"
Expand Down Expand Up @@ -760,7 +804,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"
Expand Down Expand Up @@ -795,7 +839,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"
Expand Down Expand Up @@ -830,7 +874,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"
Expand Down Expand Up @@ -865,7 +909,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"
Expand Down
Loading