Skip to content

Commit d9893bb

Browse files
committed
fix(parser): don't anchor comment directives on comment lines
The @Description/@Interactive/@InjectSSHAgent/@NoArtifactsToSource injection used /\w:/ to find the job to attach a pending directive to. That regex also matches a colon inside a comment line, so a multi-line '# @description ...: ...' block (or any comment containing 'word:') was treated as the anchor. The 2-space 'gclDescription:' line then got spliced in after a comment, landing on the previous job — producing a duplicate mapping key and the 'duplicated mapping key detected! Values will be overwritten!' warning. Skip comment lines entirely when scanning for the anchor, and only anchor on a real top-level key (/^[\w.$-]+:/) so indented keys and comments can never be mistaken for a job.
1 parent cfc7aaf commit d9893bb

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/parser.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,16 @@ export class Parser {
297297
let index = 0;
298298
if (expandVariables) {
299299
for (const line of fileSplit) {
300-
interactiveMatch = interactiveMatch ?? /#\s?@\s?[Ii]nteractive/.exec(line);
301-
injectSSHAgent = injectSSHAgent ?? /#\s?@\s?[Ii]njectSSHAgent/.exec(line);
302-
noArtifactsToSourceMatch = noArtifactsToSourceMatch ?? /#\s?@\s?NoArtifactsToSource/i.exec(line);
303-
descriptionMatch = descriptionMatch ?? /#\s?@\s?[Dd]escription (?<description>.*)/.exec(line);
300+
if (/^\s*#/.test(line)) {
301+
interactiveMatch = interactiveMatch ?? /#\s?@\s?[Ii]nteractive/.exec(line);
302+
injectSSHAgent = injectSSHAgent ?? /#\s?@\s?[Ii]njectSSHAgent/.exec(line);
303+
noArtifactsToSourceMatch = noArtifactsToSourceMatch ?? /#\s?@\s?NoArtifactsToSource/i.exec(line);
304+
descriptionMatch = descriptionMatch ?? /#\s?@\s?[Dd]escription (?<description>.*)/.exec(line);
305+
index++;
306+
continue;
307+
}
304308

305-
const jobMatch = /\w:/.exec(line);
309+
const jobMatch = /^[\w.$-]+:/.exec(line);
306310
if (jobMatch && (interactiveMatch || descriptionMatch || injectSSHAgent || noArtifactsToSourceMatch)) {
307311
if (interactiveMatch) {
308312
fileSplitClone.splice(index + 1, 0, " gclInteractive: true");

0 commit comments

Comments
 (0)