Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ function validateInput (ctx: any) {

const regex = inputsSpecification.spec.inputs[interpolationKey]?.regex;
if (regex) {
ctx.writeStreams?.stderr(chalk`{black.bgYellowBright WARN } spec:inputs:regex is currently not supported via gitlab-ci-local. This will just be a no-op.\n`);
assert(new RegExp(regex).test(String(inputValue)),
chalk`This GitLab CI configuration is invalid: \`{blueBright ${configFilePath}}\`: \`{blueBright ${interpolationKey}}\` input: \`{blueBright ${inputValue}}\` does not match required regex: {blueBright ${regex}}.`);
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
spec:
inputs:
version:
regex: ^v\d+\.\d+\.\d+$
---
deploy:
script:
- echo $[[ inputs.version ]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
include:
- local: '/.gitlab-ci-input-template.yml'
inputs:
version: "v1.2.3"
stages:
- test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
spec:
inputs:
version:
regex: ^v\d+\.\d+\.\d+$
---
deploy:
script:
- echo $[[ inputs.version ]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
include:
- local: '/.gitlab-ci-input-template.yml'
inputs:
version: "invalid-version"
stages:
- test
38 changes: 38 additions & 0 deletions tests/test-cases/include-inputs/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,41 @@ scan-website:

expect(writeStreams.stdoutLines[0]).toEqual(expected);
});

test.concurrent("include-inputs regex validation (invalid)", async () => {
try {
const writeStreams = new WriteStreamsMock();
await handler({
cwd: "tests/test-cases/include-inputs/input-templates/regex-validation",
preview: true,
}, writeStreams);
} catch (e: any) {
assert(e instanceof AssertionError, "e is not instanceof AssertionError");
expect(e.message).toContain("This GitLab CI configuration is invalid:");
expect(e.message).toContain(
chalk`\`{blueBright version}\` input: \`{blueBright invalid-version}\` does not match required regex: {blueBright ^v\\d+\\.\\d+\\.\\d+$}.`,
);
return;
}

throw new Error("Error is expected but not thrown/caught");
});

test.concurrent("include-inputs regex validation (valid)", async () => {
const writeStreams = new WriteStreamsMock();
await handler({
cwd: "tests/test-cases/include-inputs/input-templates/regex-validation-pass",
preview: true,
}, writeStreams);

const expected = `---
stages:
- .pre
- test
- .post
deploy:
script:
- echo v1.2.3`;

expect(writeStreams.stdoutLines[0]).toEqual(expected);
});