Skip to content

Commit

Permalink
Merge remote-tracking branch 'holochain/develop' into add-clippy-and-…
Browse files Browse the repository at this point in the history
…fmt-checks-to-ci-workflow
  • Loading branch information
c12i committed Mar 21, 2024
1 parent 345f4c7 commit 9e9895e
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 69 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
scope: [ hello_world ]
scope:
- hello_world
- holo_integration
steps:
- uses: actions/checkout@v4

Expand Down
156 changes: 104 additions & 52 deletions run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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\<ActionHash\>::Like,string_list:Vec\<String\>
hc-scaffold entry-type certificate --reference-entry-hash true --crud cr --fields post_hash:ActionHash::Post,agent:AgentPubKey::certified,certifications_hashes:Vec\<EntryHash\>::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\<ActionHash\>::Like,string_list:Vec\<String\>
hc-scaffold entry-type certificate --reference-entry-hash true --crud cr --fields post_hash:ActionHash::Post,agent:AgentPubKey::certified,certifications_hashes:Vec\<EntryHash\>::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"
Expand Down
12 changes: 9 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ pub enum HcScaffoldCommand {
Example {
/// Name of the example to scaffold. One of ['hello-world', 'forum'].
example: Option<Example>,

#[structopt(long = "holo", hidden = true)]
holo_enabled: bool,
},
}

Expand Down Expand Up @@ -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()?,
Expand All @@ -696,7 +702,7 @@ Collection "{}" scaffolded!
Some(String::from("A simple 'hello world' application.")),
false,
&template_file_tree,
false,
holo_enabled,
)?;

file_tree
Expand All @@ -708,7 +714,7 @@ Collection "{}" scaffolded!
Some(String::from("A simple 'forum' application.")),
false,
&template_file_tree,
false,
holo_enabled,
)?;

// scaffold dna hello_world
Expand Down
18 changes: 17 additions & 1 deletion src/scaffold/app/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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:
Expand All @@ -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
];
}};
Expand Down
2 changes: 1 addition & 1 deletion src/scaffold/entry_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/scaffold/entry_type/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl EntryTypeReference {

pub fn parse_entry_type_reference(s: &str) -> ScaffoldResult<EntryTypeReference> {
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,
Expand Down Expand Up @@ -269,7 +269,7 @@ impl Serialize for Referenceable {
pub fn parse_referenceable(s: &str) -> ScaffoldResult<Referenceable> {
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() {
Expand Down
2 changes: 1 addition & 1 deletion src/scaffold/entry_type/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
));
Expand Down
2 changes: 1 addition & 1 deletion src/scaffold/entry_type/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntryTypeReference> = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion src/scaffold/link_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/scaffold/link_type/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/scaffold/web_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
5 changes: 1 addition & 4 deletions src/scaffold/zome/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9e9895e

Please sign in to comment.