forked from firecow/gitlab-ci-local
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproducers.ts
More file actions
45 lines (37 loc) · 1.7 KB
/
Copy pathproducers.ts
File metadata and controls
45 lines (37 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import {Utils} from "./utils.js";
import {Job} from "./job.js";
import {findMatchingNeed, matrixSelectorMatches} from "./parallel.js";
export class Producers {
static init (jobs: ReadonlyArray<Job>, stages: readonly string[], job: Job) {
const producerSet: Set<string> = new Set();
if (job.needs && job.needs.length === 0) return [];
if (!job.needs && !job.dependencies) {
for (const jobName of Utils.getJobNamesFromPreviousStages(jobs, stages, job)) {
producerSet.add(jobName);
}
}
(job.dependencies ?? []).forEach(dependency => {
const foundInNeeds = (job.needs ?? []).find(n => n.job === dependency);
if (foundInNeeds) return;
producerSet.add(dependency);
});
(job.needs ?? []).forEach(need => {
if (!need.artifacts) return;
if (need.pipeline) return;
if (need.project) return;
producerSet.add(need.job);
});
const producers: Job[] = [];
for (const potential of jobs) {
if (potential.artifacts == null) continue;
if (potential.when == "never") continue;
if (!producerSet.has(potential.name) && !producerSet.has(potential.baseName)) continue;
const matchedNeed = findMatchingNeed(job.needs, potential.name, potential.baseName);
if (matchedNeed?.parallel?.matrix && !matrixSelectorMatches(potential.matrixVariables, matchedNeed.parallel.matrix)) continue;
producers.push(potential);
}
return producers.map(producer => {
return {name: producer.name, dotenv: producer?.artifacts?.reports?.dotenv ?? null};
});
}
}