fix: strip YAML comments before template rendering - #152
Open
Hermsi1337 wants to merge 3 commits into
Open
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The stack/services/volumes input is rendered as a Go text/template before it is parsed as YAML, so template expressions inside YAML comments were evaluated as well. A commented-out line referencing an unset variable failed the whole deployment due to missingkey=error, and broken template syntax inside a comment produced misleading parse errors. Comments are now removed before templating by a scanner that is aware of quoted scalars, "#" without preceding whitespace, and block scalars (including shebangs), so legitimate "#" content is preserved. Closes #151 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #151.
The stack/services/volumes input is rendered as a Go
text/templatebefore it is parsed as YAML, so template expressions inside YAML comments were evaluated as well:# db_url: {{ .Env.DATABASE_URL }}failed the whole deployment withmap has no entry for key "DATABASE_URL"(because ofmissingkey=error).# see {{) produced a misleading parse error pointing at the wrong line.Changes
cmd/action/main.go: newstripYamlComments()is called inloadYamlOptional()right beforetemplate.Parse. The scanner removes comments while preserving the line count (error messages keep pointing at the correct line) and knows the cases where#is not a comment:image: nginx#latest),command: |followed by#!/bin/sh).cmd/action/main_test.go: 10 end-to-end regression tests plus a 14-case table test forstripYamlComments, including non-regression tests asserting that templating outside comments still works and thatmissingkey=errorstill fires there.README.md: note in the "Environment Variable Parsing" section that comments are stripped before rendering, so template expressions inside comments are inert..gitattributes(separate commit): enforce LF line endings (* text=auto eol=lf) so Windows checkouts withcore.autocrlfstay gofmt-clean.Testing
go test ./...: 49 tests pass (26 new).go vet ./...: clean.golangci-lint(the Makefile'squay.io/mittwald/golangci-lint:0.0.38image): no findings.Known limitation
The scanner tracks quote state conservatively: an apostrophe in an unquoted scalar (e.g.
description: user's app) opens single-quote state, so comments until the next apostrophe are left in place. In that case behavior simply degrades to the status quo before this PR — legitimate content is never stripped.🤖 Generated with Claude Code