From 9e9895ef601f1f05fcbf97181b0bb2217d59974e Mon Sep 17 00:00:00 2001 From: Collins Muriuki Date: Thu, 21 Mar 2024 19:40:14 +0300 Subject: [PATCH] Merge remote-tracking branch 'holochain/develop' into add-clippy-and-fmt-checks-to-ci-workflow --- .github/workflows/test.yaml | 4 +- run_test.sh | 156 ++++++++++++++++--------- src/cli.rs | 12 +- src/scaffold/app/nix.rs | 18 ++- src/scaffold/entry_type.rs | 2 +- src/scaffold/entry_type/definitions.rs | 4 +- src/scaffold/entry_type/fields.rs | 2 +- src/scaffold/entry_type/integrity.rs | 2 +- src/scaffold/link_type.rs | 2 +- src/scaffold/link_type/integrity.rs | 2 +- src/scaffold/web_app.rs | 2 +- src/scaffold/zome/utils.rs | 5 +- 12 files changed, 142 insertions(+), 69 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index bb89d28da..f1faba224 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -49,7 +49,9 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - scope: [ hello_world ] + scope: + - hello_world + - holo_integration steps: - uses: actions/checkout@v4 diff --git a/run_test.sh b/run_test.sh index fe0dde06f..91b040008 100755 --- a/run_test.sh +++ b/run_test.sh @@ -10,93 +10,145 @@ SCOPE= # parse args while getopts ":t:s:" opt; do case $opt in - t) TEMPLATE_NAME="$OPTARG";; - s) SCOPE="$OPTARG";; - \?) echo "Invalid option: -$OPTARG" >&2 - exit 1;; - :) echo "Option -$OPTARG requires an argument." >&2 - exit 1;; + t) TEMPLATE_NAME="$OPTARG" ;; + s) SCOPE="$OPTARG" ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; esac done cleanup_tmp() { - rm -rf $TEMPLATE_PATH/$1 + rm -rf "${TEMPLATE_PATH:?}/$1" } print_version() { - echo $(hc-scaffold --version) + echo "$(hc-scaffold --version)" } setup_and_build_happ() { - print_version - cleanup_tmp $1 - - cd $TEMPLATE_PATH - hc-scaffold --template $2 web-app $1 --setup-nix true - cd $1 - - hc-scaffold dna forum - hc-scaffold zome posts --integrity dnas/forum/zomes/integrity/ --coordinator dnas/forum/zomes/coordinator/ - hc-scaffold entry-type post --reference-entry-hash false --crud crud --link-from-original-to-each-update true --fields title:String:TextField,content:String:TextArea - hc-scaffold entry-type comment --reference-entry-hash false --crud crud --link-from-original-to-each-update false --fields post_hash:ActionHash::Post - hc-scaffold entry-type like --reference-entry-hash false --crud crd --fields like_hash:Option\::Like,string_list:Vec\ - hc-scaffold entry-type certificate --reference-entry-hash true --crud cr --fields post_hash:ActionHash::Post,agent:AgentPubKey::certified,certifications_hashes:Vec\::Certificate,certificate_type:Enum::CertificateType:TypeOne.TypeTwo,dna_hash:DnaHash - - hc-scaffold collection global all_posts post - hc-scaffold collection by-author posts_by_author post - hc-scaffold collection global all_likes like - hc-scaffold collection global all_posts_entry_hash post:EntryHash - hc-scaffold collection by-author posts_by_author_entry_hash post:EntryHash - - hc-scaffold link-type post like --delete true --bidirectional false - hc-scaffold link-type comment like:EntryHash --delete true --bidirectional true - hc-scaffold link-type certificate:EntryHash like --delete false --bidirectional false - hc-scaffold link-type agent:creator post:EntryHash --delete false --bidirectional true - - nix develop --command bash -c " + print_version + cleanup_tmp "$1" + + cd $TEMPLATE_PATH + hc-scaffold --template "$2" web-app "$1" --setup-nix true + cd "$1" + + hc-scaffold dna forum + hc-scaffold zome posts --integrity dnas/forum/zomes/integrity/ --coordinator dnas/forum/zomes/coordinator/ + hc-scaffold entry-type post --reference-entry-hash false --crud crud --link-from-original-to-each-update true --fields title:String:TextField,content:String:TextArea + hc-scaffold entry-type comment --reference-entry-hash false --crud crud --link-from-original-to-each-update false --fields post_hash:ActionHash::Post + hc-scaffold entry-type like --reference-entry-hash false --crud crd --fields like_hash:Option\::Like,string_list:Vec\ + hc-scaffold entry-type certificate --reference-entry-hash true --crud cr --fields post_hash:ActionHash::Post,agent:AgentPubKey::certified,certifications_hashes:Vec\::Certificate,certificate_type:Enum::CertificateType:TypeOne.TypeTwo,dna_hash:DnaHash + + hc-scaffold collection global all_posts post + hc-scaffold collection by-author posts_by_author post + hc-scaffold collection global all_likes like + hc-scaffold collection global all_posts_entry_hash post:EntryHash + hc-scaffold collection by-author posts_by_author_entry_hash post:EntryHash + + hc-scaffold link-type post like --delete true --bidirectional false + hc-scaffold link-type comment like:EntryHash --delete true --bidirectional true + hc-scaffold link-type certificate:EntryHash like --delete false --bidirectional false + hc-scaffold link-type agent:creator post:EntryHash --delete false --bidirectional true + + nix develop --command bash -c " set -e npm i npm run build -w ui npm t npm run package " - cd .. + cd .. } setup_and_build_hello_world() { - print_version - cleanup_tmp hello-world + print_version + cleanup_tmp hello-world - cd $TEMPLATE_PATH - hc-scaffold --template vanilla example hello-world - cd hello-world + cd $TEMPLATE_PATH + hc-scaffold --template vanilla example hello-world + cd hello-world - nix develop --command bash -c " + nix develop --command bash -c " set -e npm i npm t " - cd .. + cd .. } -if [[ -n "$SCOPE" && "$SCOPE" == "hello_world" ]]; then - setup_and_build_hello_world - exit 0 # Exit early +if [[ -n "$SCOPE" ]]; then + + case "$SCOPE" in + "hello_world") + setup_and_build_hello_world + ;; + "holo_integration") + rm -rf /tmp/holo-flake + cd /tmp + + hc-scaffold --template vue web-app holo-flake --setup-nix true + cd holo-flake + + nix develop --command bash -c " + set -e + # Check if holo-dev-server is in the path + if command -v holo-dev-server >/dev/null 2>&1; then + echo 'holo-dev-server is available in the PATH while it should not' + exit 1 + else + echo 'holo-dev-server is NOT available in the PATH' + fi + " + + rm -rf /tmp/holo-flake + cd /tmp + + hc-scaffold --template vue web-app holo-flake --setup-nix true --holo + cd holo-flake + + nix develop --command bash -c " + set -e + # Check if holo-dev-server is in the path + if command -v holo-dev-server >/dev/null 2>&1; then + echo 'holo-dev-server is available in the PATH' + else + echo 'holo-dev-server is NOT available in the PATH' + exit 1 + fi + " + + rm -rf /tmp/holo-flake + cd /tmp + ;; + *) + echo "Error: SCOPE must be one of 'hello_world', 'holo_integration', but got $SCOPE." + exit 1 + ;; + esac + + exit 0 # Exit early fi if [[ -z "$APP_NAME" || -z "$TEMPLATE_NAME" ]]; then - echo "Error: APP_NAME and TEMPLATE_NAME environment variables must be set." - exit 1 + echo "Error: APP_NAME and TEMPLATE_NAME environment variables must be set." + exit 1 fi case "$TEMPLATE_NAME" in "svelte" | "lit" | "vue" | "vanilla") - # Valid template name, proceed - ;; + # Valid template name, proceed + ;; *) - echo "Error: TEMPLATE_NAME must be one of 'svelte', 'lit', 'vue', or 'vanilla'." - exit 1 - ;; + echo "Error: TEMPLATE_NAME must be one of 'svelte', 'lit', 'vue', or 'vanilla'." + exit 1 + ;; esac cleanup_tmp "$APP_NAME" diff --git a/src/cli.rs b/src/cli.rs index 078ed37ef..02ffa78f6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -196,6 +196,9 @@ pub enum HcScaffoldCommand { Example { /// Name of the example to scaffold. One of ['hello-world', 'forum']. example: Option, + + #[structopt(long = "holo", hidden = true)] + holo_enabled: bool, }, } @@ -675,7 +678,10 @@ Collection "{}" scaffolded! println!("{}", i); } } - HcScaffoldCommand::Example { example } => { + HcScaffoldCommand::Example { + example, + holo_enabled, + } => { let example = match example { Some(e) => e, None => choose_example()?, @@ -696,7 +702,7 @@ Collection "{}" scaffolded! Some(String::from("A simple 'hello world' application.")), false, &template_file_tree, - false, + holo_enabled, )?; file_tree @@ -708,7 +714,7 @@ Collection "{}" scaffolded! Some(String::from("A simple 'forum' application.")), false, &template_file_tree, - false, + holo_enabled, )?; // scaffold dna hello_world diff --git a/src/scaffold/app/nix.rs b/src/scaffold/app/nix.rs index 31977a78a..06ea31d3f 100644 --- a/src/scaffold/app/nix.rs +++ b/src/scaffold/app/nix.rs @@ -9,8 +9,22 @@ use crate::error::{ScaffoldError, ScaffoldResult}; use crate::file_tree::*; use crate::versions::holochain_nix_version; -pub fn flake_nix() -> FileTree { +#[allow(clippy::obfuscated_if_else)] +pub fn flake_nix(holo_enabled: bool) -> FileTree { let holochain_nix_version = holochain_nix_version(); + + let holo_inputs = holo_enabled + .then_some( + r#" + hds-releases.url = "github:holo-host/hds-releases"; + "#, + ) + .unwrap_or(""); + + let holo_packages = holo_enabled + .then_some("inputs'.hds-releases.packages.holo-dev-server-bin") + .unwrap_or(""); + file!(format!( r#"{{ description = "Template for Holochain app development"; @@ -23,6 +37,7 @@ pub fn flake_nix() -> FileTree { nixpkgs.follows = "holochain-flake/nixpkgs"; flake-parts.follows = "holochain-flake/flake-parts"; + {holo_inputs} }}; outputs = inputs: @@ -43,6 +58,7 @@ pub fn flake_nix() -> FileTree { inputsFrom = [ inputs'.holochain-flake.devShells.holonix ]; packages = [ pkgs.nodejs_20 + {holo_packages} # more packages go here ]; }}; diff --git a/src/scaffold/entry_type.rs b/src/scaffold/entry_type.rs index e4332cea4..df15c5a52 100644 --- a/src/scaffold/entry_type.rs +++ b/src/scaffold/entry_type.rs @@ -176,7 +176,7 @@ pub fn scaffold_entry_type( let coordinator_zomes_for_integrity = get_coordinator_zomes_for_integrity( &zome_file_tree.dna_file_tree.dna_manifest, - &zome_file_tree.zome_manifest.name.0.to_string(), + zome_file_tree.zome_manifest.name.0.as_ref(), ); let coordinator_zome = match coordinator_zomes_for_integrity.len() { diff --git a/src/scaffold/entry_type/definitions.rs b/src/scaffold/entry_type/definitions.rs index da161726d..2e154ffec 100644 --- a/src/scaffold/entry_type/definitions.rs +++ b/src/scaffold/entry_type/definitions.rs @@ -229,7 +229,7 @@ impl EntryTypeReference { pub fn parse_entry_type_reference(s: &str) -> ScaffoldResult { let sp: Vec<&str> = s.split(':').collect(); - check_case(&sp[0].to_string(), "entry type reference", Case::Snake)?; + check_case(sp[0], "entry type reference", Case::Snake)?; let reference_entry_hash = match sp.len() { 0 | 1 => false, @@ -269,7 +269,7 @@ impl Serialize for Referenceable { pub fn parse_referenceable(s: &str) -> ScaffoldResult { let sp: Vec<&str> = s.split(':').collect(); - check_case(&sp[0].to_string(), "referenceable", Case::Snake)?; + check_case(sp[0], "referenceable", Case::Snake)?; Ok(match sp[0] { "agent" => match sp.len() { diff --git a/src/scaffold/entry_type/fields.rs b/src/scaffold/entry_type/fields.rs index 449beb3b5..723ca1aca 100644 --- a/src/scaffold/entry_type/fields.rs +++ b/src/scaffold/entry_type/fields.rs @@ -199,7 +199,7 @@ pub fn choose_field( if !input.is_case(Case::Pascal) { return Err(format!("Input must be {:?} case.", Case::Pascal)); } - if &input.to_ascii_lowercase() == entry_type_name { + if input.to_ascii_lowercase() == entry_type_name { return Err(format!( "Enum name: {input} conflicts with entry-type name: {entry_type_name}" )); diff --git a/src/scaffold/entry_type/integrity.rs b/src/scaffold/entry_type/integrity.rs index a3f115c77..6beaf5d4e 100644 --- a/src/scaffold/entry_type/integrity.rs +++ b/src/scaffold/entry_type/integrity.rs @@ -483,7 +483,7 @@ pub fn get_all_entry_types( let coordinators_for_zome = get_coordinator_zomes_for_integrity( &zome_file_tree.dna_file_tree.dna_manifest, - &zome_file_tree.zome_manifest.name.0.to_string(), + zome_file_tree.zome_manifest.name.0.as_ref(), ); let mut entry_types: Vec = Vec::new(); diff --git a/src/scaffold/link_type.rs b/src/scaffold/link_type.rs index 160de0ba3..1c46f0084 100644 --- a/src/scaffold/link_type.rs +++ b/src/scaffold/link_type.rs @@ -155,7 +155,7 @@ pub use {}::*; let coordinator_zomes_for_integrity = get_coordinator_zomes_for_integrity( &zome_file_tree.dna_file_tree.dna_manifest, - &zome_file_tree.zome_manifest.name.0.to_string(), + zome_file_tree.zome_manifest.name.0.as_ref(), ); let coordinator_zome = match coordinator_zomes_for_integrity.len() { diff --git a/src/scaffold/link_type/integrity.rs b/src/scaffold/link_type/integrity.rs index f148deeda..78254a19a 100644 --- a/src/scaffold/link_type/integrity.rs +++ b/src/scaffold/link_type/integrity.rs @@ -307,7 +307,7 @@ pub fn add_link_type_to_integrity_zome( let coordinator_zomes_for_integrity = get_coordinator_zomes_for_integrity( &dna_manifest, - &zome_file_tree.zome_manifest.name.0.to_string(), + zome_file_tree.zome_manifest.name.0.as_ref(), ); for coordinator_zome in coordinator_zomes_for_integrity { diff --git a/src/scaffold/web_app.rs b/src/scaffold/web_app.rs index 2df67217d..3120de47d 100644 --- a/src/scaffold/web_app.rs +++ b/src/scaffold/web_app.rs @@ -39,7 +39,7 @@ fn web_app_skeleton( app_file_tree .dir_content_mut() .ok_or(ScaffoldError::PathNotFound(PathBuf::new()))? - .insert(OsString::from("flake.nix"), flake_nix()); + .insert(OsString::from("flake.nix"), flake_nix(holo_enabled)); } let mut scaffold_template_result = diff --git a/src/scaffold/zome/utils.rs b/src/scaffold/zome/utils.rs index 1b62e7732..e30bca813 100644 --- a/src/scaffold/zome/utils.rs +++ b/src/scaffold/zome/utils.rs @@ -24,10 +24,7 @@ pub fn select_integrity_zomes( return Ok(vec![]); } - let prompt = match prompt { - Some(p) => p, - None => "Select integrity zome (SPACE to select/unselect):", - }; + let prompt = prompt.unwrap_or("Select integrity zome (SPACE to select/unselect):"); let selected_options = MultiSelect::with_theme(&ColorfulTheme::default()) .with_prompt(prompt)