Skip to content

Commit 41eea11

Browse files
authored
fix: fall back to a literal tag when a component ref is not a semver range (#1913)
1 parent e3f4023 commit 41eea11

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/parser-includes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ export class ParserIncludes {
282282
const stdout = getGitRemoteInfo(this, "--tags");
283283
const tags = stdout.split("\n").map(line => line.split("\t")[1].split("/")[2]);
284284
const version = resolveSemanticVersionRange(this.reference, tags);
285-
assert(version, `This GitLab CI configuration is invalid: component: \`${this.name}\` - The reference (${this.reference}) is invalid`);
286-
this._cache.version = version;
285+
assert(version ?? tags.includes(this.reference), `This GitLab CI configuration is invalid: component: \`${this.name}\` - The reference (${this.reference}) is invalid`);
286+
this._cache.version = version ?? null;
287287
} else {
288288
this._cache.version = null;
289289
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
# https://gitlab.com/ANGkeith/gitlab-ci-local-test tags a commit as `1`, which
3+
# matches the semver range pattern but is not a valid semver version.
4+
include:
5+
- component: gitlab.com/angkeith/gitlab-ci-local-test/my-components@1

tests/test-cases/include-component/integration.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,28 @@ component-job:
197197

198198
expect(writeStreams.stdoutLines[0]).toEqual(expected);
199199
});
200+
201+
test.concurrent("include-component component (non semver tag)", async () => {
202+
initSpawnSpy([WhenStatics.mockGitRemoteHttp]);
203+
204+
const writeStreams = new WriteStreamsMock();
205+
await handler({
206+
cwd: "tests/test-cases/include-component/component-non-semver-tag",
207+
preview: true,
208+
stateDir: ".gitlab-ci-local-include-component-non-semver-tag",
209+
}, writeStreams);
210+
211+
const expected = `---
212+
stages:
213+
- .pre
214+
- build
215+
- test
216+
- deploy
217+
- .post
218+
component-job:
219+
script:
220+
- echo job 1
221+
stage: test`;
222+
223+
expect(writeStreams.stdoutLines[0]).toEqual(expected);
224+
});

0 commit comments

Comments
 (0)