diff --git a/src/executor/engine.rs b/src/executor/engine.rs index e6aa8cf..b99e32e 100644 --- a/src/executor/engine.rs +++ b/src/executor/engine.rs @@ -98,9 +98,6 @@ pub enum ExecutionError { #[error("Parse error: {0}")] ParseError(String), - #[error("Dependency error: {0}")] - DependencyError(String), - #[error("Runtime error: {0}")] RuntimeError(String), @@ -383,7 +380,7 @@ async fn execute_step( } } else { // For GitHub actions, check if we have special handling - if let Err(e) = handle_special_action(uses, &step.with).await { + if let Err(e) = handle_special_action(uses).await { // Log error but continue println!(" Warning: Special action handling failed: {}", e); } @@ -614,59 +611,3 @@ async fn prepare_runner_image( Ok(()) } - -async fn prepare_nix_container( - runtime: &Box, - verbose: bool, -) -> Result { - if verbose { - println!("🔧 Preparing specialized container for Nix workflow"); - } - - // Create a container that has Nix pre-installed - // We'll use a multi-step approach to create a Nix-enabled container - - // Step 1: Create a temporary Dockerfile for a Nix-enabled container - let temp_dir = tempfile::tempdir() - .map_err(|e| ExecutionError::ExecutionError(format!("Failed to create temp dir: {}", e)))?; - - let dockerfile_path = temp_dir.path().join("Dockerfile"); - let dockerfile_content = r#"FROM ubuntu:latest -RUN apt-get update && apt-get install -y curl xz-utils sudo -RUN adduser --disabled-password --gecos '' nix && \ - echo "nix ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/nix && \ - mkdir -p /nix && chown nix:nix /nix - -USER nix -RUN curl -L https://nixos.org/nix/install | sh -ENV PATH="/nix/var/nix/profiles/default/bin:${PATH}" -ENV NIX_PATH="nixpkgs=/nix/var/nix/profiles/per-user/nix/channels/nixpkgs" - -# Run nix once to verify it works -RUN nix --version - -WORKDIR /github/workspace -"#; - - std::fs::write(&dockerfile_path, dockerfile_content).map_err(|e| { - ExecutionError::ExecutionError(format!("Failed to write Dockerfile: {}", e)) - })?; - - // Step 2: Build the custom image - let nix_image_tag = format!("wrkflw-nix-{}", uuid::Uuid::new_v4()); - - if verbose { - println!("🔧 Building custom Nix-enabled image: {}", nix_image_tag); - } - - runtime - .build_image(&dockerfile_path, &nix_image_tag) - .await - .map_err(|e| ExecutionError::RuntimeError(format!("Failed to build Nix image: {}", e)))?; - - if verbose { - println!("✅ Successfully built Nix-enabled container image"); - } - - Ok(nix_image_tag) -} diff --git a/src/executor/environment.rs b/src/executor/environment.rs index 81ed39d..9ac4442 100644 --- a/src/executor/environment.rs +++ b/src/executor/environment.rs @@ -1,8 +1,6 @@ use crate::parser::workflow::WorkflowDefinition; use chrono::Utc; use std::collections::HashMap; -use std::path::{Path, PathBuf}; -use std::process::Command; pub fn create_github_context(workflow: &WorkflowDefinition) -> HashMap { let mut env = HashMap::new(); @@ -29,40 +27,6 @@ pub fn create_github_context(workflow: &WorkflowDefinition) -> HashMap HashMap { - let mut env = HashMap::new(); - - // Try to detect the git repository root - let repo_root = find_git_repo_root(workflow_dir); - - if let Some(repo_root) = repo_root { - // Set GITHUB_WORKSPACE to the git repo root - env.insert( - "GITHUB_WORKSPACE".to_string(), - repo_root.to_string_lossy().to_string(), - ); - - // Try to get current branch - if let Some(branch) = get_current_branch(&repo_root) { - env.insert("GITHUB_REF".to_string(), format!("refs/heads/{}", branch)); - env.insert("GITHUB_REF_NAME".to_string(), branch.clone()); - env.insert("GITHUB_HEAD_REF".to_string(), branch); - } - - // Try to get current commit SHA - if let Some(sha) = get_git_sha(&repo_root) { - env.insert("GITHUB_SHA".to_string(), sha); - } - - // Try to get repository name from remote origin - if let Some(repo) = get_repo_name_from_git(&repo_root) { - env.insert("GITHUB_REPOSITORY".to_string(), repo); - } - } - - env -} - fn get_repo_name() -> String { // Try to detect from git if available if let Ok(output) = std::process::Command::new("git") @@ -172,64 +136,3 @@ fn get_tool_cache_dir() -> String { .to_string_lossy() .to_string() } - -fn find_git_repo_root(start_dir: &Path) -> Option { - let mut current_dir = start_dir.to_path_buf(); - - loop { - let git_dir = current_dir.join(".git"); - if git_dir.exists() && git_dir.is_dir() { - return Some(current_dir); - } - - if !current_dir.pop() { - // Reached root directory without finding .git - return None; - } - } -} - -fn get_current_branch(repo_root: &Path) -> Option { - let output = Command::new("git") - .args(&["rev-parse", "--abbrev-ref", "HEAD"]) - .current_dir(repo_root) - .output(); - - match output { - Ok(output) if output.status.success() => { - let branch = String::from_utf8_lossy(&output.stdout).trim().to_string(); - Some(branch) - } - _ => None, - } -} - -fn get_git_sha(repo_root: &Path) -> Option { - let output = Command::new("git") - .args(&["rev-parse", "HEAD"]) - .current_dir(repo_root) - .output(); - - match output { - Ok(output) if output.status.success() => { - let sha = String::from_utf8_lossy(&output.stdout).trim().to_string(); - Some(sha) - } - _ => None, - } -} - -fn get_repo_name_from_git(repo_root: &Path) -> Option { - let output = Command::new("git") - .args(&["remote", "get-url", "origin"]) - .current_dir(repo_root) - .output(); - - match output { - Ok(output) if output.status.success() => { - let url = String::from_utf8_lossy(&output.stdout).trim().to_string(); - extract_repo_from_url(&url) - } - _ => None, - } -} diff --git a/src/parser/workflow.rs b/src/parser/workflow.rs index e7c7216..6461437 100644 --- a/src/parser/workflow.rs +++ b/src/parser/workflow.rs @@ -39,28 +39,11 @@ pub struct Step { } impl WorkflowDefinition { - fn default() -> Self { - WorkflowDefinition { - name: String::new(), - on: Vec::new(), - on_raw: serde_yaml::Value::Null, - jobs: HashMap::new(), - } - } - pub fn get_default_shell(&self) -> String { - // GitHub defaults to bash on Linux/macOS and PowerShell on Windows - if cfg!(windows) { - "powershell".to_string() - } else { - "bash".to_string() - } - } - pub fn resolve_action(&self, action_ref: &str) -> ActionInfo { // Parse GitHub action reference like "actions/checkout@v3" let parts: Vec<&str> = action_ref.split('@').collect(); - let (repo, version) = if parts.len() > 1 { + let (repo, _) = if parts.len() > 1 { (parts[0], parts[1]) } else { (parts[0], "main") // Default to main if no version specified @@ -68,7 +51,6 @@ impl WorkflowDefinition { ActionInfo { repository: repo.to_string(), - version: version.to_string(), is_docker: repo.starts_with("docker://"), is_local: repo.starts_with("./"), } @@ -78,7 +60,6 @@ impl WorkflowDefinition { #[derive(Debug, Clone)] pub struct ActionInfo { pub repository: String, - pub version: String, pub is_docker: bool, pub is_local: bool, } diff --git a/src/runtime/emulation.rs b/src/runtime/emulation.rs index b1c07e1..48f5d1a 100644 --- a/src/runtime/emulation.rs +++ b/src/runtime/emulation.rs @@ -1,6 +1,5 @@ use crate::runtime::container::{ContainerError, ContainerOutput, ContainerRuntime}; use async_trait::async_trait; -use std::collections::HashMap; use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; @@ -19,7 +18,7 @@ impl EmulationRuntime { EmulationRuntime { workspace } } - fn prepare_workspace(&self, working_dir: &Path, volumes: &[(&Path, &Path)]) -> PathBuf { + fn prepare_workspace(&self, _working_dir: &Path, volumes: &[(&Path, &Path)]) -> PathBuf { // Get the container root - this is the emulation workspace directory let container_root = self.workspace.path().to_path_buf(); @@ -265,10 +264,7 @@ fn copy_directory_contents(source: &Path, dest: &Path) -> std::io::Result<()> { Ok(()) } -pub async fn handle_special_action( - action: &str, - with_params: &Option>, -) -> Result<(), ContainerError> { +pub async fn handle_special_action(action: &str) -> Result<(), ContainerError> { if action.starts_with("cachix/install-nix-action") { println!("🔄 Emulating cachix/install-nix-action"); diff --git a/src/ui.rs b/src/ui.rs index 4a0f181..a281584 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -462,102 +462,3 @@ fn print_execution_results(result: &ExecutionResult) { ); } } - -// Display detailed logs for a specific job -pub fn view_job_logs(job_name: &str, logs: &str) { - println!("\n{} {}", "Job Logs:".bold().blue(), job_name.underline()); - println!("{}", "=".repeat(60)); - - // Split logs by step section markers and print with formatting - let sections: Vec<&str> = logs.split("\n## Step:").collect(); - - if sections.is_empty() { - println!("{}", logs); - } else { - for (i, section) in sections.iter().enumerate() { - if i == 0 && section.trim().is_empty() { - continue; - } - - if i == 0 { - // This is pre-step output - println!("{}", section); - } else { - // This is a step section - let lines: Vec<&str> = section.lines().collect(); - if !lines.is_empty() { - println!(" {}", lines[0].bold()); // Step name - - for line in &lines[1..] { - println!(" {}", line); - } - - println!(); - } - } - } - } - - println!("{}", "=".repeat(60)); -} - -// Function to prompt for user input with a message -pub fn prompt_for_input(message: &str) -> String { - use std::io::{self, Write}; - - print!("{}: ", message); - io::stdout().flush().unwrap(); - - let mut input = String::new(); - io::stdin().read_line(&mut input).unwrap(); - - input.trim().to_string() -} - -// Function to show progress for long-running operations -pub fn show_progress(message: &str, total: usize) -> ProgressBar { - println!("{} {}", "⏳".bold(), message); - ProgressBar::new(total) -} - -// Simple progress bar implementation -pub struct ProgressBar { - total: usize, - current: usize, -} - -impl ProgressBar { - pub fn new(total: usize) -> Self { - ProgressBar { total, current: 0 } - } - - pub fn increment(&mut self, amount: usize) { - self.current += amount; - self.current = self.current.min(self.total); - self.display(); - } - - pub fn display(&self) { - use std::io::{self, Write}; - - let width = 30; - let progress = (self.current as f32 / self.total as f32 * width as f32) as usize; - let bar = "█".repeat(progress) + &"░".repeat(width - progress); - let percentage = (self.current as f32 / self.total as f32 * 100.0) as usize; - - print!( - "\r[{}] {}% ({}/{})", - bar, percentage, self.current, self.total - ); - io::stdout().flush().unwrap(); - - if self.current == self.total { - println!(); - } - } - - pub fn complete(&mut self) { - self.current = self.total; - self.display(); - } -}