Skip to content

Commit d9bd0cb

Browse files
committed
fixed issues
1 parent 3b8891a commit d9bd0cb

File tree

8 files changed

+45
-32
lines changed

8 files changed

+45
-32
lines changed

src/commands/generate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use anyhow::{Context, Result};
22
use std::path::PathBuf;
33

4+
#[allow(clippy::collapsible_if)]
45
/// Generate CI configs from cigen.yml
56
pub fn generate_command(file: Option<String>, output: Option<String>) -> Result<()> {
67
// Find cigen.yml

src/loader.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,6 @@ fn resolve_job_dependencies(jobs: &mut HashMap<String, Job>) {
255255
}
256256
}
257257

258-
fn should_prefix_job(config: &WorkflowConfig, stage: &str) -> bool {
259-
if stage == "default" {
260-
config.default_stage_prefix
261-
} else {
262-
config.stage_prefix
263-
}
264-
}
265-
266258
fn load_workflow_config(workflow_path: &Path) -> Result<WorkflowConfig> {
267259
for candidate in ["config.yml", "config.yaml"] {
268260
let candidate_path = workflow_path.join(candidate);

src/orchestrator/convert.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ mod tests {
373373
artifacts: vec![],
374374
extra: HashMap::new(),
375375
workflow: None,
376+
stage: None,
376377
},
377378
);
378379

src/orchestrator/dag.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ fn expand_matrix_job(
250250
// But if we have "ci/rspec", stage="ci". "ci_rspec".
251251
// If we have "deploy/pre_release", stage="deploy_us". "deploy_us_pre_release".
252252
// So we just want the file stem.
253-
let base_short_name = job_id.split('/').last().unwrap_or(job_id);
253+
let base_short_name = job_id.split('/').next_back().unwrap_or(job_id);
254254

255255
// Sanitize base name (replace / with _ just in case, though split should handle it)
256256
let base_clean_name = base_short_name.replace('/', "_");
@@ -327,7 +327,7 @@ fn expand_matrix_job(
327327

328328
let mut substituted_job = job.clone();
329329
for need in substituted_job.needs.iter_mut() {
330-
*need = substitute_matrix_in_string(need, &row);
330+
*need = substitute_matrix_in_string(need, row);
331331
}
332332

333333
instances.push(ConcreteJob {
@@ -472,6 +472,7 @@ mod tests {
472472
artifacts: vec![],
473473
extra: HashMap::new(),
474474
workflow: None,
475+
stage: None,
475476
}
476477
}
477478

@@ -686,7 +687,12 @@ mod tests {
686687

687688
let result = JobDAG::build(&config);
688689
assert!(result.is_err());
689-
assert!(result.unwrap_err().to_string().contains("doesn't exist"));
690+
assert!(
691+
result
692+
.unwrap_err()
693+
.to_string()
694+
.contains("no matching job instance exists")
695+
);
690696
}
691697

692698
#[test]

src/orchestrator/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ mod workflow;
55

66
pub use dag::{ConcreteJob, JobDAG};
77
pub use workflow::{FileFragment, GenerationResult, MergeStrategy, WorkflowOrchestrator};
8-
9-
use crate::schema::CigenConfig;
10-
use std::collections::HashMap;

src/schema/job.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,16 @@ matrix:
292292
"#;
293293

294294
let job: Job = serde_yaml::from_str(yaml).unwrap();
295-
assert_eq!(job.matrix.len(), 2);
296295

297-
if let Some(MatrixDimension::List(values)) = job.matrix.get("ruby") {
298-
assert_eq!(values, &vec!["3.2", "3.3"]);
299-
} else {
300-
panic!("Expected ruby matrix dimension");
296+
match job.matrix {
297+
Some(JobMatrix::Dimensions(dims)) => {
298+
assert_eq!(dims.len(), 2);
299+
assert_eq!(
300+
dims.get("ruby").unwrap(),
301+
&vec!["3.2".to_string(), "3.3".to_string()]
302+
);
303+
}
304+
_ => panic!("Expected dimensions matrix"),
301305
}
302306
}
303307

tests/circleci_job_status.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,16 @@ fn circleci_job_status_steps_for_rails_fixture() {
167167
let jobs = load_jobs_map(&output.path().join(".circleci/main.yml"));
168168

169169
for job_id in &with_sources {
170-
let job_value = jobs.get(job_id).unwrap_or_else(|| {
171-
panic!("expected job {job_id} in generated main.yml");
170+
let sanitized_id = job_id.replace(['/', '\\'], "_");
171+
let job_value = jobs.get(&sanitized_id).unwrap_or_else(|| {
172+
panic!("expected job {sanitized_id} (from {job_id}) in generated main.yml");
172173
});
173174
assert_has_job_status_steps(job_id, job_value);
174175
}
175176

176177
for job_id in &without_sources {
177-
if let Some(job_value) = jobs.get(job_id) {
178+
let sanitized_id = job_id.replace(['/', '\\'], "_");
179+
if let Some(job_value) = jobs.get(&sanitized_id) {
178180
assert_absent_job_status_steps(job_id, job_value);
179181
}
180182
}
@@ -197,14 +199,16 @@ fn circleci_job_status_steps_for_docspring_config() {
197199
let jobs = load_jobs_map(&output.path().join(".circleci/main.yml"));
198200

199201
for job_id in &with_sources {
200-
let job_value = jobs.get(job_id).unwrap_or_else(|| {
201-
panic!("expected job {job_id} in generated main.yml");
202+
let sanitized_id = job_id.replace(['/', '\\'], "_");
203+
let job_value = jobs.get(&sanitized_id).unwrap_or_else(|| {
204+
panic!("expected job {sanitized_id} (from {job_id}) in generated main.yml");
202205
});
203206
assert_has_job_status_steps(job_id, job_value);
204207
}
205208

206209
for job_id in &without_sources {
207-
if let Some(job_value) = jobs.get(job_id) {
210+
let sanitized_id = job_id.replace(['/', '\\'], "_");
211+
if let Some(job_value) = jobs.get(&sanitized_id) {
208212
assert_absent_job_status_steps(job_id, job_value);
209213
}
210214
}

tests/schema_parsing.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// Tests for parsing example cigen.yml configs
2-
use cigen::schema::CigenConfig;
2+
use cigen::schema::{CigenConfig, JobMatrix};
33
use std::fs;
44

55
#[test]
@@ -32,9 +32,13 @@ fn test_parse_rails_app_example() {
3232

3333
// Check test job has matrix
3434
let test_job = &config.jobs["test"];
35-
assert!(!test_job.matrix.is_empty());
36-
assert!(test_job.matrix.contains_key("ruby"));
37-
assert!(test_job.matrix.contains_key("arch"));
35+
if let Some(JobMatrix::Dimensions(dims)) = &test_job.matrix {
36+
assert!(!dims.is_empty());
37+
assert!(dims.contains_key("ruby"));
38+
assert!(dims.contains_key("arch"));
39+
} else {
40+
panic!("Expected Dimensions matrix for test job");
41+
}
3842

3943
// Check services
4044
assert_eq!(test_job.services.len(), 2);
@@ -105,7 +109,11 @@ jobs:
105109
let config = CigenConfig::from_yaml(yaml).unwrap();
106110
let test_job = &config.jobs["test"];
107111

108-
assert_eq!(test_job.matrix.len(), 2);
109-
assert!(test_job.matrix.contains_key("ruby"));
110-
assert!(test_job.matrix.contains_key("node"));
112+
if let Some(JobMatrix::Dimensions(dims)) = &test_job.matrix {
113+
assert_eq!(dims.len(), 2);
114+
assert!(dims.contains_key("ruby"));
115+
assert!(dims.contains_key("node"));
116+
} else {
117+
panic!("Expected Dimensions matrix for test job");
118+
}
111119
}

0 commit comments

Comments
 (0)