Skip to content

Commit 1e3df13

Browse files
authored
fix: reject empty rules array instead of silently skipping job (#1852)
1 parent 5898e76 commit 1e3df13

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/validator.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ For further troubleshooting, consider either of the following:
133133
}
134134
}
135135

136+
private static rulesBlank (jobs: ReadonlyArray<Job>) {
137+
for (const job of jobs) {
138+
if (!job.rules) continue;
139+
assert(job.rules.length > 0, chalk`{blue ${job.name}} {yellow rules:} config can't be blank`);
140+
}
141+
}
142+
136143
private static arrayOfStrings (jobs: ReadonlyArray<Job>) {
137144
for (const job of jobs) {
138145
if (job.trigger) continue;
@@ -144,6 +151,7 @@ For further troubleshooting, consider either of the following:
144151

145152
static async run (jobs: ReadonlyArray<Job>, stages: readonly string[]) {
146153
this.scriptBlank(jobs);
154+
this.rulesBlank(jobs);
147155
this.arrayOfStrings(jobs);
148156
this.dependencies(jobs, stages);
149157
this.dependenciesContainment(jobs);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
job:
3+
rules: []
4+
script:
5+
- echo "Heya"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {WriteStreamsMock} from "../../../src/write-streams.js";
2+
import {handler} from "../../../src/handler.js";
3+
import {initSpawnSpy} from "../../mocks/utils.mock.js";
4+
import {WhenStatics} from "../../mocks/when-statics.js";
5+
import chalk from "chalk-template";
6+
7+
beforeAll(() => {
8+
initSpawnSpy(WhenStatics.all);
9+
});
10+
11+
test.concurrent("rules-blank <job>", async () => {
12+
const writeStreams = new WriteStreamsMock();
13+
14+
await expect(handler({
15+
cwd: "tests/test-cases/rules-blank",
16+
stateDir: ".gitlab-ci-local-rules-blank",
17+
}, writeStreams)).rejects.toThrow(chalk`{blue job} {yellow rules:} config can't be blank`);
18+
});

0 commit comments

Comments
 (0)