From a78548415cb467ac701d9ca354b82c3e1c9560a6 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Wed, 25 Sep 2024 19:09:23 +0530 Subject: [PATCH 1/4] fix: zshScript Signed-off-by: Ayush Sharma --- scripts/zsh/keploy_record_script.zsh | 68 ++++++++++++++++++++-------- scripts/zsh/keploy_test_script.zsh | 59 ++++++++++++++++++++---- src/OneClickInstall.ts | 2 +- src/Record.ts | 4 +- src/Test.ts | 4 +- 5 files changed, 104 insertions(+), 33 deletions(-) diff --git a/scripts/zsh/keploy_record_script.zsh b/scripts/zsh/keploy_record_script.zsh index c452ae9..5bc5a58 100755 --- a/scripts/zsh/keploy_record_script.zsh +++ b/scripts/zsh/keploy_record_script.zsh @@ -1,53 +1,85 @@ #!/bin/zsh -i -echo "Executing keploy_record_script.zsh" - -folderpath="$2" log_file_path="$1" -# Command is all of the CLI args after the 2nd arg -command="${@:3}" +# Extract command from keploy.yml +keploy_config="keploy.yml" +if [[ ! -f "$keploy_config" ]]; then + echo "keploy.yml file not found in the current directory." + exit 1 +fi + +command=$(awk '/command:/ { $1=""; sub(/^ /, ""); print }' "$keploy_config") +# echo "Command in yml file: $command" + +# Check if command is empty +if [[ -z "$command" ]]; then + echo "Command is not specified in keploy.yml." + exit 1 +fi # Create log file if it doesn't exist touch "$log_file_path" -> "$log_file_path" # Clear the log file +: > "$log_file_path" # Clear the log file # Set permissions of the log file chmod 666 "$log_file_path" -echo "Command: $command" - if [[ "$command" =~ .*"go".* ]]; then - # echo "Go is present." go mod download go build -o application -fi -# Adding sudo here worked -keploycmd="sudo -E env PATH=\"$PATH\" keploy" +elif [[ "$command" =~ .*"python3".* ]]; then + # echo "Python3 command found" + python3 -m venv venv + # echo "venv created" + source venv/bin/activate + # echo "venv activated" + pip install -r requirements.txt + # echo "requirements installed" + +elif [[ "$command" =~ .*"python".* ]] ; then +# echo "Python command found" + python -m venv venv + # echo "venv created" + source venv/bin/activate + # echo "venv activated" + pip install -r requirements.txt + # echo "requirements installed" + +elif [[ "$command" =~ .*"node".* ]]; then + npm install -cd "$folderpath" +elif [[ "$command" =~ .*"java".* ]] || [[ "$command" =~ .*"mvn".* ]]; then + mvn clean install +fi # Create a named pipe fifo=$(mktemp -u) mkfifo "$fifo" # Background process to read from the named pipe and write to the log file -(cat "$fifo" | tee -a "$log_file_path") & +cat "$fifo" | tee -a "$log_file_path" & cat_pid=$! # Dummy background process to keep the parent script running (while true; do sleep 1; done) & dummy_pid=$! -# Execute the keploy command, redirecting output to the named pipe -# echo $keploycmd record -c "$command" -sudo $keploycmd record -c "$command" > "$fifo" 2>&1 +# Check if running on WSL +if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then + sudo -E env "PATH=$PATH" keploy record > "$fifo" 2>&1 +else + keploycmd="sudo -E env PATH=\"$PATH\" keploy" + $keploycmd record > "$fifo" 2>&1 +fi # Clean up: Wait for keploy command to finish wait $! +touch ./log_file.txt + # Terminate the dummy process and the logging process kill $dummy_pid wait $cat_pid -rm "$fifo" +rm "$fifo" \ No newline at end of file diff --git a/scripts/zsh/keploy_test_script.zsh b/scripts/zsh/keploy_test_script.zsh index 73b5f6e..21f6147 100755 --- a/scripts/zsh/keploy_test_script.zsh +++ b/scripts/zsh/keploy_test_script.zsh @@ -1,26 +1,65 @@ #!/bin/zsh -i -folderpath="$2" log_file_path="$1" -# Command is all of the CLI args after the 2nd arg -command="${@:3}" - # Create log file if it doesn't exist touch "$log_file_path" -> "$log_file_path" # Clear the log file +: > "$log_file_path" # Clear the log file # Set permissions of the log file chmod 666 "$log_file_path" -if [ "$command" = *go* ]; then -# echo "Go is present." +# Extract the command from keploy.yml +command=$(awk -F: '/command:/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' keploy.yml) +# echo "Command in yml file: $command" + +# echo "Command in yml file: $command" +if [[ "$command" =~ .*"go".* ]]; then + # echo "Go is present." go mod download go build -o application + +elif [[ "$command" =~ .*"python3".* ]]; then + # echo "Python 3 is present, Activating Virtual Environment 🐍" + python3 -m venv venv + source venv/bin/activate + # echo 'Installing requirements 📦' + pip install -r requirements.txt + # echo 'Test Mode Starting 🎉' + +elif [[ "$command" =~ .*"python".* ]] ; then + # echo "Python is present, Activating Virtual Environment 🐍" + python -m venv venv + source venv/bin/activate + # echo 'Installing requirements 📦' + pip install -r requirements.txt + # echo 'Test Mode Starting 🎉' + +elif [[ "$command" =~ .*"node".* ]]; then + # echo "Node is present." + npm install + +elif [[ "$command" =~ .*"java".* ]] || [[ "$command" =~ .*"mvn".* ]]; then + # echo "Java is present." + mvn clean install + fi -keploycmd="sudo -E env PATH=\"$PATH\" keploy" +# Check if running on WSL +if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then + # echo "Running on WSL" + # Temporarily modify PATH + sudo -E env "PATH=$PATH" keploy test | tee -a "$log_file_path" +else + # echo "Not running on WSL" + # Original PATH handling + keploycmd="sudo -E env PATH=\"$PATH\" keploy" + sudo $keploycmd test | tee -a "$log_file_path" +fi + +# echo "Keploy command: $keploycmd" -cd "$folderpath" +# cd "$folderpath" -sudo $keploycmd test -c "$command" | tee -a "$log_file_path" +# Execute the keploy command and append the output to the log file +touch ./log_file.txt \ No newline at end of file diff --git a/src/OneClickInstall.ts b/src/OneClickInstall.ts index a90ed86..c6b47d8 100644 --- a/src/OneClickInstall.ts +++ b/src/OneClickInstall.ts @@ -5,7 +5,7 @@ export default function executeKeployOneClickCommand(): void { const checkKeployExistsCommand = `keploy`; // The command to download and install Keploy - const installationCommand = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && bash /tmp/install.sh -noRoot -platform bash`; + const installationCommand = `curl --silent -L https://keploy.io/install.sh -o /tmp/install.sh && chmod +x /tmp/install.sh && /tmp/install.sh -noRoot`; exec(checkKeployExistsCommand, (error, stdout, stderr) => { if (error) { // Execute the installation command diff --git a/src/Record.ts b/src/Record.ts index 7b7c865..03a488e 100644 --- a/src/Record.ts +++ b/src/Record.ts @@ -105,7 +105,7 @@ export async function startRecording( wslscriptPath: string, wsllogfilePath: str console.log(`Current default shell: ${currentShell}`); //uncomment the below line if you want to use the default shell (for zsh test) - // terminalPath = currentShell; + terminalPath = currentShell; } console.log(`Terminal path: ${terminalPath}`); const terminal = vscode.window.createTerminal({ @@ -121,7 +121,7 @@ export async function startRecording( wslscriptPath: string, wsllogfilePath: str if (currentShell.includes('zsh')) { // Use a Zsh-specific script if needed //replace bashScriptPath with zshScriptPath for zsh - recordCmd = `"${bashScriptPath}" "${logfilePath}" `; + recordCmd = `"${zshScriptPath}" "${logfilePath}" ;exit 0`; } else { // Default to Bash script recordCmd = `"${bashScriptPath}" "${logfilePath}" ;exit 0`; diff --git a/src/Test.ts b/src/Test.ts index 6c5d78d..236fb98 100644 --- a/src/Test.ts +++ b/src/Test.ts @@ -319,7 +319,7 @@ export async function startTesting(wslscriptPath: string, wsllogfilePath: string console.log(`Current default shell: ${currentShell}`); //uncomment the below line if you want to use the default shell (for zsh test) - // terminalPath = currentShell; + terminalPath = currentShell; } console.log(`Terminal path: ${terminalPath}`); const terminal = vscode.window.createTerminal({ @@ -338,7 +338,7 @@ export async function startTesting(wslscriptPath: string, wsllogfilePath: string // Use a Zsh-specific script if needed console.log('Using Zsh script'); //replace bashScriptPath with zshScriptPath for zsh - testCmd = `"${bashScriptPath}" "${logfilePath}"; exit 0`; + testCmd = `"${zshScriptPath}" "${logfilePath}"; exit 0`; } else { // Default to Bash script testCmd = `"${bashScriptPath}" "${logfilePath}" ; exit 0`; From f05e7b57978e167e571ca78a7e4e9b7a31f90ecc Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 26 Sep 2024 11:32:42 +0530 Subject: [PATCH 2/4] removed comments Signed-off-by: Ayush Sharma --- scripts/bash/keploy_record_script.sh | 13 ------------- scripts/bash/keploy_test_script.sh | 25 +------------------------ scripts/zsh/keploy_record_script.zsh | 13 +------------ scripts/zsh/keploy_test_script.zsh | 24 +----------------------- 4 files changed, 3 insertions(+), 72 deletions(-) diff --git a/scripts/bash/keploy_record_script.sh b/scripts/bash/keploy_record_script.sh index f48d389..01a2ebc 100755 --- a/scripts/bash/keploy_record_script.sh +++ b/scripts/bash/keploy_record_script.sh @@ -1,6 +1,5 @@ #!/bin/bash -i -# folderpath="$2" log_file_path="$1" # Extract command from keploy.yml @@ -11,9 +10,7 @@ if [[ ! -f "$keploy_config" ]]; then fi command=$(awk '/command:/ { $1=""; sub(/^ /, ""); print }' "$keploy_config") -# echo "Command in yml file: $command" -# Check if command is empty if [[ -z "$command" ]]; then echo "Command is not specified in keploy.yml." exit 1 @@ -31,22 +28,14 @@ if [[ "$command" =~ .*"go".* ]]; then go build -o application elif [[ "$command" =~ .*"python3".* ]]; then - # echo "Python3 command found" python3 -m venv venv - # echo "venv created" source venv/bin/activate - # echo "venv activated" pip install -r requirements.txt - # echo "requirements installed" elif [[ "$command" =~ .*"python".* ]] ; then -# echo "Python command found" python -m venv venv - # echo "venv created" source venv/bin/activate - # echo "venv activated" pip install -r requirements.txt - # echo "requirements installed" elif [[ "$command" =~ .*"node".* ]]; then npm install @@ -80,9 +69,7 @@ sudo -E $keploycmd record > "$fifo" 2>&1 # Clean up: Wait for keploy command to finish wait $! -touch ./log_file.txt - # Terminate the dummy process and the logging process kill $dummy_pid wait $cat_pid diff --git a/scripts/bash/keploy_test_script.sh b/scripts/bash/keploy_test_script.sh index d824ef6..fa4e618 100755 --- a/scripts/bash/keploy_test_script.sh +++ b/scripts/bash/keploy_test_script.sh @@ -1,6 +1,5 @@ #!/bin/bash -i -# folderpath="$2" log_file_path="$1" # Create log file if it doesn't exist @@ -12,57 +11,35 @@ chmod 666 "$log_file_path" # Extract the command from keploy.yml command=$(awk -F: '/command:/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' keploy.yml) -# echo "Command in yml file: $command" -# echo "Command in yml file: $command" if [[ "$command" =~ .*"go".* ]]; then - # echo "Go is present." go mod download go build -o application elif [[ "$command" =~ .*"python3".* ]]; then - # echo "Python 3 is present, Activating Virtual Environment 🐍" python3 -m venv venv source venv/bin/activate - # echo 'Installing requirements 📦' pip install -r requirements.txt - # echo 'Test Mode Starting 🎉' elif [[ "$command" =~ .*"python".* ]] ; then - # echo "Python is present, Activating Virtual Environment 🐍" python -m venv venv source venv/bin/activate - # echo 'Installing requirements 📦' pip install -r requirements.txt - # echo 'Test Mode Starting 🎉' elif [[ "$command" =~ .*"node".* ]]; then - # echo "Node is present." npm install elif [[ "$command" =~ .*"java".* ]] || [[ "$command" =~ .*"mvn".* ]]; then - # echo "Java is present." mvn clean install - fi # Check if running on WSL if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then - # echo "Running on WSL" - # Temporarily modify PATH export PATH=$(echo "$PATH" | tr ' ' '\n' | grep -v " " | tr '\n' ':') keploycmd="sudo -E keploy" else - # echo "Not running on WSL" - # Original PATH handling keploycmd="sudo -E env PATH=\"$PATH\" keploy" fi -# echo "Keploy command: $keploycmd" - -# cd "$folderpath" - # Execute the keploy command and append the output to the log file -sudo $keploycmd test | tee -a "$log_file_path" -touch ./log_file.txt - +sudo $keploycmd test | tee -a "$log_file_path" \ No newline at end of file diff --git a/scripts/zsh/keploy_record_script.zsh b/scripts/zsh/keploy_record_script.zsh index 5bc5a58..8467721 100755 --- a/scripts/zsh/keploy_record_script.zsh +++ b/scripts/zsh/keploy_record_script.zsh @@ -10,7 +10,6 @@ if [[ ! -f "$keploy_config" ]]; then fi command=$(awk '/command:/ { $1=""; sub(/^ /, ""); print }' "$keploy_config") -# echo "Command in yml file: $command" # Check if command is empty if [[ -z "$command" ]]; then @@ -30,22 +29,14 @@ if [[ "$command" =~ .*"go".* ]]; then go build -o application elif [[ "$command" =~ .*"python3".* ]]; then - # echo "Python3 command found" python3 -m venv venv - # echo "venv created" source venv/bin/activate - # echo "venv activated" pip install -r requirements.txt - # echo "requirements installed" elif [[ "$command" =~ .*"python".* ]] ; then -# echo "Python command found" python -m venv venv - # echo "venv created" source venv/bin/activate - # echo "venv activated" pip install -r requirements.txt - # echo "requirements installed" elif [[ "$command" =~ .*"node".* ]]; then npm install @@ -75,9 +66,7 @@ else fi # Clean up: Wait for keploy command to finish -wait $! -touch ./log_file.txt - +wait $! # Terminate the dummy process and the logging process kill $dummy_pid diff --git a/scripts/zsh/keploy_test_script.zsh b/scripts/zsh/keploy_test_script.zsh index 21f6147..2bb8ca9 100755 --- a/scripts/zsh/keploy_test_script.zsh +++ b/scripts/zsh/keploy_test_script.zsh @@ -11,55 +11,33 @@ chmod 666 "$log_file_path" # Extract the command from keploy.yml command=$(awk -F: '/command:/ {gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' keploy.yml) -# echo "Command in yml file: $command" -# echo "Command in yml file: $command" if [[ "$command" =~ .*"go".* ]]; then - # echo "Go is present." go mod download go build -o application elif [[ "$command" =~ .*"python3".* ]]; then - # echo "Python 3 is present, Activating Virtual Environment 🐍" python3 -m venv venv source venv/bin/activate - # echo 'Installing requirements 📦' pip install -r requirements.txt - # echo 'Test Mode Starting 🎉' elif [[ "$command" =~ .*"python".* ]] ; then - # echo "Python is present, Activating Virtual Environment 🐍" python -m venv venv source venv/bin/activate - # echo 'Installing requirements 📦' pip install -r requirements.txt - # echo 'Test Mode Starting 🎉' elif [[ "$command" =~ .*"node".* ]]; then - # echo "Node is present." npm install elif [[ "$command" =~ .*"java".* ]] || [[ "$command" =~ .*"mvn".* ]]; then - # echo "Java is present." mvn clean install fi # Check if running on WSL if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then - # echo "Running on WSL" - # Temporarily modify PATH sudo -E env "PATH=$PATH" keploy test | tee -a "$log_file_path" else - # echo "Not running on WSL" - # Original PATH handling keploycmd="sudo -E env PATH=\"$PATH\" keploy" sudo $keploycmd test | tee -a "$log_file_path" -fi - -# echo "Keploy command: $keploycmd" - -# cd "$folderpath" - -# Execute the keploy command and append the output to the log file -touch ./log_file.txt \ No newline at end of file +fi \ No newline at end of file From 6437493959398a690d48f48c0c038a7f129eae6a Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 26 Sep 2024 13:26:42 +0530 Subject: [PATCH 3/4] fixed scripts Signed-off-by: Ayush Sharma --- scripts/bash/keploy_record_script.sh | 2 +- scripts/bash/keploy_test_script.sh | 2 +- .../zsh/{keploy_record_script.zsh => keploy_record_script.sh} | 4 ++-- scripts/zsh/{keploy_test_script.zsh => keploy_test_script.sh} | 4 ++-- src/SidebarProvider.ts | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) rename scripts/zsh/{keploy_record_script.zsh => keploy_record_script.sh} (97%) rename scripts/zsh/{keploy_test_script.zsh => keploy_test_script.sh} (94%) diff --git a/scripts/bash/keploy_record_script.sh b/scripts/bash/keploy_record_script.sh index 01a2ebc..39914ab 100755 --- a/scripts/bash/keploy_record_script.sh +++ b/scripts/bash/keploy_record_script.sh @@ -47,7 +47,7 @@ fi # Check if running on WSL if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then export PATH=$(echo "$PATH" | tr ' ' '\n' | grep -v " " | tr '\n' ':') - keploycmd="sudo -E keploy" + keploycmd="sudo -E env PATH=\"$PATH\" keploy" else keploycmd="sudo -E env PATH=\"$PATH\" keploy" fi diff --git a/scripts/bash/keploy_test_script.sh b/scripts/bash/keploy_test_script.sh index fa4e618..da809d2 100755 --- a/scripts/bash/keploy_test_script.sh +++ b/scripts/bash/keploy_test_script.sh @@ -36,7 +36,7 @@ fi # Check if running on WSL if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then export PATH=$(echo "$PATH" | tr ' ' '\n' | grep -v " " | tr '\n' ':') - keploycmd="sudo -E keploy" + keploycmd="sudo -E env PATH=\"$PATH\" keploy" else keploycmd="sudo -E env PATH=\"$PATH\" keploy" fi diff --git a/scripts/zsh/keploy_record_script.zsh b/scripts/zsh/keploy_record_script.sh similarity index 97% rename from scripts/zsh/keploy_record_script.zsh rename to scripts/zsh/keploy_record_script.sh index 8467721..01b3284 100755 --- a/scripts/zsh/keploy_record_script.zsh +++ b/scripts/zsh/keploy_record_script.sh @@ -1,4 +1,4 @@ -#!/bin/zsh -i +#!/bin/zsh log_file_path="$1" @@ -62,7 +62,7 @@ if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then sudo -E env "PATH=$PATH" keploy record > "$fifo" 2>&1 else keploycmd="sudo -E env PATH=\"$PATH\" keploy" - $keploycmd record > "$fifo" 2>&1 + eval $keploycmd record > "$fifo" 2>&1 fi # Clean up: Wait for keploy command to finish diff --git a/scripts/zsh/keploy_test_script.zsh b/scripts/zsh/keploy_test_script.sh similarity index 94% rename from scripts/zsh/keploy_test_script.zsh rename to scripts/zsh/keploy_test_script.sh index 2bb8ca9..3fadf60 100755 --- a/scripts/zsh/keploy_test_script.zsh +++ b/scripts/zsh/keploy_test_script.sh @@ -1,4 +1,4 @@ -#!/bin/zsh -i +#!/bin/zsh log_file_path="$1" @@ -39,5 +39,5 @@ if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then sudo -E env "PATH=$PATH" keploy test | tee -a "$log_file_path" else keploycmd="sudo -E env PATH=\"$PATH\" keploy" - sudo $keploycmd test | tee -a "$log_file_path" + eval sudo $keploycmd test | tee -a "$log_file_path" fi \ No newline at end of file diff --git a/src/SidebarProvider.ts b/src/SidebarProvider.ts index 89353df..e2a2564 100644 --- a/src/SidebarProvider.ts +++ b/src/SidebarProvider.ts @@ -141,7 +141,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider { console.log('Start Recording button clicked'); const bashScript = vscode.Uri.joinPath(this._extensionUri, "scripts", "bash", "keploy_record_script.sh"); - const zshScript = vscode.Uri.joinPath(this._extensionUri, "scripts", "zsh", "keploy_record_script.zsh"); + const zshScript = vscode.Uri.joinPath(this._extensionUri, "scripts", "zsh", "keploy_record_script.sh"); const logfilePath = vscode.Uri.joinPath(this._extensionUri, "scripts", "logs", "record_mode.log"); let wslscriptPath = bashScript.fsPath; let wsllogPath = logfilePath.fsPath; @@ -190,7 +190,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider { try { console.log('Start Testing button clicked'); const bashScript = vscode.Uri.joinPath(this._extensionUri, "scripts", "bash", "keploy_test_script.sh"); - const zshScript = vscode.Uri.joinPath(this._extensionUri, "scripts", "zsh", "keploy_test_script.zsh"); + const zshScript = vscode.Uri.joinPath(this._extensionUri, "scripts", "zsh", "keploy_test_script.sh"); const logfilePath = vscode.Uri.joinPath(this._extensionUri, "scripts", "logs", "test_mode.log"); let wslscriptPath = bashScript.fsPath; let wsllogPath = logfilePath.fsPath; From 068acbfecdeb03a3df520e0b550ae99979518b2c Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Thu, 26 Sep 2024 17:24:47 +0530 Subject: [PATCH 4/4] removed sudo Signed-off-by: Ayush Sharma --- scripts/zsh/keploy_test_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/zsh/keploy_test_script.sh b/scripts/zsh/keploy_test_script.sh index 3fadf60..117cf18 100755 --- a/scripts/zsh/keploy_test_script.sh +++ b/scripts/zsh/keploy_test_script.sh @@ -39,5 +39,5 @@ if grep -qEi "(Microsoft|WSL)" /proc/version &> /dev/null ; then sudo -E env "PATH=$PATH" keploy test | tee -a "$log_file_path" else keploycmd="sudo -E env PATH=\"$PATH\" keploy" - eval sudo $keploycmd test | tee -a "$log_file_path" + eval $keploycmd test | tee -a "$log_file_path" fi \ No newline at end of file