diff --git a/src/parser-includes.ts b/src/parser-includes.ts index 41a33976..d7633d22 100644 --- a/src/parser-includes.ts +++ b/src/parser-includes.ts @@ -94,6 +94,12 @@ export class ParserIncludes { fileDoc["include"] = this.expandInclude(fileDoc["include"], opts.variables); fileDoc["include"].forEach((inner: any, i: number) => { if (!inner["local"]) return; + if (inner["rules"]) { + const rulesResult = Utils.getRulesResult({cwd: opts.cwd, variables: opts.variables, rules: inner["rules"]}, gitData); + if (rulesResult.when === "never") { + return; + } + } fileDoc["include"][i] = { project: value["project"], file: inner["local"].replace(/^\//, ""), diff --git a/tests/test-cases/include-project-file/.gitlab-ci-3.yml b/tests/test-cases/include-project-file/.gitlab-ci-3.yml new file mode 100644 index 00000000..83d407eb --- /dev/null +++ b/tests/test-cases/include-project-file/.gitlab-ci-3.yml @@ -0,0 +1,7 @@ +--- +include: + # https://gitlab.com/ANGkeith/gitlab-ci-local-test + - project: angkeith/gitlab-ci-local-test + ref: issue/#1011 + file: + - .gitlab-ci.yml diff --git a/tests/test-cases/include-project-file/integration.test.ts b/tests/test-cases/include-project-file/integration.test.ts index 5394f13d..a261d318 100644 --- a/tests/test-cases/include-project-file/integration.test.ts +++ b/tests/test-cases/include-project-file/integration.test.ts @@ -49,3 +49,22 @@ test("include:project should target default branch when ref is missing", async ( const filteredStdout = writeStreams.stdoutLines.filter(f => f.startsWith("job >")).join("\n"); expect(filteredStdout).toEqual(expected); }); + +test("include:project should respect rules specified in included project", async () => { + const writeStreams = new WriteStreamsMock(); + + await handler({ + file: ".gitlab-ci-3.yml", + cwd: "tests/test-cases/include-project-file", + noColor: true, + list: true, + }, writeStreams); + + + const expected = [ + "name description stage when allow_failure needs", + "should execute since rule eval to true test on_success false ", + ]; + + expect(writeStreams.stdoutLines.join("\n")).toEqual(expected.join("\n")); +});