diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fa20eb3..0aed001 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,38 +2,30 @@ # This pipeline will build and test the Rust project stages: - - lint - build - test - - release + - deploy variables: - CARGO_HOME: ${CI_PROJECT_DIR}/.cargo - RUST_VERSION: stable + RUST_VERSION: "1.70.0" + CARGO_TERM_COLOR: always -# Cache dependencies between jobs +# Cache settings cache: + key: "$CI_COMMIT_REF_SLUG" paths: - - .cargo/ - target/ + script: + - echo "This is a placeholder - the cache directive doesn't need a script" # Lint job - runs rustfmt and clippy lint: - stage: lint + stage: test image: rust:${RUST_VERSION} script: - - rustup component add rustfmt clippy - - cargo fmt -- --check + - rustup component add clippy - cargo clippy -- -D warnings - rules: - - if: $CI_PIPELINE_SOURCE == "web" - when: always - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - when: always - - if: $CI_COMMIT_TAG - when: never - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - when: always + allow_failure: true # Build job - builds the application build: @@ -43,17 +35,8 @@ build: - cargo build --verbose artifacts: paths: - - target/debug/wrkflw + - target/debug expire_in: 1 week - rules: - - if: $CI_PIPELINE_SOURCE == "web" - when: always - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - when: always - - if: $CI_COMMIT_TAG - when: always - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - when: always # Test job - runs unit and integration tests test: @@ -61,21 +44,12 @@ test: image: rust:${RUST_VERSION} script: - cargo test --verbose - needs: + dependencies: - build - rules: - - if: $CI_PIPELINE_SOURCE == "web" - when: always - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - when: always - - if: $CI_COMMIT_TAG - when: always - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - when: always # Release job - creates a release build release: - stage: release + stage: deploy image: rust:${RUST_VERSION} script: - cargo build --release --verbose @@ -92,16 +66,35 @@ release: # Custom job for documentation docs: - stage: release + stage: deploy image: rust:${RUST_VERSION} script: - cargo doc --no-deps + - mkdir -p public + - cp -r target/doc/* public/ artifacts: paths: - - target/doc/ - rules: - - if: $CI_PIPELINE_SOURCE == "web" && $BUILD_DOCS == "true" - when: always - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH - when: always - - when: never \ No newline at end of file + - public + only: + - main + +format: + stage: test + image: rust:${RUST_VERSION} + script: + - rustup component add rustfmt + - cargo fmt --check + allow_failure: true + +pages: + stage: deploy + image: rust:${RUST_VERSION} + script: + - cargo doc --no-deps + - mkdir -p public + - cp -r target/doc/* public/ + artifacts: + paths: + - public + only: + - main \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 5b889ce..8be13da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1506,6 +1506,8 @@ dependencies = [ "serde", "serde_json", "serde_yaml", + "tempfile", + "thiserror", ] [[package]] @@ -1768,6 +1770,15 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "schannel" version = "0.1.27" @@ -2323,6 +2334,16 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -2444,6 +2465,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -2688,6 +2718,7 @@ dependencies = [ "utils", "uuid", "validators", + "walkdir", ] [[package]] diff --git a/crates/executor/src/engine.rs b/crates/executor/src/engine.rs index 3219493..89072f5 100644 --- a/crates/executor/src/engine.rs +++ b/crates/executor/src/engine.rs @@ -13,6 +13,8 @@ use crate::docker; use crate::environment; use logging; use matrix::MatrixCombination; +use models::gitlab::Pipeline; +use parser::gitlab::{self, parse_pipeline}; use parser::workflow::{self, parse_workflow, ActionInfo, Job, WorkflowDefinition}; use runtime::container::ContainerRuntime; use runtime::emulation; @@ -27,6 +29,51 @@ pub async fn execute_workflow( logging::info(&format!("Executing workflow: {}", workflow_path.display())); logging::info(&format!("Runtime: {:?}", runtime_type)); + // Determine if this is a GitLab CI/CD pipeline or GitHub Actions workflow + let is_gitlab = is_gitlab_pipeline(workflow_path); + + if is_gitlab { + execute_gitlab_pipeline(workflow_path, runtime_type, verbose).await + } else { + execute_github_workflow(workflow_path, runtime_type, verbose).await + } +} + +/// Determine if a file is a GitLab CI/CD pipeline +fn is_gitlab_pipeline(path: &Path) -> bool { + // Check the file name + if let Some(file_name) = path.file_name() { + if let Some(file_name_str) = file_name.to_str() { + return file_name_str == ".gitlab-ci.yml" || file_name_str.ends_with("gitlab-ci.yml"); + } + } + + // If file name check fails, try to read and determine by content + if let Ok(content) = fs::read_to_string(path) { + // GitLab CI/CD pipelines typically have stages, before_script, after_script at the top level + if content.contains("stages:") + || content.contains("before_script:") + || content.contains("after_script:") + { + // Check for GitHub Actions specific keys that would indicate it's not GitLab + if !content.contains("on:") + && !content.contains("runs-on:") + && !content.contains("uses:") + { + return true; + } + } + } + + false +} + +/// Execute a GitHub Actions workflow file locally +async fn execute_github_workflow( + workflow_path: &Path, + runtime_type: RuntimeType, + verbose: bool, +) -> Result { // 1. Parse workflow file let workflow = parse_workflow(workflow_path)?; @@ -113,6 +160,192 @@ pub async fn execute_workflow( }) } +/// Execute a GitLab CI/CD pipeline locally +async fn execute_gitlab_pipeline( + pipeline_path: &Path, + runtime_type: RuntimeType, + verbose: bool, +) -> Result { + logging::info("Executing GitLab CI/CD pipeline"); + + // 1. Parse the GitLab pipeline file + let pipeline = parse_pipeline(pipeline_path) + .map_err(|e| ExecutionError::Parse(format!("Failed to parse GitLab pipeline: {}", e)))?; + + // 2. Convert the GitLab pipeline to a format compatible with the workflow executor + let workflow = gitlab::convert_to_workflow_format(&pipeline); + + // 3. Resolve job dependencies based on stages + let execution_plan = resolve_gitlab_dependencies(&pipeline, &workflow)?; + + // 4. Initialize appropriate runtime + let runtime = initialize_runtime(runtime_type.clone())?; + + // Create a temporary workspace directory + let workspace_dir = tempfile::tempdir() + .map_err(|e| ExecutionError::Execution(format!("Failed to create workspace: {}", e)))?; + + // 5. Set up GitLab-like environment + let mut env_context = create_gitlab_context(&pipeline, workspace_dir.path()); + + // Add runtime mode to environment + env_context.insert( + "WRKFLW_RUNTIME_MODE".to_string(), + if runtime_type == RuntimeType::Emulation { + "emulation".to_string() + } else { + "docker".to_string() + }, + ); + + // Setup environment files + environment::setup_github_environment_files(workspace_dir.path()).map_err(|e| { + ExecutionError::Execution(format!("Failed to setup environment files: {}", e)) + })?; + + // 6. Execute jobs according to the plan + let mut results = Vec::new(); + let mut has_failures = false; + let mut failure_details = String::new(); + + for job_batch in execution_plan { + // Execute jobs in parallel if they don't depend on each other + let job_results = execute_job_batch( + &job_batch, + &workflow, + runtime.as_ref(), + &env_context, + verbose, + ) + .await?; + + // Check for job failures and collect details + for job_result in &job_results { + if job_result.status == JobStatus::Failure { + has_failures = true; + failure_details.push_str(&format!("\n❌ Job failed: {}\n", job_result.name)); + + // Add step details for failed jobs + for step in &job_result.steps { + if step.status == StepStatus::Failure { + failure_details.push_str(&format!(" ❌ {}: {}\n", step.name, step.output)); + } + } + } + } + + results.extend(job_results); + } + + // If there were failures, add detailed failure information to the result + if has_failures { + logging::error(&format!("Pipeline execution failed:{}", failure_details)); + } + + Ok(ExecutionResult { + jobs: results, + failure_details: if has_failures { + Some(failure_details) + } else { + None + }, + }) +} + +/// Create an environment context for GitLab CI/CD pipeline execution +fn create_gitlab_context(pipeline: &Pipeline, workspace_dir: &Path) -> HashMap { + let mut env_context = HashMap::new(); + + // Add GitLab CI/CD environment variables + env_context.insert("CI".to_string(), "true".to_string()); + env_context.insert("GITLAB_CI".to_string(), "true".to_string()); + + // Add custom environment variable to indicate use in wrkflw + env_context.insert("WRKFLW_CI".to_string(), "true".to_string()); + + // Add workspace directory + env_context.insert( + "CI_PROJECT_DIR".to_string(), + workspace_dir.to_string_lossy().to_string(), + ); + + // Add global variables from the pipeline + if let Some(variables) = &pipeline.variables { + for (key, value) in variables { + env_context.insert(key.clone(), value.clone()); + } + } + + env_context +} + +/// Resolve GitLab CI/CD pipeline dependencies +fn resolve_gitlab_dependencies( + pipeline: &Pipeline, + workflow: &WorkflowDefinition, +) -> Result>, ExecutionError> { + // For GitLab CI/CD pipelines, jobs within the same stage can run in parallel, + // but jobs in different stages run sequentially + + // Get stages from the pipeline or create a default one + let stages = match &pipeline.stages { + Some(defined_stages) => defined_stages.clone(), + None => vec![ + "build".to_string(), + "test".to_string(), + "deploy".to_string(), + ], + }; + + // Create an execution plan based on stages + let mut execution_plan = Vec::new(); + + // For each stage, collect the jobs that belong to it + for stage in stages { + let mut stage_jobs = Vec::new(); + + for (job_name, job) in &pipeline.jobs { + // Skip template jobs + if let Some(true) = job.template { + continue; + } + + // Get the job's stage, or assume "test" if not specified + let default_stage = "test".to_string(); + let job_stage = job.stage.as_ref().unwrap_or(&default_stage); + + // If the job belongs to the current stage, add it to the batch + if job_stage == &stage { + stage_jobs.push(job_name.clone()); + } + } + + if !stage_jobs.is_empty() { + execution_plan.push(stage_jobs); + } + } + + // Also create a batch for jobs without a stage + let mut stageless_jobs = Vec::new(); + + for (job_name, job) in &pipeline.jobs { + // Skip template jobs + if let Some(true) = job.template { + continue; + } + + if job.stage.is_none() { + stageless_jobs.push(job_name.clone()); + } + } + + if !stageless_jobs.is_empty() { + execution_plan.push(stageless_jobs); + } + + Ok(execution_plan) +} + // Determine if Docker is available or fall back to emulation fn initialize_runtime( runtime_type: RuntimeType, @@ -1425,7 +1658,12 @@ async fn execute_step(ctx: StepExecutionContext<'_>) -> Result, + + /// Global variables available to all jobs + #[serde(skip_serializing_if = "Option::is_none")] + pub variables: Option>, + + /// Pipeline stages in execution order + #[serde(skip_serializing_if = "Option::is_none")] + pub stages: Option>, + + /// Default before_script for all jobs + #[serde(skip_serializing_if = "Option::is_none")] + pub before_script: Option>, + + /// Default after_script for all jobs + #[serde(skip_serializing_if = "Option::is_none")] + pub after_script: Option>, + + /// Job definitions (name => job) + #[serde(flatten)] + pub jobs: HashMap, + + /// Workflow rules for the pipeline + #[serde(skip_serializing_if = "Option::is_none")] + pub workflow: Option, + + /// Includes for pipeline configuration + #[serde(skip_serializing_if = "Option::is_none")] + pub include: Option>, + } + + /// A job in a GitLab CI/CD pipeline + #[derive(Debug, Serialize, Deserialize, Clone)] + pub struct Job { + /// The stage this job belongs to + #[serde(skip_serializing_if = "Option::is_none")] + pub stage: Option, + + /// Docker image to use for this job + #[serde(skip_serializing_if = "Option::is_none")] + pub image: Option, + + /// Script commands to run + #[serde(skip_serializing_if = "Option::is_none")] + pub script: Option>, + + /// Commands to run before the main script + #[serde(skip_serializing_if = "Option::is_none")] + pub before_script: Option>, + + /// Commands to run after the main script + #[serde(skip_serializing_if = "Option::is_none")] + pub after_script: Option>, + + /// When to run the job (on_success, on_failure, always, manual) + #[serde(skip_serializing_if = "Option::is_none")] + pub when: Option, + + /// Allow job failure + #[serde(skip_serializing_if = "Option::is_none")] + pub allow_failure: Option, + + /// Services to run alongside the job + #[serde(skip_serializing_if = "Option::is_none")] + pub services: Option>, + + /// Tags to define which runners can execute this job + #[serde(skip_serializing_if = "Option::is_none")] + pub tags: Option>, + + /// Job-specific variables + #[serde(skip_serializing_if = "Option::is_none")] + pub variables: Option>, + + /// Job dependencies + #[serde(skip_serializing_if = "Option::is_none")] + pub dependencies: Option>, + + /// Artifacts to store after job execution + #[serde(skip_serializing_if = "Option::is_none")] + pub artifacts: Option, + + /// Cache configuration + #[serde(skip_serializing_if = "Option::is_none")] + pub cache: Option, + + /// Rules for when this job should run + #[serde(skip_serializing_if = "Option::is_none")] + pub rules: Option>, + + /// Only run on specified refs + #[serde(skip_serializing_if = "Option::is_none")] + pub only: Option, + + /// Exclude specified refs + #[serde(skip_serializing_if = "Option::is_none")] + pub except: Option, + + /// Retry configuration + #[serde(skip_serializing_if = "Option::is_none")] + pub retry: Option, + + /// Timeout for the job in seconds + #[serde(skip_serializing_if = "Option::is_none")] + pub timeout: Option, + + /// Mark job as parallel and specify instance count + #[serde(skip_serializing_if = "Option::is_none")] + pub parallel: Option, + + /// Flag to indicate this is a template job + #[serde(skip_serializing_if = "Option::is_none")] + pub template: Option, + + /// List of jobs this job extends from + #[serde(skip_serializing_if = "Option::is_none")] + pub extends: Option>, + } + + /// Docker image configuration + #[derive(Debug, Serialize, Deserialize, Clone)] + #[serde(untagged)] + pub enum Image { + /// Simple image name as string + Simple(String), + /// Detailed image configuration + Detailed { + /// Image name + name: String, + /// Entrypoint to override in the image + #[serde(skip_serializing_if = "Option::is_none")] + entrypoint: Option>, + }, + } + + /// Service container to run alongside a job + #[derive(Debug, Serialize, Deserialize, Clone)] + #[serde(untagged)] + pub enum Service { + /// Simple service name as string + Simple(String), + /// Detailed service configuration + Detailed { + /// Service name/image + name: String, + /// Command to run in the service container + #[serde(skip_serializing_if = "Option::is_none")] + command: Option>, + /// Entrypoint to override in the image + #[serde(skip_serializing_if = "Option::is_none")] + entrypoint: Option>, + }, + } + + /// Artifacts configuration + #[derive(Debug, Serialize, Deserialize, Clone)] + pub struct Artifacts { + /// Paths to include as artifacts + #[serde(skip_serializing_if = "Option::is_none")] + pub paths: Option>, + /// Artifact expiration duration + #[serde(skip_serializing_if = "Option::is_none")] + pub expire_in: Option, + /// When to upload artifacts (on_success, on_failure, always) + #[serde(skip_serializing_if = "Option::is_none")] + pub when: Option, + } + + /// Cache configuration + #[derive(Debug, Serialize, Deserialize, Clone)] + pub struct Cache { + /// Cache key + #[serde(skip_serializing_if = "Option::is_none")] + pub key: Option, + /// Paths to cache + #[serde(skip_serializing_if = "Option::is_none")] + pub paths: Option>, + /// When to save cache (on_success, on_failure, always) + #[serde(skip_serializing_if = "Option::is_none")] + pub when: Option, + /// Cache policy + #[serde(skip_serializing_if = "Option::is_none")] + pub policy: Option, + } + + /// Rule for conditional job execution + #[derive(Debug, Serialize, Deserialize, Clone)] + pub struct Rule { + /// If condition expression + #[serde(skip_serializing_if = "Option::is_none")] + pub if_: Option, + /// When to run if condition is true + #[serde(skip_serializing_if = "Option::is_none")] + pub when: Option, + /// Variables to set if condition is true + #[serde(skip_serializing_if = "Option::is_none")] + pub variables: Option>, + } + + /// Only/except configuration + #[derive(Debug, Serialize, Deserialize, Clone)] + #[serde(untagged)] + pub enum Only { + /// Simple list of refs + Refs(Vec), + /// Detailed configuration + Complex { + /// Refs to include + #[serde(skip_serializing_if = "Option::is_none")] + refs: Option>, + /// Branch patterns to include + #[serde(skip_serializing_if = "Option::is_none")] + branches: Option>, + /// Tags to include + #[serde(skip_serializing_if = "Option::is_none")] + tags: Option>, + /// Pipeline types to include + #[serde(skip_serializing_if = "Option::is_none")] + variables: Option>, + /// Changes to files that trigger the job + #[serde(skip_serializing_if = "Option::is_none")] + changes: Option>, + }, + } + + /// Except configuration + #[derive(Debug, Serialize, Deserialize, Clone)] + #[serde(untagged)] + pub enum Except { + /// Simple list of refs + Refs(Vec), + /// Detailed configuration + Complex { + /// Refs to exclude + #[serde(skip_serializing_if = "Option::is_none")] + refs: Option>, + /// Branch patterns to exclude + #[serde(skip_serializing_if = "Option::is_none")] + branches: Option>, + /// Tags to exclude + #[serde(skip_serializing_if = "Option::is_none")] + tags: Option>, + /// Pipeline types to exclude + #[serde(skip_serializing_if = "Option::is_none")] + variables: Option>, + /// Changes to files that don't trigger the job + #[serde(skip_serializing_if = "Option::is_none")] + changes: Option>, + }, + } + + /// Workflow configuration + #[derive(Debug, Serialize, Deserialize, Clone)] + pub struct Workflow { + /// Rules for when to run the pipeline + pub rules: Vec, + } + + /// Retry configuration + #[derive(Debug, Serialize, Deserialize, Clone)] + #[serde(untagged)] + pub enum Retry { + /// Simple max attempts + MaxAttempts(u32), + /// Detailed retry configuration + Detailed { + /// Maximum retry attempts + max: u32, + /// When to retry + #[serde(skip_serializing_if = "Option::is_none")] + when: Option>, + }, + } + + /// Include configuration for external pipeline files + #[derive(Debug, Serialize, Deserialize, Clone)] + #[serde(untagged)] + pub enum Include { + /// Simple string include + Local(String), + /// Detailed include configuration + Detailed { + /// Local file path + #[serde(skip_serializing_if = "Option::is_none")] + local: Option, + /// Remote file URL + #[serde(skip_serializing_if = "Option::is_none")] + remote: Option, + /// Include from project + #[serde(skip_serializing_if = "Option::is_none")] + project: Option, + /// Include specific file from project + #[serde(skip_serializing_if = "Option::is_none")] + file: Option, + /// Include template + #[serde(skip_serializing_if = "Option::is_none")] + template: Option, + /// Ref to use when including from project + #[serde(skip_serializing_if = "Option::is_none")] + ref_: Option, + }, + } +} diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index b93dae5..b0b445a 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -15,3 +15,7 @@ jsonschema.workspace = true serde.workspace = true serde_yaml.workspace = true serde_json.workspace = true +thiserror.workspace = true + +[dev-dependencies] +tempfile = "3.7" diff --git a/crates/parser/src/gitlab.rs b/crates/parser/src/gitlab.rs new file mode 100644 index 0000000..31e3ac2 --- /dev/null +++ b/crates/parser/src/gitlab.rs @@ -0,0 +1,273 @@ +use crate::schema::{SchemaType, SchemaValidator}; +use crate::workflow; +use models::gitlab::Pipeline; +use models::ValidationResult; +use std::collections::HashMap; +use std::fs; +use std::path::Path; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum GitlabParserError { + #[error("I/O error: {0}")] + IoError(#[from] std::io::Error), + + #[error("YAML parsing error: {0}")] + YamlError(#[from] serde_yaml::Error), + + #[error("Invalid pipeline structure: {0}")] + InvalidStructure(String), + + #[error("Schema validation error: {0}")] + SchemaValidationError(String), +} + +/// Parse a GitLab CI/CD pipeline file +pub fn parse_pipeline(pipeline_path: &Path) -> Result { + // Read the pipeline file + let pipeline_content = fs::read_to_string(pipeline_path)?; + + // Validate against schema + let validator = + SchemaValidator::new().map_err(GitlabParserError::SchemaValidationError)?; + + validator + .validate_with_specific_schema(&pipeline_content, SchemaType::GitLab) + .map_err(GitlabParserError::SchemaValidationError)?; + + // Parse the pipeline YAML + let pipeline: Pipeline = serde_yaml::from_str(&pipeline_content)?; + + // Return the parsed pipeline + Ok(pipeline) +} + +/// Validate the basic structure of a GitLab CI/CD pipeline +pub fn validate_pipeline_structure(pipeline: &Pipeline) -> ValidationResult { + let mut result = ValidationResult::new(); + + // Check for at least one job + if pipeline.jobs.is_empty() { + result.add_issue("Pipeline must contain at least one job".to_string()); + } + + // Check for script in jobs + for (job_name, job) in &pipeline.jobs { + // Skip template jobs + if let Some(true) = job.template { + continue; + } + + // Check for script or extends + if job.script.is_none() && job.extends.is_none() { + result.add_issue(format!( + "Job '{}' must have a script section or extend another job", + job_name + )); + } + } + + // Check that referenced stages are defined + if let Some(stages) = &pipeline.stages { + for (job_name, job) in &pipeline.jobs { + if let Some(stage) = &job.stage { + if !stages.contains(stage) { + result.add_issue(format!( + "Job '{}' references undefined stage '{}'", + job_name, stage + )); + } + } + } + } + + // Check that job dependencies exist + for (job_name, job) in &pipeline.jobs { + if let Some(dependencies) = &job.dependencies { + for dependency in dependencies { + if !pipeline.jobs.contains_key(dependency) { + result.add_issue(format!( + "Job '{}' depends on undefined job '{}'", + job_name, dependency + )); + } + } + } + } + + // Check that job extensions exist + for (job_name, job) in &pipeline.jobs { + if let Some(extends) = &job.extends { + for extend in extends { + if !pipeline.jobs.contains_key(extend) { + result.add_issue(format!( + "Job '{}' extends undefined job '{}'", + job_name, extend + )); + } + } + } + } + + result +} + +/// Convert a GitLab CI/CD pipeline to a format compatible with the workflow executor +pub fn convert_to_workflow_format(pipeline: &Pipeline) -> workflow::WorkflowDefinition { + // Create a new workflow with required fields + let mut workflow = workflow::WorkflowDefinition { + name: "Converted GitLab CI Pipeline".to_string(), + on: vec!["push".to_string()], // Default trigger + on_raw: serde_yaml::Value::String("push".to_string()), + jobs: HashMap::new(), + }; + + // Convert each GitLab job to a GitHub Actions job + for (job_name, gitlab_job) in &pipeline.jobs { + // Skip template jobs + if let Some(true) = gitlab_job.template { + continue; + } + + // Create a new job + let mut job = workflow::Job { + runs_on: "ubuntu-latest".to_string(), // Default runner + needs: None, + steps: Vec::new(), + env: HashMap::new(), + matrix: None, + services: HashMap::new(), + }; + + // Add job-specific environment variables + if let Some(variables) = &gitlab_job.variables { + job.env.extend(variables.clone()); + } + + // Add global variables if they exist + if let Some(variables) = &pipeline.variables { + // Only add if not already defined at job level + for (key, value) in variables { + job.env.entry(key.clone()).or_insert_with(|| value.clone()); + } + } + + // Convert before_script to steps if it exists + if let Some(before_script) = &gitlab_job.before_script { + for (i, cmd) in before_script.iter().enumerate() { + let step = workflow::Step { + name: Some(format!("Before script {}", i + 1)), + uses: None, + run: Some(cmd.clone()), + with: None, + env: HashMap::new(), + continue_on_error: None, + }; + job.steps.push(step); + } + } + + // Convert main script to steps + if let Some(script) = &gitlab_job.script { + for (i, cmd) in script.iter().enumerate() { + let step = workflow::Step { + name: Some(format!("Run script line {}", i + 1)), + uses: None, + run: Some(cmd.clone()), + with: None, + env: HashMap::new(), + continue_on_error: None, + }; + job.steps.push(step); + } + } + + // Convert after_script to steps if it exists + if let Some(after_script) = &gitlab_job.after_script { + for (i, cmd) in after_script.iter().enumerate() { + let step = workflow::Step { + name: Some(format!("After script {}", i + 1)), + uses: None, + run: Some(cmd.clone()), + with: None, + env: HashMap::new(), + continue_on_error: Some(true), // After script should continue even if previous steps fail + }; + job.steps.push(step); + } + } + + // Add services if they exist + if let Some(services) = &gitlab_job.services { + for (i, service) in services.iter().enumerate() { + let service_name = format!("service-{}", i); + let service_image = match service { + models::gitlab::Service::Simple(name) => name.clone(), + models::gitlab::Service::Detailed { name, .. } => name.clone(), + }; + + let service = workflow::Service { + image: service_image, + ports: None, + env: HashMap::new(), + volumes: None, + options: None, + }; + + job.services.insert(service_name, service); + } + } + + // Add the job to the workflow + workflow.jobs.insert(job_name.clone(), job); + } + + workflow +} + +#[cfg(test)] +mod tests { + use super::*; + use std::path::PathBuf; + use tempfile::NamedTempFile; + + #[test] + fn test_parse_simple_pipeline() { + // Create a temporary file with a simple GitLab CI/CD pipeline + let mut file = NamedTempFile::new().unwrap(); + let content = r#" +stages: + - build + - test + +build_job: + stage: build + script: + - echo "Building..." + - make build + +test_job: + stage: test + script: + - echo "Testing..." + - make test +"#; + fs::write(&file, content).unwrap(); + + // Parse the pipeline + let pipeline = parse_pipeline(&file.path()).unwrap(); + + // Validate basic structure + assert_eq!(pipeline.stages.as_ref().unwrap().len(), 2); + assert_eq!(pipeline.jobs.len(), 2); + + // Check job contents + let build_job = pipeline.jobs.get("build_job").unwrap(); + assert_eq!(build_job.stage.as_ref().unwrap(), "build"); + assert_eq!(build_job.script.as_ref().unwrap().len(), 2); + + let test_job = pipeline.jobs.get("test_job").unwrap(); + assert_eq!(test_job.stage.as_ref().unwrap(), "test"); + assert_eq!(test_job.script.as_ref().unwrap().len(), 2); + } +} diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 3ccc3d8..45333e8 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -1,4 +1,5 @@ // parser crate +pub mod gitlab; pub mod schema; pub mod workflow; diff --git a/crates/parser/src/schema.rs b/crates/parser/src/schema.rs index 54e5572..89138e9 100644 --- a/crates/parser/src/schema.rs +++ b/crates/parser/src/schema.rs @@ -4,23 +4,50 @@ use std::fs; use std::path::Path; const GITHUB_WORKFLOW_SCHEMA: &str = include_str!("../../../schemas/github-workflow.json"); +const GITLAB_CI_SCHEMA: &str = include_str!("../../../schemas/gitlab-ci.json"); + +#[derive(Debug, Clone, Copy)] +pub enum SchemaType { + GitHub, + GitLab, +} pub struct SchemaValidator { - schema: JSONSchema, + github_schema: JSONSchema, + gitlab_schema: JSONSchema, } impl SchemaValidator { pub fn new() -> Result { - let schema_json: Value = serde_json::from_str(GITHUB_WORKFLOW_SCHEMA) + let github_schema_json: Value = serde_json::from_str(GITHUB_WORKFLOW_SCHEMA) .map_err(|e| format!("Failed to parse GitHub workflow schema: {}", e))?; - let schema = JSONSchema::compile(&schema_json) - .map_err(|e| format!("Failed to compile JSON schema: {}", e))?; + let gitlab_schema_json: Value = serde_json::from_str(GITLAB_CI_SCHEMA) + .map_err(|e| format!("Failed to parse GitLab CI schema: {}", e))?; - Ok(Self { schema }) + let github_schema = JSONSchema::compile(&github_schema_json) + .map_err(|e| format!("Failed to compile GitHub JSON schema: {}", e))?; + + let gitlab_schema = JSONSchema::compile(&gitlab_schema_json) + .map_err(|e| format!("Failed to compile GitLab JSON schema: {}", e))?; + + Ok(Self { + github_schema, + gitlab_schema, + }) } pub fn validate_workflow(&self, workflow_path: &Path) -> Result<(), String> { + // Determine the schema type based on the filename + let schema_type = if workflow_path.file_name().is_some_and(|name| { + let name_str = name.to_string_lossy(); + name_str.ends_with(".gitlab-ci.yml") || name_str.ends_with(".gitlab-ci.yaml") + }) { + SchemaType::GitLab + } else { + SchemaType::GitHub + }; + // Read the workflow file let content = fs::read_to_string(workflow_path) .map_err(|e| format!("Failed to read workflow file: {}", e))?; @@ -29,9 +56,50 @@ impl SchemaValidator { let workflow_json: Value = serde_yaml::from_str(&content) .map_err(|e| format!("Failed to parse workflow YAML: {}", e))?; - // Validate against schema - if let Err(errors) = self.schema.validate(&workflow_json) { - let mut error_msg = String::from("Workflow validation failed:\n"); + // Validate against the appropriate schema + let validation_result = match schema_type { + SchemaType::GitHub => self.github_schema.validate(&workflow_json), + SchemaType::GitLab => self.gitlab_schema.validate(&workflow_json), + }; + + // Handle validation errors + if let Err(errors) = validation_result { + let schema_name = match schema_type { + SchemaType::GitHub => "GitHub workflow", + SchemaType::GitLab => "GitLab CI", + }; + let mut error_msg = format!("{} validation failed:\n", schema_name); + for error in errors { + error_msg.push_str(&format!("- {}\n", error)); + } + return Err(error_msg); + } + + Ok(()) + } + + pub fn validate_with_specific_schema( + &self, + content: &str, + schema_type: SchemaType, + ) -> Result<(), String> { + // Parse YAML to JSON Value + let workflow_json: Value = + serde_yaml::from_str(content).map_err(|e| format!("Failed to parse YAML: {}", e))?; + + // Validate against the appropriate schema + let validation_result = match schema_type { + SchemaType::GitHub => self.github_schema.validate(&workflow_json), + SchemaType::GitLab => self.gitlab_schema.validate(&workflow_json), + }; + + // Handle validation errors + if let Err(errors) = validation_result { + let schema_name = match schema_type { + SchemaType::GitHub => "GitHub workflow", + SchemaType::GitLab => "GitLab CI", + }; + let mut error_msg = format!("{} validation failed:\n", schema_name); for error in errors { error_msg.push_str(&format!("- {}\n", error)); } diff --git a/crates/ui/src/handlers/workflow.rs b/crates/ui/src/handlers/workflow.rs index 893587f..a6a94ba 100644 --- a/crates/ui/src/handlers/workflow.rs +++ b/crates/ui/src/handlers/workflow.rs @@ -10,8 +10,7 @@ use std::sync::mpsc; use std::thread; // Validate a workflow or directory containing workflows -#[allow(clippy::ptr_arg)] -pub fn validate_workflow(path: &PathBuf, verbose: bool) -> io::Result<()> { +pub fn validate_workflow(path: &Path, verbose: bool) -> io::Result<()> { let mut workflows = Vec::new(); if path.is_dir() { @@ -26,7 +25,7 @@ pub fn validate_workflow(path: &PathBuf, verbose: bool) -> io::Result<()> { } } } else if path.is_file() { - workflows.push(path.clone()); + workflows.push(PathBuf::from(path)); } else { return Err(io::Error::new( io::ErrorKind::NotFound, @@ -69,9 +68,8 @@ pub fn validate_workflow(path: &PathBuf, verbose: bool) -> io::Result<()> { } // Execute a workflow through the CLI -#[allow(clippy::ptr_arg)] pub async fn execute_workflow_cli( - path: &PathBuf, + path: &Path, runtime_type: RuntimeType, verbose: bool, ) -> io::Result<()> { diff --git a/crates/validators/src/gitlab.rs b/crates/validators/src/gitlab.rs new file mode 100644 index 0000000..1b416fc --- /dev/null +++ b/crates/validators/src/gitlab.rs @@ -0,0 +1,234 @@ +use models::gitlab::{Job, Pipeline}; +use models::ValidationResult; +use std::collections::HashMap; + +/// Validate a GitLab CI/CD pipeline +pub fn validate_gitlab_pipeline(pipeline: &Pipeline) -> ValidationResult { + let mut result = ValidationResult::new(); + + // Basic structure validation + if pipeline.jobs.is_empty() { + result.add_issue("Pipeline must contain at least one job".to_string()); + } + + // Validate jobs + validate_jobs(&pipeline.jobs, &mut result); + + // Validate stages if defined + if let Some(stages) = &pipeline.stages { + validate_stages(stages, &pipeline.jobs, &mut result); + } + + // Validate dependencies + validate_dependencies(&pipeline.jobs, &mut result); + + // Validate extends + validate_extends(&pipeline.jobs, &mut result); + + // Validate artifacts + validate_artifacts(&pipeline.jobs, &mut result); + + result +} + +/// Validate GitLab CI/CD jobs +fn validate_jobs(jobs: &HashMap, result: &mut ValidationResult) { + for (job_name, job) in jobs { + // Skip template jobs + if let Some(true) = job.template { + continue; + } + + // Check for script or extends + if job.script.is_none() && job.extends.is_none() { + result.add_issue(format!( + "Job '{}' must have a script section or extend another job", + job_name + )); + } + + // Check when value if present + if let Some(when) = &job.when { + match when.as_str() { + "on_success" | "on_failure" | "always" | "manual" | "never" => { + // Valid when value + } + _ => { + result.add_issue(format!( + "Job '{}' has invalid 'when' value: '{}'. Valid values are: on_success, on_failure, always, manual, never", + job_name, when + )); + } + } + } + + // Check retry configuration + if let Some(retry) = &job.retry { + match retry { + models::gitlab::Retry::MaxAttempts(attempts) => { + if *attempts > 10 { + result.add_issue(format!( + "Job '{}' has excessive retry count: {}. Consider reducing to avoid resource waste", + job_name, attempts + )); + } + } + models::gitlab::Retry::Detailed { max, when: _ } => { + if *max > 10 { + result.add_issue(format!( + "Job '{}' has excessive retry count: {}. Consider reducing to avoid resource waste", + job_name, max + )); + } + } + } + } + } +} + +/// Validate GitLab CI/CD stages +fn validate_stages(stages: &[String], jobs: &HashMap, result: &mut ValidationResult) { + // Check that all jobs reference existing stages + for (job_name, job) in jobs { + if let Some(stage) = &job.stage { + if !stages.contains(stage) { + result.add_issue(format!( + "Job '{}' references undefined stage '{}'. Available stages are: {}", + job_name, + stage, + stages.join(", ") + )); + } + } + } + + // Check for unused stages + for stage in stages { + let used = jobs.values().any(|job| { + if let Some(job_stage) = &job.stage { + job_stage == stage + } else { + false + } + }); + + if !used { + result.add_issue(format!( + "Stage '{}' is defined but not used by any job", + stage + )); + } + } +} + +/// Validate GitLab CI/CD job dependencies +fn validate_dependencies(jobs: &HashMap, result: &mut ValidationResult) { + for (job_name, job) in jobs { + if let Some(dependencies) = &job.dependencies { + for dependency in dependencies { + if !jobs.contains_key(dependency) { + result.add_issue(format!( + "Job '{}' depends on undefined job '{}'", + job_name, dependency + )); + } else if job_name == dependency { + result.add_issue(format!("Job '{}' cannot depend on itself", job_name)); + } + } + } + } +} + +/// Validate GitLab CI/CD job extends +fn validate_extends(jobs: &HashMap, result: &mut ValidationResult) { + // Check for circular extends + for (job_name, job) in jobs { + if let Some(extends) = &job.extends { + // Check that all extended jobs exist + for extend in extends { + if !jobs.contains_key(extend) { + result.add_issue(format!( + "Job '{}' extends undefined job '{}'", + job_name, extend + )); + continue; + } + + // Check for circular extends + let mut visited = vec![job_name.clone()]; + check_circular_extends(extend, jobs, &mut visited, result); + } + } + } +} + +/// Helper function to detect circular extends +fn check_circular_extends( + job_name: &str, + jobs: &HashMap, + visited: &mut Vec, + result: &mut ValidationResult, +) { + visited.push(job_name.to_string()); + + if let Some(job) = jobs.get(job_name) { + if let Some(extends) = &job.extends { + for extend in extends { + if visited.contains(&extend.to_string()) { + // Circular dependency detected + let cycle = visited + .iter() + .skip(visited.iter().position(|x| x == extend).unwrap()) + .chain(std::iter::once(extend)) + .cloned() + .collect::>() + .join(" -> "); + + result.add_issue(format!("Circular extends detected: {}", cycle)); + return; + } + + check_circular_extends(extend, jobs, visited, result); + } + } + } + + visited.pop(); +} + +/// Validate GitLab CI/CD job artifacts +fn validate_artifacts(jobs: &HashMap, result: &mut ValidationResult) { + for (job_name, job) in jobs { + if let Some(artifacts) = &job.artifacts { + // Check that paths are specified + if let Some(paths) = &artifacts.paths { + if paths.is_empty() { + result.add_issue(format!( + "Job '{}' has artifacts section with empty paths", + job_name + )); + } + } else { + result.add_issue(format!( + "Job '{}' has artifacts section without specifying paths", + job_name + )); + } + + // Check for valid 'when' value if present + if let Some(when) = &artifacts.when { + match when.as_str() { + "on_success" | "on_failure" | "always" => { + // Valid when value + } + _ => { + result.add_issue(format!( + "Job '{}' has artifacts with invalid 'when' value: '{}'. Valid values are: on_success, on_failure, always", + job_name, when + )); + } + } + } + } + } +} diff --git a/crates/validators/src/lib.rs b/crates/validators/src/lib.rs index 336a865..e88aa20 100644 --- a/crates/validators/src/lib.rs +++ b/crates/validators/src/lib.rs @@ -1,12 +1,14 @@ // validators crate mod actions; +mod gitlab; mod jobs; mod matrix; mod steps; mod triggers; pub use actions::validate_action_reference; +pub use gitlab::validate_gitlab_pipeline; pub use jobs::validate_jobs; pub use matrix::validate_matrix; pub use steps::validate_steps; diff --git a/crates/wrkflw/Cargo.toml b/crates/wrkflw/Cargo.toml index 2d8fc33..190878b 100644 --- a/crates/wrkflw/Cargo.toml +++ b/crates/wrkflw/Cargo.toml @@ -54,6 +54,7 @@ itertools.workspace = true once_cell.workspace = true crossterm.workspace = true ratatui.workspace = true +walkdir = "2.4" [lib] name = "wrkflw_lib" diff --git a/crates/wrkflw/src/main.rs b/crates/wrkflw/src/main.rs index 7244943..fb75d22 100644 --- a/crates/wrkflw/src/main.rs +++ b/crates/wrkflw/src/main.rs @@ -2,13 +2,14 @@ use bollard::Docker; use clap::{Parser, Subcommand}; use std::collections::HashMap; use std::path::PathBuf; +use std::path::Path; #[derive(Debug, Parser)] #[command( name = "wrkflw", - about = "GitHub Workflow validator and executor", + about = "GitHub & GitLab CI/CD validator and executor", version, - long_about = "A GitHub Workflow validator and executor that runs workflows locally.\n\nExamples:\n wrkflw validate # Validate all workflows in .github/workflows\n wrkflw run .github/workflows/build.yml # Run a specific workflow\n wrkflw --verbose run .github/workflows/build.yml # Run with more output\n wrkflw --debug run .github/workflows/build.yml # Run with detailed debug information\n wrkflw run --emulate .github/workflows/build.yml # Use emulation mode instead of Docker" + long_about = "A CI/CD validator and executor that runs workflows locally.\n\nExamples:\n wrkflw validate # Validate all workflows in .github/workflows\n wrkflw run .github/workflows/build.yml # Run a specific workflow\n wrkflw run .gitlab-ci.yml # Run a GitLab CI pipeline\n wrkflw --verbose run .github/workflows/build.yml # Run with more output\n wrkflw --debug run .github/workflows/build.yml # Run with detailed debug information\n wrkflw run --emulate .github/workflows/build.yml # Use emulation mode instead of Docker" )] struct Wrkflw { #[command(subcommand)] @@ -25,15 +26,19 @@ struct Wrkflw { #[derive(Debug, Subcommand)] enum Commands { - /// Validate GitHub workflow files + /// Validate workflow or pipeline files Validate { - /// Path to workflow file or directory (defaults to .github/workflows) + /// Path to workflow/pipeline file or directory (defaults to .github/workflows) path: Option, + + /// Explicitly validate as GitLab CI/CD pipeline + #[arg(long)] + gitlab: bool, }, - /// Execute GitHub workflow files locally + /// Execute workflow or pipeline files locally Run { - /// Path to workflow file to execute + /// Path to workflow/pipeline file to execute path: PathBuf, /// Use emulation mode instead of Docker @@ -43,6 +48,10 @@ enum Commands { /// Show 'Would execute GitHub action' messages in emulation mode #[arg(long, default_value_t = false)] show_action_messages: bool, + + /// Explicitly run as GitLab CI/CD pipeline + #[arg(long)] + gitlab: bool, }, /// Open TUI interface to manage workflows @@ -84,7 +93,7 @@ enum Commands { variable: Option>, }, - /// List available workflows + /// List available workflows and pipelines List, } @@ -173,6 +182,51 @@ async fn handle_signals() { std::process::exit(0); } +/// Determines if a file is a GitLab CI/CD pipeline based on its name and content +fn is_gitlab_pipeline(path: &Path) -> bool { + // First check the file name + if let Some(file_name) = path.file_name() { + if let Some(file_name_str) = file_name.to_str() { + if file_name_str == ".gitlab-ci.yml" || file_name_str.ends_with("gitlab-ci.yml") { + return true; + } + } + } + + // Check if file is in .gitlab/ci directory + if let Some(parent) = path.parent() { + if let Some(parent_str) = parent.to_str() { + if parent_str.ends_with(".gitlab/ci") + && path + .extension().is_some_and(|ext| ext == "yml" || ext == "yaml") + { + return true; + } + } + } + + // If file exists, check the content + if path.exists() { + if let Ok(content) = std::fs::read_to_string(path) { + // GitLab CI/CD pipelines typically have stages, before_script, after_script at the top level + if content.contains("stages:") + || content.contains("before_script:") + || content.contains("after_script:") + { + // Check for GitHub Actions specific keys that would indicate it's not GitLab + if !content.contains("on:") + && !content.contains("runs-on:") + && !content.contains("uses:") + { + return true; + } + } + } + } + + false +} + #[tokio::main] async fn main() { let cli = Wrkflw::parse(); @@ -194,285 +248,303 @@ async fn main() { tokio::spawn(handle_signals()); match &cli.command { - Some(Commands::Validate { path }) => { + Some(Commands::Validate { path, gitlab }) => { // Determine the path to validate let validate_path = path .clone() .unwrap_or_else(|| PathBuf::from(".github/workflows")); - // Run the validation using ui crate - ui::validate_workflow(&validate_path, verbose).unwrap_or_else(|e| { - eprintln!("Error: {}", e); + // Check if the path exists + if !validate_path.exists() { + eprintln!("Error: Path does not exist: {}", validate_path.display()); std::process::exit(1); - }); - } + } + // Determine if we're validating a GitLab pipeline based on the --gitlab flag or file detection + let force_gitlab = *gitlab; + + if validate_path.is_dir() { + // Validate all workflow files in the directory + let entries = std::fs::read_dir(&validate_path) + .expect("Failed to read directory") + .filter_map(|entry| entry.ok()) + .filter(|entry| { + entry.path().is_file() + && entry + .path() + .extension().is_some_and(|ext| ext == "yml" || ext == "yaml") + }) + .collect::>(); + + println!("Validating {} workflow file(s)...", entries.len()); + + for entry in entries { + let path = entry.path(); + let is_gitlab = force_gitlab || is_gitlab_pipeline(&path); + + if is_gitlab { + validate_gitlab_pipeline(&path, verbose); + } else { + validate_github_workflow(&path, verbose); + } + } + } else { + // Validate a single workflow file + let is_gitlab = force_gitlab || is_gitlab_pipeline(&validate_path); + + if is_gitlab { + validate_gitlab_pipeline(&validate_path, verbose); + } else { + validate_github_workflow(&validate_path, verbose); + } + } + } Some(Commands::Run { path, emulate, - show_action_messages: _, // Assuming this flag is handled within executor/runtime + show_action_messages: _, + gitlab, }) => { - // Set runner mode based on flags + // Determine the runtime type let runtime_type = if *emulate { executor::RuntimeType::Emulation } else { executor::RuntimeType::Docker }; - // First validate the workflow file using parser crate - match parser::workflow::parse_workflow(path) { - Ok(_) => logging::info("Validating workflow..."), - Err(e) => { - logging::error(&format!("Workflow validation failed: {}", e)); - std::process::exit(1); - } - } + // Check if we're explicitly or implicitly running a GitLab pipeline + let is_gitlab = *gitlab || is_gitlab_pipeline(path); + let workflow_type = if is_gitlab { + "GitLab CI pipeline" + } else { + "GitHub workflow" + }; - // Execute the workflow using executor crate - match executor::execute_workflow(path, runtime_type, verbose || debug).await { - Ok(result) => { - // Print job results - for job in &result.jobs { + logging::info(&format!("Running {} at: {}", workflow_type, path.display())); + + // Execute the workflow + let result = executor::execute_workflow(path, runtime_type, verbose) + .await + .unwrap_or_else(|e| { + eprintln!("Error executing workflow: {}", e); + std::process::exit(1); + }); + + // Print execution summary + if result.failure_details.is_some() { + eprintln!("❌ Workflow execution failed:"); + if let Some(details) = result.failure_details { + eprintln!("{}", details); + } + std::process::exit(1); + } else { + println!("✅ Workflow execution completed successfully!"); + + // Print a summary of executed jobs + if verbose { + println!("\nJob summary:"); + for job in result.jobs { println!( - "\n{} Job {}: {}", - if job.status == executor::JobStatus::Success { - "✅" - } else { - "❌" + " {} {} ({})", + match job.status { + executor::JobStatus::Success => "✅", + executor::JobStatus::Failure => "❌", + executor::JobStatus::Skipped => "⏭️", }, job.name, - if job.status == executor::JobStatus::Success { - "succeeded" - } else { - "failed" + match job.status { + executor::JobStatus::Success => "success", + executor::JobStatus::Failure => "failure", + executor::JobStatus::Skipped => "skipped", } ); - // Print step results - for step in &job.steps { - println!( - " {} {}", - if step.status == executor::StepStatus::Success { - "✅" - } else { - "❌" - }, - step.name - ); - - if !step.output.trim().is_empty() { - // If the output is very long, trim it - let output_lines = step.output.lines().collect::>(); - - println!(" Output:"); - - // In verbose mode, show complete output - if verbose || debug { - for line in &output_lines { - println!(" {}", line); - } - } else { - // Show only the first few lines - let max_lines = 5; - for line in output_lines.iter().take(max_lines) { - println!(" {}", line); - } - - if output_lines.len() > max_lines { - println!(" ... ({} more lines, use --verbose to see full output)", - output_lines.len() - max_lines); - } - } + if debug { + println!(" Steps:"); + for step in job.steps { + println!( + " {} {}", + match step.status { + executor::StepStatus::Success => "✅", + executor::StepStatus::Failure => "❌", + executor::StepStatus::Skipped => "⏭️", + }, + step.name + ); } } } - - // Print detailed failure information if available - if let Some(failure_details) = &result.failure_details { - println!("\n❌ Workflow execution failed!"); - println!("{}", failure_details); - println!("\nTo fix these issues:"); - println!("1. Check the formatting issues with: cargo fmt"); - println!("2. Fix clippy warnings with: cargo clippy -- -D warnings"); - println!("3. Run tests to ensure everything passes: cargo test"); - std::process::exit(1); - } else { - println!("\n✅ Workflow completed successfully!"); - } - } - Err(e) => { - logging::error(&format!("Workflow execution failed: {}", e)); - std::process::exit(1); } } - } + // Cleanup is handled automatically via the signal handler + } + Some(Commands::TriggerGitlab { branch, variable }) => { + // Convert optional Vec<(String, String)> to Option> + let variables = variable + .as_ref() + .map(|v| v.iter().cloned().collect::>()); + + // Trigger the pipeline + if let Err(e) = gitlab::trigger_pipeline(branch.as_deref(), variables).await { + eprintln!("Error triggering GitLab pipeline: {}", e); + std::process::exit(1); + } + } Some(Commands::Tui { path, emulate, - show_action_messages, + show_action_messages: _, }) => { - // Open the TUI interface using ui crate + // Set runtime type based on the emulate flag let runtime_type = if *emulate { executor::RuntimeType::Emulation } else { - // Check if Docker is available, fall back to emulation if not - // Assuming executor::docker::is_available() exists - if !executor::docker::is_available() { - println!("⚠️ Docker is not available. Using emulation mode instead."); - logging::warning("Docker is not available. Using emulation mode instead."); - executor::RuntimeType::Emulation - } else { - executor::RuntimeType::Docker - } + executor::RuntimeType::Docker }; - // Control hiding action messages based on the flag - if !show_action_messages { - std::env::set_var("WRKFLW_HIDE_ACTION_MESSAGES", "true"); - } else { - std::env::set_var("WRKFLW_HIDE_ACTION_MESSAGES", "false"); - } - - match ui::run_wrkflw_tui(path.as_ref(), runtime_type, verbose).await { - Ok(_) => { - // Clean up on successful exit - cleanup_on_exit().await; - } - Err(e) => { - eprintln!("Error: {}", e); - cleanup_on_exit().await; // Ensure cleanup even on error - std::process::exit(1); - } + // Call the TUI implementation from the ui crate + if let Err(e) = ui::run_wrkflw_tui(path.as_ref(), runtime_type, verbose).await { + eprintln!("Error running TUI: {}", e); + std::process::exit(1); } } - Some(Commands::Trigger { workflow, branch, input, }) => { - logging::info(&format!("Triggering workflow {} on GitHub", workflow)); + // Convert optional Vec<(String, String)> to Option> + let inputs = input + .as_ref() + .map(|i| i.iter().cloned().collect::>()); - // Convert inputs to HashMap - let input_map = input.as_ref().map(|i| { - i.iter() - .map(|(k, v)| (k.clone(), v.clone())) - .collect::>() - }); - - // Use github crate - match github::trigger_workflow(workflow, branch.as_deref(), input_map).await { - Ok(_) => logging::info("Workflow triggered successfully"), - Err(e) => { - eprintln!("Error triggering workflow: {}", e); - std::process::exit(1); - } + // Trigger the workflow + if let Err(e) = github::trigger_workflow(workflow, branch.as_deref(), inputs).await { + eprintln!("Error triggering GitHub workflow: {}", e); + std::process::exit(1); } } - - Some(Commands::TriggerGitlab { branch, variable }) => { - logging::info("Triggering pipeline on GitLab"); - - // Convert variables to HashMap - let variable_map = variable.as_ref().map(|v| { - v.iter() - .map(|(k, v)| (k.clone(), v.clone())) - .collect::>() - }); - - // Use gitlab crate - match gitlab::trigger_pipeline(branch.as_deref(), variable_map).await { - Ok(_) => logging::info("GitLab pipeline triggered successfully"), - Err(e) => { - eprintln!("Error triggering GitLab pipeline: {}", e); - std::process::exit(1); - } - } - } - Some(Commands::List) => { - logging::info("Listing available workflows"); - - // Attempt to get GitHub repo info using github crate - if let Ok(repo_info) = github::get_repo_info() { - match github::list_workflows(&repo_info).await { - Ok(workflows) => { - if workflows.is_empty() { - println!("No GitHub workflows found in repository"); - } else { - println!("GitHub workflows:"); - for workflow in workflows { - println!(" {}", workflow); - } - } - } - Err(e) => { - eprintln!("Error listing GitHub workflows: {}", e); - } - } - } else { - println!("Not a GitHub repository or unable to get repository information"); - } - - // Attempt to get GitLab repo info using gitlab crate - if let Ok(repo_info) = gitlab::get_repo_info() { - match gitlab::list_pipelines(&repo_info).await { - Ok(pipelines) => { - if pipelines.is_empty() { - println!("No GitLab pipelines found in repository"); - } else { - println!("GitLab pipelines:"); - for pipeline in pipelines { - println!(" {}", pipeline); - } - } - } - Err(e) => { - eprintln!("Error listing GitLab pipelines: {}", e); - } - } - } else { - println!("Not a GitLab repository or unable to get repository information"); - } + list_workflows_and_pipelines(verbose); } - None => { - // Default to TUI interface if no subcommand - // Check if Docker is available, fall back to emulation if not - let runtime_type = if !executor::docker::is_available() { - println!("⚠️ Docker is not available. Using emulation mode instead."); - logging::warning("Docker is not available. Using emulation mode instead."); - executor::RuntimeType::Emulation - } else { - executor::RuntimeType::Docker - }; + // Launch TUI by default when no command is provided + let runtime_type = executor::RuntimeType::Docker; - // Set environment variable to hide action messages by default - std::env::set_var("WRKFLW_HIDE_ACTION_MESSAGES", "true"); - - match ui::run_wrkflw_tui( - Some(&PathBuf::from(".github/workflows")), - runtime_type, - verbose, - ) - .await - { - Ok(_) => { - // Clean up on successful exit - cleanup_on_exit().await; - } - Err(e) => { - eprintln!("Error: {}", e); - cleanup_on_exit().await; // Ensure cleanup even on error - std::process::exit(1); - } + // Call the TUI implementation from the ui crate with default path + if let Err(e) = ui::run_wrkflw_tui(None, runtime_type, verbose).await { + eprintln!("Error running TUI: {}", e); + std::process::exit(1); + } + } + } +} + +/// Validate a GitHub workflow file +fn validate_github_workflow(path: &Path, verbose: bool) { + print!("Validating GitHub workflow file: {}... ", path.display()); + + // Use the ui crate's validate_workflow function + match ui::validate_workflow(path, verbose) { + Ok(_) => { + // The detailed validation output is already printed by the function + } + Err(e) => { + eprintln!("Error validating workflow: {}", e); + } + } +} + +/// Validate a GitLab CI/CD pipeline file +fn validate_gitlab_pipeline(path: &Path, verbose: bool) { + print!("Validating GitLab CI pipeline file: {}... ", path.display()); + + // Parse and validate the pipeline file + match parser::gitlab::parse_pipeline(path) { + Ok(pipeline) => { + println!("✅ Valid syntax"); + + // Additional structural validation + let validation_result = validators::validate_gitlab_pipeline(&pipeline); + + if !validation_result.is_valid { + println!("⚠️ Validation issues:"); + for issue in validation_result.issues { + println!(" - {}", issue); + } + } else if verbose { + println!("✅ All validation checks passed"); + } + } + Err(e) => { + println!("❌ Invalid"); + eprintln!("Validation failed: {}", e); + } + } +} + +/// List available workflows and pipelines in the repository +fn list_workflows_and_pipelines(verbose: bool) { + // Check for GitHub workflows + let github_path = PathBuf::from(".github/workflows"); + if github_path.exists() && github_path.is_dir() { + println!("GitHub Workflows:"); + + let entries = std::fs::read_dir(&github_path) + .expect("Failed to read directory") + .filter_map(|entry| entry.ok()) + .filter(|entry| { + entry.path().is_file() + && entry + .path() + .extension().is_some_and(|ext| ext == "yml" || ext == "yaml") + }) + .collect::>(); + + if entries.is_empty() { + println!(" No workflow files found in .github/workflows"); + } else { + for entry in entries { + println!(" - {}", entry.path().display()); + } + } + } else { + println!("GitHub Workflows: No .github/workflows directory found"); + } + + // Check for GitLab CI pipeline + let gitlab_path = PathBuf::from(".gitlab-ci.yml"); + if gitlab_path.exists() && gitlab_path.is_file() { + println!("GitLab CI Pipeline:"); + println!(" - {}", gitlab_path.display()); + } else { + println!("GitLab CI Pipeline: No .gitlab-ci.yml file found"); + } + + // Check for other GitLab CI pipeline files + if verbose { + println!("Searching for other GitLab CI pipeline files..."); + + let entries = walkdir::WalkDir::new(".") + .follow_links(true) + .into_iter() + .filter_map(|entry| entry.ok()) + .filter(|entry| { + entry.path().is_file() + && entry + .file_name() + .to_string_lossy() + .ends_with("gitlab-ci.yml") + && entry.path() != gitlab_path + }) + .collect::>(); + + if !entries.is_empty() { + println!("Additional GitLab CI Pipeline files:"); + for entry in entries { + println!(" - {}", entry.path().display()); } } } - - // Final cleanup before program exit (redundant if called on success/error/signal?) - // Consider if this final call is necessary given the calls in Ok/Err/signal handlers. - // It might be okay as a safety net, but ensure cleanup_on_exit is idempotent. - // cleanup_on_exit().await; // Keep or remove based on idempotency review } diff --git a/schemas/gitlab-ci.json b/schemas/gitlab-ci.json new file mode 100644 index 0000000..5a71408 --- /dev/null +++ b/schemas/gitlab-ci.json @@ -0,0 +1,3012 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://gitlab.com/.gitlab-ci.yml", + "markdownDescription": "Gitlab has a built-in solution for doing CI called Gitlab CI. It is configured by supplying a file called `.gitlab-ci.yml`, which will list all the jobs that are going to run for the project. A full list of all options can be found [here](https://docs.gitlab.com/ee/ci/yaml/). [Learn More](https://docs.gitlab.com/ee/ci/).", + "type": "object", + "properties": { + "$schema": { + "type": "string", + "format": "uri" + }, + "spec": { + "type": "object", + "markdownDescription": "Specification for pipeline configuration. Must be declared at the top of a configuration file, in a header section separated from the rest of the configuration with `---`. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#spec).", + "properties": { + "inputs": { + "$ref": "#/definitions/inputParameters" + } + }, + "additionalProperties": false + }, + "image": { + "$ref": "#/definitions/image", + "markdownDescription": "Defining `image` globally is deprecated. Use [`default`](https://docs.gitlab.com/ee/ci/yaml/#default) instead. [Learn more](https://docs.gitlab.com/ee/ci/yaml/#globally-defined-image-services-cache-before_script-after_script)." + }, + "services": { + "$ref": "#/definitions/services", + "markdownDescription": "Defining `services` globally is deprecated. Use [`default`](https://docs.gitlab.com/ee/ci/yaml/#default) instead. [Learn more](https://docs.gitlab.com/ee/ci/yaml/#globally-defined-image-services-cache-before_script-after_script)." + }, + "before_script": { + "$ref": "#/definitions/before_script", + "markdownDescription": "Defining `before_script` globally is deprecated. Use [`default`](https://docs.gitlab.com/ee/ci/yaml/#default) instead. [Learn more](https://docs.gitlab.com/ee/ci/yaml/#globally-defined-image-services-cache-before_script-after_script)." + }, + "after_script": { + "$ref": "#/definitions/after_script", + "markdownDescription": "Defining `after_script` globally is deprecated. Use [`default`](https://docs.gitlab.com/ee/ci/yaml/#default) instead. [Learn more](https://docs.gitlab.com/ee/ci/yaml/#globally-defined-image-services-cache-before_script-after_script)." + }, + "variables": { + "$ref": "#/definitions/globalVariables" + }, + "cache": { + "$ref": "#/definitions/cache", + "markdownDescription": "Defining `cache` globally is deprecated. Use [`default`](https://docs.gitlab.com/ee/ci/yaml/#default) instead. [Learn more](https://docs.gitlab.com/ee/ci/yaml/#globally-defined-image-services-cache-before_script-after_script)." + }, + "!reference": { + "$ref": "#/definitions/!reference" + }, + "default": { + "type": "object", + "properties": { + "after_script": { + "$ref": "#/definitions/after_script" + }, + "artifacts": { + "$ref": "#/definitions/artifacts" + }, + "before_script": { + "$ref": "#/definitions/before_script" + }, + "hooks": { + "$ref": "#/definitions/hooks" + }, + "cache": { + "$ref": "#/definitions/cache" + }, + "image": { + "$ref": "#/definitions/image" + }, + "interruptible": { + "$ref": "#/definitions/interruptible" + }, + "id_tokens": { + "$ref": "#/definitions/id_tokens" + }, + "identity": { + "$ref": "#/definitions/identity" + }, + "retry": { + "$ref": "#/definitions/retry" + }, + "services": { + "$ref": "#/definitions/services" + }, + "tags": { + "$ref": "#/definitions/tags" + }, + "timeout": { + "$ref": "#/definitions/timeout" + }, + "!reference": { + "$ref": "#/definitions/!reference" + } + }, + "additionalProperties": false + }, + "stages": { + "type": "array", + "markdownDescription": "Groups jobs into stages. All jobs in one stage must complete before next stage is executed. Defaults to ['build', 'test', 'deploy']. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#stages).", + "default": [ + "build", + "test", + "deploy" + ], + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "uniqueItems": true, + "minItems": 1 + }, + "include": { + "markdownDescription": "Can be `IncludeItem` or `IncludeItem[]`. Each `IncludeItem` will be a string, or an object with properties for the method if including external YAML file. The external content will be fetched, included and evaluated along the `.gitlab-ci.yml`. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#include).", + "oneOf": [ + { + "$ref": "#/definitions/include_item" + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/include_item" + } + } + ] + }, + "pages": { + "$ref": "#/definitions/job", + "markdownDescription": "A special job used to upload static sites to Gitlab pages. Requires a `public/` directory with `artifacts.path` pointing to it. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#pages)." + }, + "workflow": { + "type": "object", + "properties": { + "name": { + "$ref": "#/definitions/workflowName" + }, + "auto_cancel": { + "$ref": "#/definitions/workflowAutoCancel" + }, + "rules": { + "type": "array", + "items": { + "anyOf": [ + { + "type": "object" + }, + { + "type": "array", + "minItems": 1, + "items": { + "type": "string" + } + } + ], + "properties": { + "if": { + "$ref": "#/definitions/if" + }, + "changes": { + "$ref": "#/definitions/changes" + }, + "exists": { + "$ref": "#/definitions/exists" + }, + "variables": { + "$ref": "#/definitions/rulesVariables" + }, + "when": { + "type": "string", + "enum": [ + "always", + "never" + ] + }, + "auto_cancel": { + "$ref": "#/definitions/workflowAutoCancel" + } + }, + "additionalProperties": false + } + } + } + } + }, + "patternProperties": { + "^[.]": { + "description": "Hidden keys.", + "anyOf": [ + { + "$ref": "#/definitions/job_template" + }, + { + "description": "Arbitrary YAML anchor." + } + ] + } + }, + "additionalProperties": { + "$ref": "#/definitions/job" + }, + "definitions": { + "artifacts": { + "type": [ + "object", + "null" + ], + "markdownDescription": "Used to specify a list of files and directories that should be attached to the job if it succeeds. Artifacts are sent to Gitlab where they can be downloaded. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#artifacts).", + "additionalProperties": false, + "properties": { + "paths": { + "type": "array", + "markdownDescription": "A list of paths to files/folders that should be included in the artifact. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#artifactspaths).", + "items": { + "type": "string" + }, + "minItems": 1 + }, + "exclude": { + "type": "array", + "markdownDescription": "A list of paths to files/folders that should be excluded in the artifact. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#artifactsexclude).", + "items": { + "type": "string" + }, + "minItems": 1 + }, + "expose_as": { + "type": "string", + "markdownDescription": "Can be used to expose job artifacts in the merge request UI. GitLab will add a link to the relevant merge request that points to the artifact. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#artifactsexpose_as)." + }, + "name": { + "type": "string", + "markdownDescription": "Name for the archive created on job success. Can use variables in the name, e.g. '$CI_JOB_NAME' [Learn More](https://docs.gitlab.com/ee/ci/yaml/#artifactsname)." + }, + "untracked": { + "type": "boolean", + "markdownDescription": "Whether to add all untracked files (along with 'artifacts.paths') to the artifact. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#artifactsuntracked).", + "default": false + }, + "when": { + "markdownDescription": "Configure when artifacts are uploaded depended on job status. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#artifactswhen).", + "default": "on_success", + "type": "string", + "enum": [ + "on_success", + "on_failure", + "always" + ] + }, + "access": { + "markdownDescription": "Configure who can access the artifacts. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#artifactsaccess).", + "default": "all", + "type": "string", + "enum": [ + "none", + "developer", + "all" + ] + }, + "expire_in": { + "type": "string", + "markdownDescription": "How long artifacts should be kept. They are saved 30 days by default. Artifacts that have expired are removed periodically via cron job. Supports a wide variety of formats, e.g. '1 week', '3 mins 4 sec', '2 hrs 20 min', '2h20min', '6 mos 1 day', '47 yrs 6 mos and 4d', '3 weeks and 2 days'. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#artifactsexpire_in).", + "default": "30 days" + }, + "reports": { + "type": "object", + "markdownDescription": "Reports will be uploaded as artifacts, and often displayed in the Gitlab UI, such as in merge requests. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#artifactsreports).", + "additionalProperties": false, + "properties": { + "annotations": { + "type": "string", + "description": "Path to JSON file with annotations report." + }, + "junit": { + "description": "Path for file(s) that should be parsed as JUnit XML result", + "oneOf": [ + { + "type": "string", + "description": "Path to a single XML file" + }, + { + "type": "array", + "description": "A list of paths to XML files that will automatically be concatenated into a single file", + "items": { + "type": "string" + }, + "minItems": 1 + } + ] + }, + "browser_performance": { + "type": "string", + "description": "Path to a single file with browser performance metric report(s)." + }, + "coverage_report": { + "type": [ + "object", + "null" + ], + "description": "Used to collect coverage reports from the job.", + "properties": { + "coverage_format": { + "description": "Code coverage format used by the test framework.", + "enum": [ + "cobertura", + "jacoco" + ] + }, + "path": { + "description": "Path to the coverage report file that should be parsed.", + "type": "string", + "minLength": 1 + } + } + }, + "codequality": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files with code quality report(s) (such as Code Climate)." + }, + "dotenv": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files containing runtime-created variables for this job." + }, + "lsif": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files containing code intelligence (Language Server Index Format)." + }, + "sast": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files with SAST vulnerabilities report(s)." + }, + "dependency_scanning": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files with Dependency scanning vulnerabilities report(s)." + }, + "container_scanning": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files with Container scanning vulnerabilities report(s)." + }, + "dast": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files with DAST vulnerabilities report(s)." + }, + "license_management": { + "$ref": "#/definitions/string_file_list", + "description": "Deprecated in 12.8: Path to file or list of files with license report(s)." + }, + "license_scanning": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files with license report(s)." + }, + "requirements": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files with requirements report(s)." + }, + "secret_detection": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files with secret detection report(s)." + }, + "metrics": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files with custom metrics report(s)." + }, + "terraform": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files with terraform plan(s)." + }, + "cyclonedx": { + "$ref": "#/definitions/string_file_list", + "markdownDescription": "Path to file or list of files with cyclonedx report(s). [Learn More](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportscyclonedx)." + }, + "load_performance": { + "$ref": "#/definitions/string_file_list", + "markdownDescription": "Path to file or list of files with load performance testing report(s). [Learn More](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportsload_performance)." + }, + "repository_xray": { + "$ref": "#/definitions/string_file_list", + "description": "Path to file or list of files with Repository X-Ray report(s)." + } + } + } + } + }, + "string_file_list": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "inputParameters": { + "type": "object", + "markdownDescription": "Define parameters that can be populated in reusable CI/CD configuration files when added to a pipeline. [Learn More](https://docs.gitlab.com/ee/ci/yaml/inputs).", + "patternProperties": { + ".*": { + "markdownDescription": "**Input Configuration**\n\nAvailable properties:\n- `type`: string (default), array, boolean, or number\n- `description`: Human-readable explanation of the parameter (supports Markdown)\n- `options`: List of allowed values\n- `default`: Value to use when not specified (makes input optional)\n- `regex`: Pattern that string values must match", + "oneOf": [ + { + "type": "object", + "properties": { + "type": { + "type": "string", + "markdownDescription": "Force a specific input type. Defaults to 'string' when not specified. [Learn More](https://docs.gitlab.com/ee/ci/yaml/inputs/#input-types).", + "enum": [ + "array", + "boolean", + "number", + "string" + ], + "default": "string" + }, + "description": { + "type": "string", + "markdownDescription": "Give a description to a specific input. The description does not affect the input, but can help people understand the input details or expected values. Supports markdown.", + "maxLength": 1024 + }, + "options": { + "type": "array", + "markdownDescription": "Specify a list of allowed values for an input.", + "items": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "number" + }, + { + "type": "boolean" + } + ] + } + }, + "regex": { + "type": "string", + "markdownDescription": "Specify a regular expression that the input must match. Only impacts inputs with a `type` of `string`." + }, + "default": { + "markdownDescription": "Define default values for inputs when not specified. When you specify a default, the inputs are no longer mandatory." + } + }, + "allOf": [ + { + "if": { + "properties": { + "type": { + "enum": [ + "string" + ] + } + } + }, + "then": { + "properties": { + "default": { + "type": [ + "string", + "null" + ] + } + } + } + }, + { + "if": { + "properties": { + "type": { + "enum": [ + "number" + ] + } + } + }, + "then": { + "properties": { + "default": { + "type": [ + "number", + "null" + ] + } + } + } + }, + { + "if": { + "properties": { + "type": { + "enum": [ + "boolean" + ] + } + } + }, + "then": { + "properties": { + "default": { + "type": [ + "boolean", + "null" + ] + } + } + } + }, + { + "if": { + "properties": { + "type": { + "enum": [ + "array" + ] + } + } + }, + "then": { + "properties": { + "default": { + "oneOf": [ + { + "type": "array" + }, + { + "type": "null" + } + ] + } + } + } + } + ], + "additionalProperties": false + }, + { + "type": "null" + } + ] + } + } + }, + "include_item": { + "oneOf": [ + { + "description": "Will infer the method based on the value. E.g. `https://...` strings will be of type `include:remote`, and `/templates/...` or `templates/...` will be of type `include:local`.", + "type": "string", + "format": "uri-reference", + "pattern": "\\w\\.ya?ml$", + "anyOf": [ + { + "pattern": "^https?://" + }, + { + "not": { + "pattern": "^\\w+://" + } + } + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "local": { + "description": "Relative path from local repository root (`/`) to the `yaml`/`yml` file template. The file must be on the same branch, and does not work across git submodules.", + "type": "string", + "format": "uri-reference", + "pattern": "\\.ya?ml$" + }, + "rules": { + "$ref": "#/definitions/includeRules" + }, + "inputs": { + "$ref": "#/definitions/inputs" + } + }, + "required": [ + "local" + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "project": { + "description": "Path to the project, e.g. `group/project`, or `group/sub-group/project` [Learn more](https://docs.gitlab.com/ee/ci/yaml/#includefile).", + "type": "string", + "pattern": "(?:\\S/\\S|\\$\\S+)" + }, + "ref": { + "description": "Branch/Tag/Commit-hash for the target project.", + "type": "string" + }, + "file": { + "oneOf": [ + { + "description": "Relative path from project root (`/`) to the `yaml`/`yml` file template.", + "type": "string", + "pattern": "\\.ya?ml$" + }, + { + "description": "List of files by relative path from project root (`/`) to the `yaml`/`yml` file template.", + "type": "array", + "items": { + "type": "string", + "pattern": "\\.ya?ml$" + } + } + ] + }, + "rules": { + "$ref": "#/definitions/includeRules" + }, + "inputs": { + "$ref": "#/definitions/inputs" + } + }, + "required": [ + "project", + "file" + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "template": { + "description": "Use a `.gitlab-ci.yml` template as a base, e.g. `Nodejs.gitlab-ci.yml`.", + "type": "string", + "format": "uri-reference", + "pattern": "\\.ya?ml$" + }, + "rules": { + "$ref": "#/definitions/includeRules" + }, + "inputs": { + "$ref": "#/definitions/inputs" + } + }, + "required": [ + "template" + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "component": { + "description": "Local path to component directory or full path to external component directory.", + "type": "string", + "format": "uri-reference" + }, + "rules": { + "$ref": "#/definitions/includeRules" + }, + "inputs": { + "$ref": "#/definitions/inputs" + } + }, + "required": [ + "component" + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "remote": { + "description": "URL to a `yaml`/`yml` template file using HTTP/HTTPS.", + "type": "string", + "format": "uri-reference", + "pattern": "^https?://.+\\.ya?ml$" + }, + "integrity": { + "description": "SHA256 integrity hash of the remote file content.", + "type": "string", + "pattern": "^sha256-[A-Za-z0-9+/]{43}=$" + }, + "rules": { + "$ref": "#/definitions/includeRules" + }, + "inputs": { + "$ref": "#/definitions/inputs" + } + }, + "required": [ + "remote" + ] + } + ] + }, + "!reference": { + "type": "array", + "items": { + "type": "string", + "minLength": 1 + } + }, + "image": { + "oneOf": [ + { + "type": "string", + "minLength": 1, + "description": "Full name of the image that should be used. It should contain the Registry part if needed." + }, + { + "type": "object", + "description": "Specifies the docker image to use for the job or globally for all jobs. Job configuration takes precedence over global setting. Requires a certain kind of Gitlab runner executor.", + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "minLength": 1, + "description": "Full name of the image that should be used. It should contain the Registry part if needed." + }, + "entrypoint": { + "type": "array", + "description": "Command or script that should be executed as the container's entrypoint. It will be translated to Docker's --entrypoint option while creating the container. The syntax is similar to Dockerfile's ENTRYPOINT directive, where each shell token is a separate string in the array.", + "minItems": 1 + }, + "docker": { + "type": "object", + "markdownDescription": "Options to pass to Runners Docker Executor. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#imagedocker)", + "additionalProperties": false, + "properties": { + "platform": { + "type": "string", + "minLength": 1, + "description": "Image architecture to pull." + }, + "user": { + "type": "string", + "minLength": 1, + "maxLength": 255, + "description": "Username or UID to use for the container." + } + } + }, + "pull_policy": { + "markdownDescription": "Specifies how to pull the image in Runner. It can be one of `always`, `never` or `if-not-present`. The default value is `always`. [Learn more](https://docs.gitlab.com/ee/ci/yaml/#imagepull_policy).", + "default": "always", + "oneOf": [ + { + "type": "string", + "enum": [ + "always", + "never", + "if-not-present" + ] + }, + { + "type": "array", + "items": { + "type": "string", + "enum": [ + "always", + "never", + "if-not-present" + ] + }, + "minItems": 1, + "uniqueItems": true + } + ] + } + }, + "required": [ + "name" + ] + } + ], + "markdownDescription": "Specifies the docker image to use for the job or globally for all jobs. Job configuration takes precedence over global setting. Requires a certain kind of Gitlab runner executor. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#image)." + }, + "services": { + "type": "array", + "markdownDescription": "Similar to `image` property, but will link the specified services to the `image` container. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#services).", + "items": { + "oneOf": [ + { + "type": "string", + "minLength": 1, + "description": "Full name of the image that should be used. It should contain the Registry part if needed." + }, + { + "type": "object", + "description": "", + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "description": "Full name of the image that should be used. It should contain the Registry part if needed.", + "minLength": 1 + }, + "entrypoint": { + "type": "array", + "markdownDescription": "Command or script that should be executed as the container's entrypoint. It will be translated to Docker's --entrypoint option while creating the container. The syntax is similar to Dockerfile's ENTRYPOINT directive, where each shell token is a separate string in the array. [Learn More](https://docs.gitlab.com/ee/ci/services/#available-settings-for-services)", + "minItems": 1, + "items": { + "type": "string" + } + }, + "docker": { + "type": "object", + "markdownDescription": "Options to pass to Runners Docker Executor. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#servicesdocker)", + "additionalProperties": false, + "properties": { + "platform": { + "type": "string", + "minLength": 1, + "description": "Image architecture to pull." + }, + "user": { + "type": "string", + "minLength": 1, + "maxLength": 255, + "description": "Username or UID to use for the container." + } + } + }, + "pull_policy": { + "markdownDescription": "Specifies how to pull the image in Runner. It can be one of `always`, `never` or `if-not-present`. The default value is `always`. [Learn more](https://docs.gitlab.com/ee/ci/yaml/#servicespull_policy).", + "default": "always", + "oneOf": [ + { + "type": "string", + "enum": [ + "always", + "never", + "if-not-present" + ] + }, + { + "type": "array", + "items": { + "type": "string", + "enum": [ + "always", + "never", + "if-not-present" + ] + }, + "minItems": 1, + "uniqueItems": true + } + ] + }, + "command": { + "type": "array", + "markdownDescription": "Command or script that should be used as the container's command. It will be translated to arguments passed to Docker after the image's name. The syntax is similar to Dockerfile's CMD directive, where each shell token is a separate string in the array. [Learn More](https://docs.gitlab.com/ee/ci/services/#available-settings-for-services)", + "minItems": 1, + "items": { + "type": "string" + } + }, + "alias": { + "type": "string", + "markdownDescription": "Additional alias that can be used to access the service from the job's container. Read Accessing the services for more information. [Learn More](https://docs.gitlab.com/ee/ci/services/#available-settings-for-services)", + "minLength": 1 + }, + "variables": { + "$ref": "#/definitions/jobVariables", + "markdownDescription": "Additional environment variables that are passed exclusively to the service. Service variables cannot reference themselves. [Learn More](https://docs.gitlab.com/ee/ci/services/#available-settings-for-services)" + } + }, + "required": [ + "name" + ] + } + ] + } + }, + "id_tokens": { + "type": "object", + "markdownDescription": "Defines JWTs to be injected as environment variables.", + "patternProperties": { + ".*": { + "type": "object", + "properties": { + "aud": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true + } + ] + } + }, + "required": [ + "aud" + ], + "additionalProperties": false + } + } + }, + "identity": { + "type": "string", + "markdownDescription": "Sets a workload identity (experimental), allowing automatic authentication with the external system. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#identity).", + "enum": [ + "google_cloud" + ] + }, + "secrets": { + "type": "object", + "markdownDescription": "Defines secrets to be injected as environment variables. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#secrets).", + "patternProperties": { + ".*": { + "type": "object", + "properties": { + "vault": { + "oneOf": [ + { + "type": "string", + "markdownDescription": "The secret to be fetched from Vault (e.g. 'production/db/password@ops' translates to secret 'ops/data/production/db', field `password`). [Learn More](https://docs.gitlab.com/ee/ci/yaml/#secretsvault)" + }, + { + "type": "object", + "properties": { + "engine": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "path": { + "type": "string" + } + }, + "required": [ + "name", + "path" + ] + }, + "path": { + "type": "string" + }, + "field": { + "type": "string" + } + }, + "required": [ + "engine", + "path", + "field" + ], + "additionalProperties": false + } + ] + }, + "gcp_secret_manager": { + "type": "object", + "markdownDescription": "Defines the secret version to be fetched from GCP Secret Manager. Name refers to the secret name in GCP secret manager. Version refers to the desired secret version (defaults to 'latest').", + "properties": { + "name": { + "type": "string" + }, + "version": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer" + } + ], + "default": "version" + } + }, + "required": [ + "name" + ], + "additionalProperties": false + }, + "azure_key_vault": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + } + }, + "required": [ + "name" + ], + "additionalProperties": false + }, + "akeyless": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "data_key": { + "type": "string" + }, + "cert_user_name": { + "type": "string" + }, + "public_key_data": { + "type": "string" + }, + "csr_data": { + "type": "string" + } + }, + "additionalProperties": false + }, + "file": { + "type": "boolean", + "default": true, + "markdownDescription": "Configures the secret to be stored as either a file or variable type CI/CD variable. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#secretsfile)" + }, + "token": { + "type": "string", + "description": "Specifies the JWT variable that should be used to authenticate with the secret provider." + } + }, + "anyOf": [ + { + "required": [ + "vault" + ] + }, + { + "required": [ + "azure_key_vault" + ] + }, + { + "required": [ + "gcp_secret_manager" + ] + }, + { + "required": [ + "akeyless" + ] + } + ], + "dependencies": { + "gcp_secret_manager": [ + "token" + ] + }, + "additionalProperties": false + } + } + }, + "script": { + "oneOf": [ + { + "type": "string", + "minLength": 1 + }, + { + "type": "array", + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "minItems": 1 + } + ] + }, + "steps": { + "type": "array", + "items": { + "$ref": "#/definitions/step" + } + }, + "optional_script": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + } + } + ] + }, + "before_script": { + "$ref": "#/definitions/optional_script", + "markdownDescription": "Defines scripts that should run *before* the job. Can be set globally or per job. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#before_script)." + }, + "after_script": { + "$ref": "#/definitions/optional_script", + "markdownDescription": "Defines scripts that should run *after* the job. Can be set globally or per job. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#after_script)." + }, + "rules": { + "type": [ + "array", + "null" + ], + "markdownDescription": "Rules allows for an array of individual rule objects to be evaluated in order, until one matches and dynamically provides attributes to the job. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#rules).", + "items": { + "anyOf": [ + { + "type": "object", + "additionalProperties": false, + "properties": { + "if": { + "$ref": "#/definitions/if" + }, + "changes": { + "$ref": "#/definitions/changes" + }, + "exists": { + "$ref": "#/definitions/exists" + }, + "variables": { + "$ref": "#/definitions/rulesVariables" + }, + "when": { + "$ref": "#/definitions/when" + }, + "start_in": { + "$ref": "#/definitions/start_in" + }, + "allow_failure": { + "$ref": "#/definitions/allow_failure" + }, + "needs": { + "$ref": "#/definitions/rulesNeeds" + }, + "interruptible": { + "$ref": "#/definitions/interruptible" + } + } + }, + { + "type": "string", + "minLength": 1 + }, + { + "type": "array", + "minItems": 1, + "items": { + "type": "string" + } + } + ] + } + }, + "includeRules": { + "type": [ + "array", + "null" + ], + "markdownDescription": "You can use rules to conditionally include other configuration files. [Learn More](https://docs.gitlab.com/ee/ci/yaml/includes.html#use-rules-with-include).", + "items": { + "anyOf": [ + { + "type": "object", + "additionalProperties": false, + "properties": { + "if": { + "$ref": "#/definitions/if" + }, + "changes": { + "$ref": "#/definitions/changes" + }, + "exists": { + "$ref": "#/definitions/exists" + }, + "when": { + "markdownDescription": "Use `when: never` to exclude the configuration file if the condition matches. [Learn More](https://docs.gitlab.com/ee/ci/yaml/includes.html#include-with-rulesif).", + "oneOf": [ + { + "type": "string", + "enum": [ + "never", + "always" + ] + }, + { + "type": "null" + } + ] + } + } + }, + { + "type": "string", + "minLength": 1 + }, + { + "type": "array", + "minItems": 1, + "items": { + "type": "string" + } + } + ] + } + }, + "workflowName": { + "type": "string", + "markdownDescription": "Defines the pipeline name. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#workflowname).", + "minLength": 1, + "maxLength": 255 + }, + "workflowAutoCancel": { + "type": "object", + "description": "Define the rules for when pipeline should be automatically cancelled.", + "additionalProperties": false, + "properties": { + "on_job_failure": { + "markdownDescription": "Define which jobs to stop after a job fails.", + "default": "none", + "type": "string", + "enum": [ + "none", + "all" + ] + }, + "on_new_commit": { + "markdownDescription": "Configure the behavior of the auto-cancel redundant pipelines feature. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#workflowauto_cancelon_new_commit)", + "type": "string", + "enum": [ + "conservative", + "interruptible", + "none" + ] + } + } + }, + "globalVariables": { + "markdownDescription": "Defines default variables for all jobs. Job level property overrides global variables. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variables).", + "type": "object", + "patternProperties": { + ".*": { + "oneOf": [ + { + "type": [ + "boolean", + "number", + "string" + ] + }, + { + "type": "object", + "properties": { + "value": { + "type": "string", + "markdownDescription": "Default value of the variable. If used with `options`, `value` must be included in the array. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variablesvalue)" + }, + "options": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1, + "uniqueItems": true, + "markdownDescription": "A list of predefined values that users can select from in the **Run pipeline** page when running a pipeline manually. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variablesoptions)" + }, + "description": { + "type": "string", + "markdownDescription": "Explains what the variable is used for, what the acceptable values are. Variables with `description` are prefilled when running a pipeline manually. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variablesdescription)." + }, + "expand": { + "type": "boolean", + "markdownDescription": "If the variable is expandable or not. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variablesexpand)." + } + }, + "additionalProperties": false + } + ] + } + } + }, + "jobVariables": { + "markdownDescription": "Defines variables for a job. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variables).", + "type": "object", + "patternProperties": { + ".*": { + "oneOf": [ + { + "type": [ + "boolean", + "number", + "string" + ] + }, + { + "type": "object", + "properties": { + "value": { + "type": "string" + }, + "expand": { + "type": "boolean", + "markdownDescription": "Defines if the variable is expandable or not. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#variablesexpand)." + } + }, + "additionalProperties": false + } + ] + } + } + }, + "rulesVariables": { + "markdownDescription": "Defines variables for a rule result. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#rulesvariables).", + "type": "object", + "patternProperties": { + ".*": { + "type": [ + "boolean", + "number", + "string" + ] + } + } + }, + "if": { + "type": "string", + "markdownDescription": "Expression to evaluate whether additional attributes should be provided to the job. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#rulesif)." + }, + "changes": { + "markdownDescription": "Additional attributes will be provided to job if any of the provided paths matches a modified file. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#ruleschanges).", + "anyOf": [ + { + "type": "object", + "additionalProperties": false, + "required": [ + "paths" + ], + "properties": { + "paths": { + "type": "array", + "description": "List of file paths.", + "items": { + "type": "string" + } + }, + "compare_to": { + "type": "string", + "description": "Ref for comparing changes." + } + } + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + }, + "exists": { + "markdownDescription": "Additional attributes will be provided to job if any of the provided paths matches an existing file in the repository. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#rulesexists).", + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "object", + "additionalProperties": false, + "required": [ + "paths" + ], + "properties": { + "paths": { + "type": "array", + "description": "List of file paths.", + "items": { + "type": "string" + } + }, + "project": { + "type": "string", + "description": "Path of the project to search in." + } + } + }, + { + "type": "object", + "additionalProperties": false, + "required": [ + "paths", + "project" + ], + "properties": { + "paths": { + "type": "array", + "description": "List of file paths.", + "items": { + "type": "string" + } + }, + "project": { + "type": "string", + "description": "Path of the project to search in." + }, + "ref": { + "type": "string", + "description": "Ref of the project to search in." + } + } + } + ] + }, + "timeout": { + "type": "string", + "markdownDescription": "Allows you to configure a timeout for a specific job (e.g. `1 minute`, `1h 30m 12s`). [Learn More](https://docs.gitlab.com/ee/ci/yaml/#timeout).", + "minLength": 1 + }, + "start_in": { + "type": "string", + "markdownDescription": "Used in conjunction with 'when: delayed' to set how long to delay before starting a job. e.g. '5', 5 seconds, 30 minutes, 1 week, etc. [Learn More](https://docs.gitlab.com/ee/ci/jobs/job_control.html#run-a-job-after-a-delay).", + "minLength": 1 + }, + "rulesNeeds": { + "markdownDescription": "Use needs in rules to update job needs for specific conditions. When a condition matches a rule, the job's needs configuration is completely replaced with the needs in the rule. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#rulesneeds).", + "type": "array", + "items": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "job": { + "type": "string", + "minLength": 1, + "description": "Name of a job that is defined in the pipeline." + }, + "artifacts": { + "type": "boolean", + "description": "Download artifacts of the job in needs." + }, + "optional": { + "type": "boolean", + "description": "Whether the job needs to be present in the pipeline to run ahead of the current job." + } + }, + "required": [ + "job" + ] + } + ] + } + }, + "allow_failure": { + "markdownDescription": "Allow job to fail. A failed job does not cause the pipeline to fail. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#allow_failure).", + "oneOf": [ + { + "description": "Setting this option to true will allow the job to fail while still letting the pipeline pass.", + "type": "boolean", + "default": false + }, + { + "description": "Exit code that are not considered failure. The job fails for any other exit code.", + "type": "object", + "additionalProperties": false, + "required": [ + "exit_codes" + ], + "properties": { + "exit_codes": { + "type": "integer" + } + } + }, + { + "description": "You can list which exit codes are not considered failures. The job fails for any other exit code.", + "type": "object", + "additionalProperties": false, + "required": [ + "exit_codes" + ], + "properties": { + "exit_codes": { + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "integer" + } + } + } + } + ] + }, + "parallel": { + "description": "Splits up a single job into multiple that run in parallel. Provides `CI_NODE_INDEX` and `CI_NODE_TOTAL` environment variables to the jobs.", + "oneOf": [ + { + "type": "integer", + "description": "Creates N instances of the job that run in parallel.", + "default": 0, + "minimum": 1, + "maximum": 200 + }, + { + "type": "object", + "properties": { + "matrix": { + "type": "array", + "description": "Defines different variables for jobs that are running in parallel.", + "items": { + "type": "object", + "description": "Defines the variables for a specific job.", + "additionalProperties": { + "type": [ + "string", + "number", + "array" + ] + } + }, + "maxItems": 200 + } + }, + "additionalProperties": false, + "required": [ + "matrix" + ] + } + ] + }, + "parallel_matrix": { + "description": "Use the `needs:parallel:matrix` keyword to specify parallelized jobs needed to be completed for the job to run. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#needsparallelmatrix)", + "oneOf": [ + { + "type": "object", + "properties": { + "matrix": { + "type": "array", + "description": "Defines different variables for jobs that are running in parallel.", + "items": { + "type": "object", + "description": "Defines the variables for a specific job.", + "additionalProperties": { + "type": [ + "string", + "number", + "array" + ] + } + }, + "maxItems": 200 + } + }, + "additionalProperties": false, + "required": [ + "matrix" + ] + } + ] + }, + "when": { + "markdownDescription": "Describes the conditions for when to run the job. Defaults to 'on_success'. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#when).", + "default": "on_success", + "type": "string", + "enum": [ + "on_success", + "on_failure", + "always", + "never", + "manual", + "delayed" + ] + }, + "cache": { + "markdownDescription": "Use `cache` to specify a list of files and directories to cache between jobs. You can only use paths that are in the local working copy. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cache)", + "oneOf": [ + { + "$ref": "#/definitions/cache_item" + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/cache_item" + } + } + ] + }, + "cache_item": { + "type": "object", + "properties": { + "key": { + "markdownDescription": "Use the `cache:key` keyword to give each cache a unique identifying key. All jobs that use the same cache key use the same cache, including in different pipelines. Must be used with `cache:path`, or nothing is cached. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachekey).", + "oneOf": [ + { + "type": "string", + "pattern": "^[^/]*[^./][^/]*$" + }, + { + "type": "object", + "properties": { + "files": { + "markdownDescription": "Use the `cache:key:files` keyword to generate a new key when one or two specific files change. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachekeyfiles)", + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1, + "maxItems": 2 + }, + "prefix": { + "markdownDescription": "Use `cache:key:prefix` to combine a prefix with the SHA computed for `cache:key:files`. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachekeyprefix)", + "type": "string" + } + } + } + ] + }, + "paths": { + "type": "array", + "markdownDescription": "Use the `cache:paths` keyword to choose which files or directories to cache. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachepaths)", + "items": { + "type": "string" + } + }, + "policy": { + "type": "string", + "markdownDescription": "Determines the strategy for downloading and updating the cache. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachepolicy)", + "default": "pull-push", + "pattern": "pull-push|pull|push|\\$\\w{1,255}" + }, + "unprotect": { + "type": "boolean", + "markdownDescription": "Use `unprotect: true` to set a cache to be shared between protected and unprotected branches.", + "default": false + }, + "untracked": { + "type": "boolean", + "markdownDescription": "Use `untracked: true` to cache all files that are untracked in your Git repository. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cacheuntracked)", + "default": false + }, + "when": { + "type": "string", + "markdownDescription": "Defines when to save the cache, based on the status of the job. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#cachewhen).", + "default": "on_success", + "enum": [ + "on_success", + "on_failure", + "always" + ] + }, + "fallback_keys": { + "type": "array", + "markdownDescription": "List of keys to download cache from if no cache hit occurred for key", + "items": { + "type": "string" + }, + "maxItems": 5 + } + } + }, + "filter_refs": { + "type": "array", + "description": "Filter job by different keywords that determine origin or state, or by supplying string/regex to check against branch/tag names.", + "items": { + "anyOf": [ + { + "oneOf": [ + { + "enum": [ + "branches" + ], + "description": "When a branch is pushed." + }, + { + "enum": [ + "tags" + ], + "description": "When a tag is pushed." + }, + { + "enum": [ + "api" + ], + "description": "When a pipeline has been triggered by a second pipelines API (not triggers API)." + }, + { + "enum": [ + "external" + ], + "description": "When using CI services other than Gitlab" + }, + { + "enum": [ + "pipelines" + ], + "description": "For multi-project triggers, created using the API with 'CI_JOB_TOKEN'." + }, + { + "enum": [ + "pushes" + ], + "description": "Pipeline is triggered by a `git push` by the user" + }, + { + "enum": [ + "schedules" + ], + "description": "For scheduled pipelines." + }, + { + "enum": [ + "triggers" + ], + "description": "For pipelines created using a trigger token." + }, + { + "enum": [ + "web" + ], + "description": "For pipelines created using *Run pipeline* button in Gitlab UI (under your project's *Pipelines*)." + } + ] + }, + { + "type": "string", + "description": "String or regular expression to match against tag or branch names." + } + ] + } + }, + "filter": { + "oneOf": [ + { + "type": "null" + }, + { + "$ref": "#/definitions/filter_refs" + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "refs": { + "$ref": "#/definitions/filter_refs" + }, + "kubernetes": { + "enum": [ + "active" + ], + "description": "Filter job based on if Kubernetes integration is active." + }, + "variables": { + "type": "array", + "markdownDescription": "Filter job by checking comparing values of CI/CD variables. [Learn More](https://docs.gitlab.com/ee/ci/jobs/job_control.html#cicd-variable-expressions).", + "items": { + "type": "string" + } + }, + "changes": { + "type": "array", + "description": "Filter job creation based on files that were modified in a git push.", + "items": { + "type": "string" + } + } + } + } + ] + }, + "retry": { + "markdownDescription": "Retry a job if it fails. Can be a simple integer or object definition. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#retry).", + "oneOf": [ + { + "$ref": "#/definitions/retry_max" + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "max": { + "$ref": "#/definitions/retry_max" + }, + "when": { + "markdownDescription": "Either a single or array of error types to trigger job retry. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#retrywhen).", + "oneOf": [ + { + "$ref": "#/definitions/retry_errors" + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/retry_errors" + } + } + ] + }, + "exit_codes": { + "markdownDescription": "Either a single or array of exit codes to trigger job retry on. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#retryexit_codes).", + "oneOf": [ + { + "description": "Retry when the job exit code is included in the array's values.", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "integer" + } + }, + { + "description": "Retry when the job exit code is equal to.", + "type": "integer" + } + ] + } + } + } + ] + }, + "retry_max": { + "type": "integer", + "description": "The number of times the job will be retried if it fails. Defaults to 0 and can max be retried 2 times (3 times total).", + "default": 0, + "minimum": 0, + "maximum": 2 + }, + "retry_errors": { + "oneOf": [ + { + "const": "always", + "description": "Retry on any failure (default)." + }, + { + "const": "unknown_failure", + "description": "Retry when the failure reason is unknown." + }, + { + "const": "script_failure", + "description": "Retry when the script failed." + }, + { + "const": "api_failure", + "description": "Retry on API failure." + }, + { + "const": "stuck_or_timeout_failure", + "description": "Retry when the job got stuck or timed out." + }, + { + "const": "runner_system_failure", + "description": "Retry if there is a runner system failure (for example, job setup failed)." + }, + { + "const": "runner_unsupported", + "description": "Retry if the runner is unsupported." + }, + { + "const": "stale_schedule", + "description": "Retry if a delayed job could not be executed." + }, + { + "const": "job_execution_timeout", + "description": "Retry if the script exceeded the maximum execution time set for the job." + }, + { + "const": "archived_failure", + "description": "Retry if the job is archived and can’t be run." + }, + { + "const": "unmet_prerequisites", + "description": "Retry if the job failed to complete prerequisite tasks." + }, + { + "const": "scheduler_failure", + "description": "Retry if the scheduler failed to assign the job to a runner." + }, + { + "const": "data_integrity_failure", + "description": "Retry if there is an unknown job problem." + } + ] + }, + "interruptible": { + "type": "boolean", + "markdownDescription": "Interruptible is used to indicate that a job should be canceled if made redundant by a newer pipeline run. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#interruptible).", + "default": false + }, + "inputs": { + "markdownDescription": "Used to pass input values to included templates, components, downstream pipelines, or child pipelines. [Learn More](https://docs.gitlab.com/ee/ci/yaml/inputs.html).", + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9_-]+$": { + "description": "Input parameter value that matches parameter names defined in spec:inputs of the included configuration.", + "oneOf": [ + { + "type": "string", + "maxLength": 1024 + }, + { + "type": "number" + }, + { + "type": "boolean" + }, + { + "type": "array", + "items": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "number" + }, + { + "type": "boolean" + }, + { + "type": "object", + "additionalProperties": true + }, + { + "type": "array", + "items": { + "additionalProperties": true + } + } + ] + } + }, + { + "type": "object", + "additionalProperties": true + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + "job": { + "allOf": [ + { + "$ref": "#/definitions/job_template" + } + ] + }, + "job_template": { + "type": "object", + "additionalProperties": false, + "properties": { + "image": { + "$ref": "#/definitions/image" + }, + "services": { + "$ref": "#/definitions/services" + }, + "before_script": { + "$ref": "#/definitions/before_script" + }, + "after_script": { + "$ref": "#/definitions/after_script" + }, + "hooks": { + "$ref": "#/definitions/hooks" + }, + "rules": { + "$ref": "#/definitions/rules" + }, + "variables": { + "$ref": "#/definitions/jobVariables" + }, + "cache": { + "$ref": "#/definitions/cache" + }, + "id_tokens": { + "$ref": "#/definitions/id_tokens" + }, + "identity": { + "$ref": "#/definitions/identity" + }, + "secrets": { + "$ref": "#/definitions/secrets" + }, + "script": { + "$ref": "#/definitions/script", + "markdownDescription": "Shell scripts executed by the Runner. The only required property of jobs. Be careful with special characters (e.g. `:`, `{`, `}`, `&`) and use single or double quotes to avoid issues. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#script)" + }, + "run": { + "$ref": "#/definitions/steps", + "markdownDescription": "Specifies a list of steps to execute in the job. The `run` keyword is an alternative to `script` and allows for more advanced job configuration. Each step is an object that defines a single task or command. Use either `run` or `script` in a job, but not both, otherwise the pipeline will error out." + }, + "stage": { + "description": "Define what stage the job will run in.", + "anyOf": [ + { + "type": "string", + "minLength": 1 + }, + { + "type": "array", + "minItems": 1, + "items": { + "type": "string" + } + } + ] + }, + "only": { + "$ref": "#/definitions/filter", + "description": "Job will run *only* when these filtering options match." + }, + "extends": { + "description": "The name of one or more jobs to inherit configuration from.", + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 1 + } + ] + }, + "needs": { + "description": "The list of jobs in previous stages whose sole completion is needed to start the current job.", + "type": "array", + "items": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "job": { + "type": "string" + }, + "artifacts": { + "type": "boolean" + }, + "optional": { + "type": "boolean" + }, + "parallel": { + "$ref": "#/definitions/parallel_matrix" + } + }, + "required": [ + "job" + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "pipeline": { + "type": "string" + }, + "job": { + "type": "string" + }, + "artifacts": { + "type": "boolean" + }, + "parallel": { + "$ref": "#/definitions/parallel_matrix" + } + }, + "required": [ + "job", + "pipeline" + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "job": { + "type": "string" + }, + "project": { + "type": "string" + }, + "ref": { + "type": "string" + }, + "artifacts": { + "type": "boolean" + }, + "parallel": { + "$ref": "#/definitions/parallel_matrix" + } + }, + "required": [ + "job", + "project", + "ref" + ] + }, + { + "$ref": "#/definitions/!reference" + } + ] + } + }, + "except": { + "$ref": "#/definitions/filter", + "description": "Job will run *except* for when these filtering options match." + }, + "tags": { + "$ref": "#/definitions/tags" + }, + "allow_failure": { + "$ref": "#/definitions/allow_failure" + }, + "timeout": { + "$ref": "#/definitions/timeout" + }, + "when": { + "$ref": "#/definitions/when" + }, + "start_in": { + "$ref": "#/definitions/start_in" + }, + "manual_confirmation": { + "markdownDescription": "Describes the Custom confirmation message for a manual job [Learn More](https://docs.gitlab.com/ee/ci/yaml/#when).", + "type": "string" + }, + "dependencies": { + "type": "array", + "description": "Specify a list of job names from earlier stages from which artifacts should be loaded. By default, all previous artifacts are passed. Use an empty array to skip downloading artifacts.", + "items": { + "type": "string" + } + }, + "artifacts": { + "$ref": "#/definitions/artifacts" + }, + "environment": { + "description": "Used to associate environment metadata with a deploy. Environment can have a name and URL attached to it, and will be displayed under /environments under the project.", + "oneOf": [ + { + "type": "string" + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "description": "The name of the environment, e.g. 'qa', 'staging', 'production'.", + "minLength": 1 + }, + "url": { + "type": "string", + "description": "When set, this will expose buttons in various places for the current environment in Gitlab, that will take you to the defined URL.", + "format": "uri", + "pattern": "^(https?://.+|\\$[A-Za-z]+)" + }, + "on_stop": { + "type": "string", + "description": "The name of a job to execute when the environment is about to be stopped." + }, + "action": { + "enum": [ + "start", + "prepare", + "stop", + "verify", + "access" + ], + "description": "Specifies what this job will do. 'start' (default) indicates the job will start the deployment. 'prepare'/'verify'/'access' indicates this will not affect the deployment. 'stop' indicates this will stop the deployment.", + "default": "start" + }, + "auto_stop_in": { + "type": "string", + "description": "The amount of time it should take before Gitlab will automatically stop the environment. Supports a wide variety of formats, e.g. '1 week', '3 mins 4 sec', '2 hrs 20 min', '2h20min', '6 mos 1 day', '47 yrs 6 mos and 4d', '3 weeks and 2 days'." + }, + "kubernetes": { + "type": "object", + "description": "Used to configure the kubernetes deployment for this environment. This is currently not supported for kubernetes clusters that are managed by Gitlab.", + "properties": { + "namespace": { + "type": "string", + "description": "The kubernetes namespace where this environment should be deployed to.", + "minLength": 1 + }, + "agent": { + "type": "string", + "description": "Specifies the Gitlab Agent for Kubernetes. The format is `path/to/agent/project:agent-name`." + }, + "flux_resource_path": { + "type": "string", + "description": "The Flux resource path to associate with this environment. This must be the full resource path. For example, 'helm.toolkit.fluxcd.io/v2/namespaces/gitlab-agent/helmreleases/gitlab-agent'." + } + } + }, + "deployment_tier": { + "type": "string", + "description": "Explicitly specifies the tier of the deployment environment if non-standard environment name is used.", + "enum": [ + "production", + "staging", + "testing", + "development", + "other" + ] + } + }, + "required": [ + "name" + ] + } + ] + }, + "release": { + "type": "object", + "description": "Indicates that the job creates a Release.", + "additionalProperties": false, + "properties": { + "tag_name": { + "type": "string", + "description": "The tag_name must be specified. It can refer to an existing Git tag or can be specified by the user.", + "minLength": 1 + }, + "tag_message": { + "type": "string", + "description": "Message to use if creating a new annotated tag." + }, + "description": { + "type": "string", + "description": "Specifies the longer description of the Release.", + "minLength": 1 + }, + "name": { + "type": "string", + "description": "The Release name. If omitted, it is populated with the value of release: tag_name." + }, + "ref": { + "type": "string", + "description": "If the release: tag_name doesn’t exist yet, the release is created from ref. ref can be a commit SHA, another tag name, or a branch name." + }, + "milestones": { + "type": "array", + "description": "The title of each milestone the release is associated with.", + "items": { + "type": "string" + } + }, + "released_at": { + "type": "string", + "description": "The date and time when the release is ready. Defaults to the current date and time if not defined. Should be enclosed in quotes and expressed in ISO 8601 format.", + "format": "date-time", + "pattern": "^(?:[1-9]\\d{3}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1\\d|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[1-9]\\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)-02-29)T(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:Z|[+-][01]\\d:[0-5]\\d)$" + }, + "assets": { + "type": "object", + "additionalProperties": false, + "properties": { + "links": { + "type": "array", + "description": "Include asset links in the release.", + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "description": "The name of the link.", + "minLength": 1 + }, + "url": { + "type": "string", + "description": "The URL to download a file.", + "minLength": 1 + }, + "filepath": { + "type": "string", + "description": "The redirect link to the url." + }, + "link_type": { + "type": "string", + "description": "The content kind of what users can download via url.", + "enum": [ + "runbook", + "package", + "image", + "other" + ] + } + }, + "required": [ + "name", + "url" + ] + }, + "minItems": 1 + } + }, + "required": [ + "links" + ] + } + }, + "required": [ + "tag_name", + "description" + ] + }, + "coverage": { + "type": "string", + "description": "Must be a regular expression, optionally but recommended to be quoted, and must be surrounded with '/'. Example: '/Code coverage: \\d+\\.\\d+/'", + "format": "regex", + "pattern": "^/.+/$" + }, + "retry": { + "$ref": "#/definitions/retry" + }, + "parallel": { + "$ref": "#/definitions/parallel" + }, + "interruptible": { + "$ref": "#/definitions/interruptible" + }, + "resource_group": { + "type": "string", + "description": "Limit job concurrency. Can be used to ensure that the Runner will not run certain jobs simultaneously." + }, + "trigger": { + "markdownDescription": "Trigger allows you to define downstream pipeline trigger. When a job created from trigger definition is started by GitLab, a downstream pipeline gets created. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#trigger).", + "oneOf": [ + { + "type": "object", + "markdownDescription": "Trigger a multi-project pipeline. [Learn More](https://docs.gitlab.com/ci/pipelines/downstream_pipelines/#multi-project-pipelines).", + "additionalProperties": false, + "properties": { + "project": { + "description": "Path to the project, e.g. `group/project`, or `group/sub-group/project`.", + "type": "string", + "pattern": "(?:\\S/\\S|\\$\\S+)" + }, + "branch": { + "description": "The branch name that a downstream pipeline will use", + "type": "string" + }, + "strategy": { + "description": "You can mirror the pipeline status from the triggered pipeline to the source bridge job by using strategy: depend", + "type": "string", + "enum": [ + "depend" + ] + }, + "inputs": { + "$ref": "#/definitions/inputs" + }, + "forward": { + "description": "Specify what to forward to the downstream pipeline.", + "type": "object", + "additionalProperties": false, + "properties": { + "yaml_variables": { + "type": "boolean", + "description": "Variables defined in the trigger job are passed to downstream pipelines.", + "default": true + }, + "pipeline_variables": { + "type": "boolean", + "description": "Variables added for manual pipeline runs and scheduled pipelines are passed to downstream pipelines.", + "default": false + } + } + } + }, + "required": [ + "project" + ], + "dependencies": { + "branch": [ + "project" + ] + } + }, + { + "type": "object", + "description": "Trigger a child pipeline. [Learn More](https://docs.gitlab.com/ci/pipelines/downstream_pipelines/#parent-child-pipelines).", + "additionalProperties": false, + "properties": { + "include": { + "oneOf": [ + { + "description": "Relative path from local repository root (`/`) to the local YAML file to define the pipeline configuration.", + "type": "string", + "format": "uri-reference", + "pattern": "\\.ya?ml$" + }, + { + "type": "array", + "description": "References a local file or an artifact from another job to define the pipeline configuration.", + "maxItems": 3, + "items": { + "oneOf": [ + { + "type": "object", + "additionalProperties": false, + "properties": { + "local": { + "description": "Relative path from local repository root (`/`) to the local YAML file to define the pipeline configuration.", + "type": "string", + "format": "uri-reference", + "pattern": "\\.ya?ml$" + }, + "inputs": { + "$ref": "#/definitions/inputs" + } + }, + "required": [ + "local" + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "template": { + "description": "Name of the template YAML file to use in the pipeline configuration.", + "type": "string", + "format": "uri-reference", + "pattern": "\\.ya?ml$" + }, + "inputs": { + "$ref": "#/definitions/inputs" + } + }, + "required": [ + "template" + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "artifact": { + "description": "Relative path to the generated YAML file which is extracted from the artifacts and used as the configuration for triggering the child pipeline.", + "type": "string", + "format": "uri-reference", + "pattern": "\\.ya?ml$" + }, + "job": { + "description": "Job name which generates the artifact", + "type": "string" + }, + "inputs": { + "$ref": "#/definitions/inputs" + } + }, + "required": [ + "artifact", + "job" + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "project": { + "description": "Path to another private project under the same GitLab instance, like `group/project` or `group/sub-group/project`.", + "type": "string", + "pattern": "(?:\\S/\\S|\\$\\S+)" + }, + "ref": { + "description": "Branch/Tag/Commit hash for the target project.", + "minLength": 1, + "type": "string" + }, + "file": { + "description": "Relative path from repository root (`/`) to the pipeline configuration YAML file.", + "type": "string", + "format": "uri-reference", + "pattern": "\\.ya?ml$" + }, + "inputs": { + "$ref": "#/definitions/inputs" + } + }, + "required": [ + "project", + "file" + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "component": { + "description": "Local path to component directory or full path to external component directory.", + "type": "string", + "format": "uri-reference" + }, + "inputs": { + "$ref": "#/definitions/inputs" + } + }, + "required": [ + "component" + ] + }, + { + "type": "object", + "additionalProperties": false, + "properties": { + "remote": { + "description": "URL to a `yaml`/`yml` template file using HTTP/HTTPS.", + "type": "string", + "format": "uri-reference", + "pattern": "^https?://.+\\.ya?ml$" + }, + "inputs": { + "$ref": "#/definitions/inputs" + } + }, + "required": [ + "remote" + ] + } + ] + } + } + ] + }, + "strategy": { + "description": "You can mirror the pipeline status from the triggered pipeline to the source bridge job by using strategy: depend", + "type": "string", + "enum": [ + "depend" + ] + }, + "forward": { + "description": "Specify what to forward to the downstream pipeline.", + "type": "object", + "additionalProperties": false, + "properties": { + "yaml_variables": { + "type": "boolean", + "description": "Variables defined in the trigger job are passed to downstream pipelines.", + "default": true + }, + "pipeline_variables": { + "type": "boolean", + "description": "Variables added for manual pipeline runs and scheduled pipelines are passed to downstream pipelines.", + "default": false + } + } + } + } + }, + { + "markdownDescription": "Path to the project, e.g. `group/project`, or `group/sub-group/project`. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#trigger).", + "type": "string", + "pattern": "(?:\\S/\\S|\\$\\S+)" + } + ] + }, + "inherit": { + "type": "object", + "markdownDescription": "Controls inheritance of globally-defined defaults and variables. Boolean values control inheritance of all default: or variables: keywords. To inherit only a subset of default: or variables: keywords, specify what you wish to inherit. Anything not listed is not inherited. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#inherit).", + "properties": { + "default": { + "markdownDescription": "Whether to inherit all globally-defined defaults or not. Or subset of inherited defaults. [Learn more](https://docs.gitlab.com/ee/ci/yaml/#inheritdefault).", + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "array", + "items": { + "type": "string", + "enum": [ + "after_script", + "artifacts", + "before_script", + "cache", + "image", + "interruptible", + "retry", + "services", + "tags", + "timeout" + ] + } + } + ] + }, + "variables": { + "markdownDescription": "Whether to inherit all globally-defined variables or not. Or subset of inherited variables. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#inheritvariables).", + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ] + } + }, + "additionalProperties": false + }, + "publish": { + "description": "Deprecated. Use `pages.publish` instead. A path to a directory that contains the files to be published with Pages.", + "type": "string" + }, + "pages": { + "oneOf": [ + { + "type": "object", + "additionalProperties": false, + "properties": { + "path_prefix": { + "type": "string", + "markdownDescription": "The GitLab Pages URL path prefix used in this version of pages. The given value is converted to lowercase, shortened to 63 bytes, and everything except alphanumeric characters is replaced with a hyphen. Leading and trailing hyphens are not permitted." + }, + "expire_in": { + "type": "string", + "markdownDescription": "How long the deployment should be active. Deployments that have expired are no longer available on the web. Supports a wide variety of formats, e.g. '1 week', '3 mins 4 sec', '2 hrs 20 min', '2h20min', '6 mos 1 day', '47 yrs 6 mos and 4d', '3 weeks and 2 days'. Set to 'never' to prevent extra deployments from expiring. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#pagesexpire_in)." + }, + "publish": { + "type": "string", + "markdownDescription": "A path to a directory that contains the files to be published with Pages." + } + } + }, + { + "type": "boolean", + "markdownDescription": "Whether this job should trigger a Pages deploy (Replaces the need to name the job `pages`)", + "default": false + } + ] + } + }, + "oneOf": [ + { + "properties": { + "when": { + "enum": [ + "delayed" + ] + } + }, + "required": [ + "when", + "start_in" + ] + }, + { + "properties": { + "when": { + "not": { + "enum": [ + "delayed" + ] + } + } + } + } + ] + }, + "tags": { + "type": "array", + "minItems": 1, + "markdownDescription": "Used to select runners from the list of available runners. A runner must have all tags listed here to run the job. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#tags).", + "items": { + "anyOf": [ + { + "type": "string", + "minLength": 1 + }, + { + "type": "array", + "minItems": 1, + "items": { + "type": "string" + } + } + ] + } + }, + "hooks": { + "type": "object", + "markdownDescription": "Specifies lists of commands to execute on the runner at certain stages of job execution. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#hooks).", + "properties": { + "pre_get_sources_script": { + "$ref": "#/definitions/optional_script", + "markdownDescription": "Specifies a list of commands to execute on the runner before updating the Git repository and any submodules. [Learn More](https://docs.gitlab.com/ee/ci/yaml/#hookspre_get_sources_script)." + } + }, + "additionalProperties": false + }, + "step": { + "description": "Any of these step use cases are valid.", + "oneOf": [ + { + "description": "Run a referenced step.", + "type": "object", + "additionalProperties": false, + "required": [ + "name", + "step" + ], + "properties": { + "name": { + "$ref": "#/definitions/stepName" + }, + "env": { + "$ref": "#/definitions/stepNamedStrings" + }, + "inputs": { + "$ref": "#/definitions/stepNamedValues" + }, + "step": { + "oneOf": [ + { + "type": "string" + }, + { + "$ref": "#/definitions/stepGitReference" + }, + { + "$ref": "#/definitions/stepOciReference" + } + ] + } + } + }, + { + "description": "Run a sequence of steps.", + "oneOf": [ + { + "type": "object", + "additionalProperties": false, + "required": [ + "run" + ], + "properties": { + "env": { + "$ref": "#/definitions/stepNamedStrings" + }, + "run": { + "type": "array", + "items": { + "$ref": "#/definitions/step" + } + }, + "outputs": { + "$ref": "#/definitions/stepNamedValues" + }, + "delegate": { + "type": "string" + } + } + } + ] + }, + { + "description": "Run an action.", + "type": "object", + "additionalProperties": false, + "required": [ + "name", + "action" + ], + "properties": { + "name": { + "$ref": "#/definitions/stepName" + }, + "env": { + "$ref": "#/definitions/stepNamedStrings" + }, + "inputs": { + "$ref": "#/definitions/stepNamedValues" + }, + "action": { + "type": "string", + "minLength": 1 + } + } + }, + { + "description": "Run a script.", + "type": "object", + "additionalProperties": false, + "required": [ + "name", + "script" + ], + "properties": { + "name": { + "$ref": "#/definitions/stepName" + }, + "env": { + "$ref": "#/definitions/stepNamedStrings" + }, + "script": { + "type": "string", + "minLength": 1 + } + } + }, + { + "description": "Exec a binary.", + "type": "object", + "additionalProperties": false, + "required": [ + "exec" + ], + "properties": { + "env": { + "$ref": "#/definitions/stepNamedStrings" + }, + "exec": { + "description": "Exec is a command to run.", + "$ref": "#/definitions/stepExec" + } + } + } + ] + }, + "stepName": { + "type": "string", + "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$" + }, + "stepNamedStrings": { + "type": "object", + "patternProperties": { + "^[a-zA-Z_][a-zA-Z0-9_]*$": { + "type": "string" + } + }, + "additionalProperties": false + }, + "stepNamedValues": { + "type": "object", + "patternProperties": { + "^[a-zA-Z_][a-zA-Z0-9_]*$": { + "type": [ + "string", + "number", + "boolean", + "null", + "array", + "object" + ] + } + }, + "additionalProperties": false + }, + "stepGitReference": { + "type": "object", + "description": "GitReference is a reference to a step in a Git repository.", + "additionalProperties": false, + "required": [ + "git" + ], + "properties": { + "git": { + "type": "object", + "additionalProperties": false, + "required": [ + "url", + "rev" + ], + "properties": { + "url": { + "type": "string" + }, + "dir": { + "type": "string" + }, + "rev": { + "type": "string" + }, + "file": { + "type": "string" + } + } + } + } + }, + "stepOciReference": { + "type": "object", + "description": "OCIReference is a reference to a step hosted in an OCI repository.", + "additionalProperties": false, + "required": [ + "oci" + ], + "properties": { + "oci": { + "type": "object", + "additionalProperties": false, + "required": [ + "registry", + "repository", + "tag" + ], + "properties": { + "registry": { + "type": "string", + "description": "The [:] of the container registry server.", + "examples": [ + "registry.gitlab.com" + ] + }, + "repository": { + "type": "string", + "description": "A path within the registry containing related OCI images. Typically the namespace, project, and image name.", + "examples": [ + "my_group/my_project/image" + ] + }, + "tag": { + "type": "string", + "description": "A pointer to the image manifest hosted in the OCI repository.", + "examples": [ + "latest", + "1", + "1.5", + "1.5.0" + ] + }, + "dir": { + "type": "string", + "description": "A directory inside the OCI image where the step can be found.", + "examples": [ + "/my_steps/hello_world" + ] + }, + "file": { + "type": "string", + "description": "The name of the file that defines the step, defaults to step.yml.", + "examples": [ + "step.yml" + ] + } + } + } + } + }, + "stepExec": { + "type": "object", + "additionalProperties": false, + "required": [ + "command" + ], + "properties": { + "command": { + "type": "array", + "description": "Command are the parameters to the system exec API. It does not invoke a shell.", + "items": { + "type": "string" + }, + "minItems": 1 + }, + "work_dir": { + "type": "string", + "description": "WorkDir is the working directly in which `command` will be exec'ed." + } + } + } + } +} diff --git a/test_gitlab_ci/.gitlab/ci/build.yml b/test_gitlab_ci/.gitlab/ci/build.yml new file mode 100644 index 0000000..1773c55 --- /dev/null +++ b/test_gitlab_ci/.gitlab/ci/build.yml @@ -0,0 +1,33 @@ +.build-template: + stage: build + script: + - cargo build --release + artifacts: + paths: + - target/release/ + expire_in: 1 week + cache: + key: + files: + - Cargo.lock + paths: + - ${CARGO_HOME} + - target/ + +# Normal build job +build: + extends: .build-template + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH == "main" + +# Debug build with additional flags +debug-build: + extends: .build-template + script: + - cargo build --features debug + variables: + RUSTFLAGS: "-Z debug-info=2" + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" && $DEBUG_BUILD == "true" + when: manual \ No newline at end of file diff --git a/test_gitlab_ci/.gitlab/ci/test.yml b/test_gitlab_ci/.gitlab/ci/test.yml new file mode 100644 index 0000000..161b6f1 --- /dev/null +++ b/test_gitlab_ci/.gitlab/ci/test.yml @@ -0,0 +1,63 @@ +.test-template: + stage: test + dependencies: + - build + cache: + key: + files: + - Cargo.lock + paths: + - ${CARGO_HOME} + - target/ + +# Unit tests +unit-tests: + extends: .test-template + script: + - cargo test --lib + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH == "main" + +# Integration tests +integration-tests: + extends: .test-template + script: + - cargo test --test '*' + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH == "main" + +# Lint with clippy +lint: + extends: .test-template + dependencies: [] # No dependencies needed for linting + script: + - rustup component add clippy + - cargo clippy -- -D warnings + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH == "main" + +# Check formatting +format: + extends: .test-template + dependencies: [] # No dependencies needed for formatting + script: + - rustup component add rustfmt + - cargo fmt -- --check + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH == "main" + +# Deployment template +.deploy-template: + stage: deploy + script: + - echo "Deploying to ${ENVIRONMENT} environment" + - cp target/release/wrkflw /tmp/wrkflw-${ENVIRONMENT} + artifacts: + paths: + - /tmp/wrkflw-${ENVIRONMENT} + dependencies: + - build \ No newline at end of file diff --git a/test_gitlab_ci/advanced.gitlab-ci.yml b/test_gitlab_ci/advanced.gitlab-ci.yml new file mode 100644 index 0000000..1df2791 --- /dev/null +++ b/test_gitlab_ci/advanced.gitlab-ci.yml @@ -0,0 +1,197 @@ +stages: + - setup + - build + - test + - package + - deploy + +variables: + CARGO_HOME: "${CI_PROJECT_DIR}/.cargo" + RUST_BACKTRACE: "1" + +workflow: + rules: + - if: $CI_COMMIT_BRANCH == "main" + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/ + - if: $CI_COMMIT_BRANCH =~ /^feature\/.*/ + - if: $CI_COMMIT_BRANCH == "staging" + +# Default image and settings for all jobs +default: + image: rust:1.76 + interruptible: true + retry: + max: 2 + when: + - runner_system_failure + - stuck_or_timeout_failure + +# Cache configuration +.cargo-cache: + cache: + key: + files: + - Cargo.lock + paths: + - ${CARGO_HOME} + - target/ + policy: pull-push + +# Job to initialize the environment +setup: + stage: setup + extends: .cargo-cache + cache: + policy: push + script: + - cargo --version + - rustc --version + - cargo fetch + artifacts: + paths: + - Cargo.lock + +# Matrix build for multiple platforms +.build-matrix: + stage: build + extends: .cargo-cache + needs: + - setup + parallel: + matrix: + - TARGET: + - x86_64-unknown-linux-gnu + - x86_64-apple-darwin + - aarch64-apple-darwin + - x86_64-pc-windows-msvc + RUST_VERSION: + - "1.75" + - "1.76" + script: + - rustup target add $TARGET + - cargo build --release --target $TARGET + artifacts: + paths: + - target/$TARGET/release/ + expire_in: 1 week + rules: + - if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_TAG + when: always + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + when: manual + allow_failure: true + +# Regular build job for most cases +build: + stage: build + extends: .cargo-cache + needs: + - setup + script: + - cargo build --release + artifacts: + paths: + - target/release/ + expire_in: 1 week + rules: + - if: $CI_COMMIT_BRANCH != "main" && !$CI_COMMIT_TAG + when: always + +# Test with different feature combinations +.test-template: + stage: test + extends: .cargo-cache + needs: + - build + artifacts: + reports: + junit: test-results.xml + when: always + +test-default: + extends: .test-template + script: + - cargo test -- -Z unstable-options --format json | tee test-output.json + - cat test-output.json | jq -r '.[]' > test-results.xml + +test-all-features: + extends: .test-template + script: + - cargo test --all-features -- -Z unstable-options --format json | tee test-output.json + - cat test-output.json | jq -r '.[]' > test-results.xml + +test-no-features: + extends: .test-template + script: + - cargo test --no-default-features -- -Z unstable-options --format json | tee test-output.json + - cat test-output.json | jq -r '.[]' > test-results.xml + +# Security scanning +security: + stage: test + extends: .cargo-cache + needs: + - build + script: + - cargo install cargo-audit || true + - cargo audit + allow_failure: true + +# Linting +lint: + stage: test + extends: .cargo-cache + script: + - rustup component add clippy + - cargo clippy -- -D warnings + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + +# Package for different targets +package: + stage: package + extends: .cargo-cache + needs: + - job: build + artifacts: true + - test-default + - test-all-features + script: + - mkdir -p packages + - tar -czf packages/wrkflw-${CI_COMMIT_REF_SLUG}.tar.gz -C target/release wrkflw + artifacts: + paths: + - packages/ + only: + - main + - tags + +# Deploy to staging +deploy-staging: + stage: deploy + image: alpine + needs: + - package + environment: + name: staging + script: + - apk add --no-cache curl + - curl -X POST -F "file=@packages/wrkflw-${CI_COMMIT_REF_SLUG}.tar.gz" ${STAGING_DEPLOY_URL} + only: + - staging + +# Deploy to production +deploy-production: + stage: deploy + image: alpine + needs: + - package + environment: + name: production + script: + - apk add --no-cache curl + - curl -X POST -F "file=@packages/wrkflw-${CI_COMMIT_REF_SLUG}.tar.gz" ${PROD_DEPLOY_URL} + only: + - tags + when: manual \ No newline at end of file diff --git a/test_gitlab_ci/basic.gitlab-ci.yml b/test_gitlab_ci/basic.gitlab-ci.yml new file mode 100644 index 0000000..24d0aed --- /dev/null +++ b/test_gitlab_ci/basic.gitlab-ci.yml @@ -0,0 +1,45 @@ +stages: + - build + - test + - deploy + +variables: + CARGO_HOME: "${CI_PROJECT_DIR}/.cargo" + +# Default image for all jobs +image: rust:1.76 + +build: + stage: build + script: + - cargo build --release + artifacts: + paths: + - target/release/ + expire_in: 1 week + +test: + stage: test + script: + - cargo test + dependencies: + - build + +lint: + stage: test + script: + - rustup component add clippy + - cargo clippy -- -D warnings + - cargo fmt -- --check + +deploy: + stage: deploy + script: + - echo "Deploying application..." + - cp target/release/wrkflw /usr/local/bin/ + only: + - main + environment: + name: production + dependencies: + - build \ No newline at end of file diff --git a/test_gitlab_ci/docker.gitlab-ci.yml b/test_gitlab_ci/docker.gitlab-ci.yml new file mode 100644 index 0000000..9076eba --- /dev/null +++ b/test_gitlab_ci/docker.gitlab-ci.yml @@ -0,0 +1,97 @@ +stages: + - build + - test + - deploy + +variables: + DOCKER_DRIVER: overlay2 + DOCKER_TLS_CERTDIR: "/certs" + CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG} + CONTAINER_IMAGE_LATEST: ${CI_REGISTRY_IMAGE}:latest + +# Use Docker-in-Docker for building and testing +.docker: + image: docker:20.10 + services: + - docker:20.10-dind + variables: + DOCKER_HOST: tcp://docker:2376 + DOCKER_TLS_VERIFY: 1 + DOCKER_CERT_PATH: $DOCKER_TLS_CERTDIR/client + before_script: + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + +# Build the Docker image +build-docker: + extends: .docker + stage: build + script: + - docker build --pull -t $CONTAINER_IMAGE -t $CONTAINER_IMAGE_LATEST . + - docker push $CONTAINER_IMAGE + - docker push $CONTAINER_IMAGE_LATEST + only: + - main + - tags + +# Run tests inside Docker +test-docker: + extends: .docker + stage: test + script: + - docker pull $CONTAINER_IMAGE + - docker run --rm $CONTAINER_IMAGE cargo test + dependencies: + - build-docker + +# Security scan the Docker image +security-scan: + extends: .docker + stage: test + image: aquasec/trivy:latest + script: + - trivy image --no-progress --exit-code 1 --severity HIGH,CRITICAL $CONTAINER_IMAGE + allow_failure: true + +# Run a Docker container with our app in the staging environment +deploy-staging: + extends: .docker + stage: deploy + environment: + name: staging + url: https://staging.example.com + script: + - docker pull $CONTAINER_IMAGE + - docker tag $CONTAINER_IMAGE wrkflw-staging + - | + cat > deploy.sh << 'EOF' + docker stop wrkflw-staging || true + docker rm wrkflw-staging || true + docker run -d --name wrkflw-staging -p 8080:8080 wrkflw-staging + EOF + - chmod +x deploy.sh + - ssh $STAGING_USER@$STAGING_HOST 'bash -s' < deploy.sh + only: + - main + when: manual + +# Run a Docker container with our app in the production environment +deploy-production: + extends: .docker + stage: deploy + environment: + name: production + url: https://wrkflw.example.com + script: + - docker pull $CONTAINER_IMAGE + - docker tag $CONTAINER_IMAGE wrkflw-production + - | + cat > deploy.sh << 'EOF' + docker stop wrkflw-production || true + docker rm wrkflw-production || true + docker run -d --name wrkflw-production -p 80:8080 wrkflw-production + EOF + - chmod +x deploy.sh + - ssh $PRODUCTION_USER@$PRODUCTION_HOST 'bash -s' < deploy.sh + only: + - tags + when: manual \ No newline at end of file diff --git a/test_gitlab_ci/includes.gitlab-ci.yml b/test_gitlab_ci/includes.gitlab-ci.yml new file mode 100644 index 0000000..dd20fae --- /dev/null +++ b/test_gitlab_ci/includes.gitlab-ci.yml @@ -0,0 +1,40 @@ +stages: + - build + - test + - deploy + +# Including external files +include: + - local: '.gitlab/ci/build.yml' # Will be created in a moment + - local: '.gitlab/ci/test.yml' # Will be created in a moment + - template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml' # Built-in template + +variables: + RUST_VERSION: "1.76" + CARGO_HOME: "${CI_PROJECT_DIR}/.cargo" + +# Default settings for all jobs +default: + image: rust:${RUST_VERSION} + before_script: + - rustc --version + - cargo --version + +# Main pipeline jobs that use the included templates +production_deploy: + stage: deploy + extends: .deploy-template # This template is defined in one of the included files + variables: + ENVIRONMENT: production + only: + - main + when: manual + +staging_deploy: + stage: deploy + extends: .deploy-template + variables: + ENVIRONMENT: staging + only: + - staging + when: manual \ No newline at end of file diff --git a/test_gitlab_ci/invalid.gitlab-ci.yml b/test_gitlab_ci/invalid.gitlab-ci.yml new file mode 100644 index 0000000..08c1602 --- /dev/null +++ b/test_gitlab_ci/invalid.gitlab-ci.yml @@ -0,0 +1,57 @@ +# Invalid GitLab CI file with common mistakes + +# Missing stages definition +# stages: +# - build +# - test + +variables: + CARGO_HOME: ${CI_PROJECT_DIR}/.cargo # Missing quotes around value with variables + +# Invalid job definition (missing script) +build: + stage: build # Referring to undefined stage + # Missing required script section + artifacts: + paths: + - target/release/ + expire_in: 1 week + +# Invalid job with incorrect when value +test: + stage: test + script: + - cargo test + when: never # Invalid value for when (should be always, manual, or delayed) + dependencies: + - non_existent_job # Dependency on non-existent job + +# Improperly structured job with invalid keys +deploy: + stagee: deploy # Typo in stage key + scriptt: # Typo in script key + - echo "Deploying..." + only: + - main + environment: + production # Incorrect format for environment + retry: hello # Incorrect type for retry (should be integer or object) + +# Invalid rules section +lint: + stage: test + script: + - cargo clippy + rules: + - equals: $CI_COMMIT_BRANCH == "main" # Invalid rule (should be if, changes, exists, etc.) + +# Job with invalid cache configuration +cache-test: + stage: test + script: + - echo "Testing cache" + cache: + paths: + - ${CARGO_HOME} + key: [invalid, key, type] # Invalid type for key (should be string) + policy: invalid-policy # Invalid policy value \ No newline at end of file diff --git a/test_gitlab_ci/minimal.gitlab-ci.yml b/test_gitlab_ci/minimal.gitlab-ci.yml new file mode 100644 index 0000000..224c139 --- /dev/null +++ b/test_gitlab_ci/minimal.gitlab-ci.yml @@ -0,0 +1,11 @@ +# Minimal GitLab CI configuration + +image: rust:latest + +build: + script: + - cargo build + +test: + script: + - cargo test \ No newline at end of file diff --git a/test_gitlab_ci/services.gitlab-ci.yml b/test_gitlab_ci/services.gitlab-ci.yml new file mode 100644 index 0000000..70f0e6b --- /dev/null +++ b/test_gitlab_ci/services.gitlab-ci.yml @@ -0,0 +1,167 @@ +stages: + - build + - test + - deploy + +variables: + POSTGRES_DB: test_db + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_HOST: postgres + REDIS_HOST: redis + MONGO_HOST: mongo + RUST_BACKTRACE: 1 + +# Default settings +default: + image: rust:1.76 + +# Build the application +build: + stage: build + script: + - cargo build --release + artifacts: + paths: + - target/release/ + cache: + key: + files: + - Cargo.lock + paths: + - ${CI_PROJECT_DIR}/.cargo + - target/ + +# Run unit tests (no services needed) +unit-tests: + stage: test + needs: + - build + script: + - cargo test --lib + cache: + key: + files: + - Cargo.lock + paths: + - ${CI_PROJECT_DIR}/.cargo + - target/ + policy: pull + +# Run integration tests with a PostgreSQL service +postgres-tests: + stage: test + needs: + - build + services: + - name: postgres:14-alpine + alias: postgres + variables: + # Service-specific variables + POSTGRES_DB: test_db + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + DATABASE_URL: postgres://postgres:postgres@postgres:5432/test_db + script: + - apt-get update && apt-get install -y postgresql-client + - cd target/release && ./wrkflw test-postgres + - psql -h postgres -U postgres -d test_db -c "SELECT 1;" + cache: + key: + files: + - Cargo.lock + paths: + - ${CI_PROJECT_DIR}/.cargo + - target/ + policy: pull + +# Run integration tests with Redis service +redis-tests: + stage: test + needs: + - build + services: + - name: redis:alpine + alias: redis + variables: + REDIS_URL: redis://redis:6379 + script: + - apt-get update && apt-get install -y redis-tools + - cd target/release && ./wrkflw test-redis + - redis-cli -h redis PING + cache: + key: + files: + - Cargo.lock + paths: + - ${CI_PROJECT_DIR}/.cargo + - target/ + policy: pull + +# Run integration tests with MongoDB service +mongo-tests: + stage: test + needs: + - build + services: + - name: mongo:5 + alias: mongo + variables: + MONGO_URL: mongodb://mongo:27017 + script: + - apt-get update && apt-get install -y mongodb-clients + - cd target/release && ./wrkflw test-mongo + - mongosh --host mongo --eval "db.version()" + cache: + key: + files: + - Cargo.lock + paths: + - ${CI_PROJECT_DIR}/.cargo + - target/ + policy: pull + +# Run multi-service integration tests +all-services-test: + stage: test + needs: + - build + services: + - name: postgres:14-alpine + alias: postgres + - name: redis:alpine + alias: redis + - name: mongo:5 + alias: mongo + - name: rabbitmq:3-management + alias: rabbitmq + variables: + DATABASE_URL: postgres://postgres:postgres@postgres:5432/test_db + REDIS_URL: redis://redis:6379 + MONGO_URL: mongodb://mongo:27017 + RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672 + script: + - apt-get update && apt-get install -y postgresql-client redis-tools mongodb-clients + - cd target/release && ./wrkflw test-all-services + cache: + key: + files: + - Cargo.lock + paths: + - ${CI_PROJECT_DIR}/.cargo + - target/ + policy: pull + +# Deploy to production +deploy: + stage: deploy + needs: + - unit-tests + - postgres-tests + - redis-tests + - mongo-tests + script: + - echo "Deploying application..." + - cp target/release/wrkflw /tmp/ + only: + - main \ No newline at end of file diff --git a/test_gitlab_ci/workflow.gitlab-ci.yml b/test_gitlab_ci/workflow.gitlab-ci.yml new file mode 100644 index 0000000..4b14eab --- /dev/null +++ b/test_gitlab_ci/workflow.gitlab-ci.yml @@ -0,0 +1,186 @@ +stages: + - prepare + - build + - test + - deploy + +# Global workflow rules to control when pipelines run +workflow: + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + when: always + - if: $CI_COMMIT_BRANCH == "main" + when: always + - if: $CI_COMMIT_TAG + when: always + - if: $CI_COMMIT_BRANCH == "develop" + when: always + - if: $CI_COMMIT_BRANCH =~ /^release\/.*/ + when: always + - if: $CI_COMMIT_BRANCH =~ /^hotfix\/.*/ + when: always + - when: never # Skip all other branches + +variables: + RUST_VERSION: "1.76" + CARGO_HOME: "${CI_PROJECT_DIR}/.cargo" + +# Default settings +default: + image: "rust:${RUST_VERSION}" + interruptible: true + +# Cache definition to be used by other jobs +.cargo-cache: + cache: + key: + files: + - Cargo.lock + paths: + - ${CARGO_HOME} + - target/ + +# Prepare the dependencies (runs on all branches) +prepare: + stage: prepare + extends: .cargo-cache + script: + - cargo fetch --locked + artifacts: + paths: + - Cargo.lock + +# Build only on main branch and MRs +build: + stage: build + extends: .cargo-cache + needs: + - prepare + script: + - cargo build --release + artifacts: + paths: + - target/release/ + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH == "main" + - if: $CI_COMMIT_TAG + +# Build with debug symbols on develop branch +debug-build: + stage: build + extends: .cargo-cache + needs: + - prepare + script: + - cargo build + artifacts: + paths: + - target/debug/ + rules: + - if: $CI_COMMIT_BRANCH == "develop" + +# Test job - run on all branches except release and hotfix +test: + stage: test + extends: .cargo-cache + needs: + - job: build + optional: true + - job: debug-build + optional: true + script: + - | + if [ -d "target/release" ]; then + cargo test --release + else + cargo test + fi + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH == "main" + - if: $CI_COMMIT_BRANCH == "develop" + - if: $CI_COMMIT_TAG + - if: $CI_COMMIT_BRANCH =~ /^feature\/.*/ + +# Only lint on MRs and develop +lint: + stage: test + extends: .cargo-cache + script: + - rustup component add clippy + - cargo clippy -- -D warnings + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_COMMIT_BRANCH == "develop" + +# Run benchmarks only on main branch +benchmark: + stage: test + extends: .cargo-cache + needs: + - build + script: + - cargo bench + rules: + - if: $CI_COMMIT_BRANCH == "main" + - if: $CI_COMMIT_TAG + +# Deploy to staging on develop branch pushes +deploy-staging: + stage: deploy + needs: + - test + environment: + name: staging + url: https://staging.example.com + script: + - echo "Deploying to staging..." + - cp target/release/wrkflw /tmp/wrkflw-staging + rules: + - if: $CI_COMMIT_BRANCH == "develop" + when: on_success + - if: $CI_COMMIT_BRANCH =~ /^release\/.*/ + when: manual + +# Deploy to production on main branch and tags +deploy-prod: + stage: deploy + needs: + - test + - benchmark + environment: + name: production + url: https://example.com + script: + - echo "Deploying to production..." + - cp target/release/wrkflw /tmp/wrkflw-prod + rules: + - if: $CI_COMMIT_BRANCH == "main" + when: manual + - if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/ + when: manual + - if: $CI_COMMIT_BRANCH =~ /^hotfix\/.*/ + when: manual + +# Notify slack only when deploy succeeded or failed +notify: + stage: .post + image: curlimages/curl:latest + needs: + - job: deploy-staging + optional: true + - job: deploy-prod + optional: true + script: + - | + if [ "$CI_JOB_STATUS" == "success" ]; then + curl -X POST -H 'Content-type: application/json' --data '{"text":"Deployment succeeded! :tada:"}' $SLACK_WEBHOOK_URL + else + curl -X POST -H 'Content-type: application/json' --data '{"text":"Deployment failed! :boom:"}' $SLACK_WEBHOOK_URL + fi + rules: + - if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE != "merge_request_event" + - if: $CI_COMMIT_BRANCH == "develop" && $CI_PIPELINE_SOURCE != "merge_request_event" + - if: $CI_COMMIT_TAG + - if: $CI_COMMIT_BRANCH =~ /^hotfix\/.*/ \ No newline at end of file