From 4a9db6000c3ef0d37ccae5502941c55df61d64a0 Mon Sep 17 00:00:00 2001 From: ke-lit <173372444+ke-lit@users.noreply.github.com> Date: Sun, 3 Nov 2024 18:38:14 +0000 Subject: [PATCH 1/2] feat: Respect rules for local includes (#1406) --- src/parser-includes.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/parser-includes.ts b/src/parser-includes.ts index 41a33976d..d7633d223 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(/^\//, ""), From f2a55757c1dc49da2c297a93a5a0c3d72d2fa39a Mon Sep 17 00:00:00 2001 From: ANGkeith Date: Thu, 7 Nov 2024 13:04:44 +0800 Subject: [PATCH 2/2] test: add integration test --- .../include-project-file/.gitlab-ci-3.yml | 7 +++++++ .../include-project-file/integration.test.ts | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/test-cases/include-project-file/.gitlab-ci-3.yml 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 000000000..83d407eb4 --- /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 5394f13d4..a261d318e 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")); +});