Skip to content

Commit fac75e5

Browse files
committed
List without entries, now starts the job right away. Jobnames specified in needs list are now validate and must exist
1 parent 4da83bf commit fac75e5

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const runJobs = async () => {
7474

7575
// Find jobs that can be started, because their needed jobs have finished
7676
for (const job of jobs) {
77-
if (job.isRunning() || job.isFinished() || job.needs.length === 0) {
77+
if (job.isRunning() || job.isFinished() || job.needs === null) {
7878
continue;
7979
}
8080

src/job.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (process.env.EXEPATH) {
1717

1818
export class Job {
1919
public readonly name: string;
20-
public readonly needs: string[];
20+
public readonly needs: string[] | null;
2121
public readonly stage: string;
2222

2323
private readonly afterScripts: string[] = [];
@@ -72,11 +72,7 @@ export class Job {
7272
this.afterScripts = [].concat(jobData.after_script || ciDefault.after_script || globals.after_script || []);
7373
this.allowFailure = jobData.allow_failure || false;
7474
this.variables = jobData.variables || {};
75-
if (this.needs && this.needs.length === 0) {
76-
console.error(`${jobNameStr} ${c.red("'needs' cannot be empty array")}`);
77-
process.exit(1);
78-
}
79-
this.needs = jobData.needs || [];
75+
this.needs = jobData.needs || null;
8076
}
8177

8278
public getJobNameString() {

src/parser.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ export class Parser {
102102

103103
this.jobs.set(key, job);
104104
}
105+
106+
this.validateNeedsTags();
105107
}
106108

107109
public getJobs(): ReadonlyMap<string, Job> {
@@ -111,4 +113,18 @@ export class Parser {
111113
public getStages(): ReadonlyMap<string, Stage> {
112114
return this.stages;
113115
}
116+
117+
private validateNeedsTags() {
118+
const jobNames = Array.from(this.jobs.values()).map((j) => j.name);
119+
for (const job of this.jobs.values()) {
120+
if (job.needs === null || job.needs.length === 0) {
121+
continue;
122+
}
123+
124+
if (job.needs.filter((v) => (jobNames.indexOf(v) >= 0)).length !== job.needs.length) {
125+
console.error(`${c.blueBright(`${job.name}`)} needs list contains unspecified jobs.`);
126+
process.exit(1);
127+
}
128+
}
129+
}
114130
}

tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
],
66
"jsRules": {},
77
"rules": {
8+
"no-null-keyword": false,
89
"no-magic-numbers": false,
910
"strict-boolean-expressions": false,
1011
"newline-per-chained-call": false,

0 commit comments

Comments
 (0)