diff --git a/src/parser-includes.ts b/src/parser-includes.ts index 171b516fb..cbb3f6aa6 100644 --- a/src/parser-includes.ts +++ b/src/parser-includes.ts @@ -282,8 +282,8 @@ export class ParserIncludes { const stdout = getGitRemoteInfo(this, "--tags"); const tags = stdout.split("\n").map(line => line.split("\t")[1].split("/")[2]); const version = resolveSemanticVersionRange(this.reference, tags); - assert(version, `This GitLab CI configuration is invalid: component: \`${this.name}\` - The reference (${this.reference}) is invalid`); - this._cache.version = version; + assert(version ?? tags.includes(this.reference), `This GitLab CI configuration is invalid: component: \`${this.name}\` - The reference (${this.reference}) is invalid`); + this._cache.version = version ?? null; } else { this._cache.version = null; } diff --git a/tests/test-cases/include-component/component-non-semver-tag/.gitlab-ci.yml b/tests/test-cases/include-component/component-non-semver-tag/.gitlab-ci.yml new file mode 100644 index 000000000..1cca144be --- /dev/null +++ b/tests/test-cases/include-component/component-non-semver-tag/.gitlab-ci.yml @@ -0,0 +1,5 @@ +--- +# https://gitlab.com/ANGkeith/gitlab-ci-local-test tags a commit as `1`, which +# matches the semver range pattern but is not a valid semver version. +include: + - component: gitlab.com/angkeith/gitlab-ci-local-test/my-components@1 diff --git a/tests/test-cases/include-component/integration.test.ts b/tests/test-cases/include-component/integration.test.ts index b907b47a8..0381c65c5 100644 --- a/tests/test-cases/include-component/integration.test.ts +++ b/tests/test-cases/include-component/integration.test.ts @@ -197,3 +197,28 @@ component-job: expect(writeStreams.stdoutLines[0]).toEqual(expected); }); + +test.concurrent("include-component component (non semver tag)", async () => { + initSpawnSpy([WhenStatics.mockGitRemoteHttp]); + + const writeStreams = new WriteStreamsMock(); + await handler({ + cwd: "tests/test-cases/include-component/component-non-semver-tag", + preview: true, + stateDir: ".gitlab-ci-local-include-component-non-semver-tag", + }, writeStreams); + + const expected = `--- +stages: + - .pre + - build + - test + - deploy + - .post +component-job: + script: + - echo job 1 + stage: test`; + + expect(writeStreams.stdoutLines[0]).toEqual(expected); +});