Skip to content

Commit

Permalink
fix: avoid job duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Dec 11, 2024
1 parent 5a42bb8 commit b6890cf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crates/gh-workflow/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,23 @@ impl Generate {
fn organize_job_dependency(mut workflow: Workflow) -> Workflow {
let mut job_id = 0;
let mut new_jobs = IndexMap::<String, Job>::new();
let empty_map = IndexMap::default();

let old_jobs: &IndexMap<String, Job> = workflow
.jobs
.as_ref()
.map(|jobs| &jobs.0)
.unwrap_or(&empty_map);

// Iterate over all jobs
for (id, mut job) in workflow.jobs.clone().unwrap_or_default().0.into_iter() {
// If job has dependencies
if let Some(dep_jobs) = &job.tmp_needs {
// Prepare the job_ids
let mut job_ids = Vec::<String>::new();
for dep_job in dep_jobs.iter() {
for job in dep_jobs.iter() {
// If the job is already available
if let Some(id) = find_job(dep_job, &new_jobs, &workflow) {
if let Some(id) = find_value(job, &new_jobs).or(find_value(job, &old_jobs)) {

Check failure on line 112 in crates/gh-workflow/src/generate.rs

View workflow job for this annotation

GitHub Actions / Build and Test

cannot find function `find_value` in this scope

Check failure on line 112 in crates/gh-workflow/src/generate.rs

View workflow job for this annotation

GitHub Actions / Build and Test

cannot find function `find_value` in this scope

Check failure on line 112 in crates/gh-workflow/src/generate.rs

View workflow job for this annotation

GitHub Actions / Lint

cannot find function `find_value` in this scope

Check failure on line 112 in crates/gh-workflow/src/generate.rs

View workflow job for this annotation

GitHub Actions / Lint

cannot find function `find_value` in this scope

Check failure on line 112 in crates/gh-workflow/src/generate.rs

View workflow job for this annotation

GitHub Actions / Lint Fix

cannot find function `find_value` in this scope

Check failure on line 112 in crates/gh-workflow/src/generate.rs

View workflow job for this annotation

GitHub Actions / Lint Fix

cannot find function `find_value` in this scope
job_ids.push(id.to_owned());
} else {
// Create a job-id for the job
Expand All @@ -112,7 +119,7 @@ fn organize_job_dependency(mut workflow: Workflow) -> Workflow {
job_ids.push(id.clone());

// Insert the missing job into the new_jobs
new_jobs.insert(format!("job-{}", job_id), dep_job.clone());
new_jobs.insert(format!("job-{}", job_id), job.clone());

job_id += 1;
}
Expand Down

0 comments on commit b6890cf

Please sign in to comment.