Skip to content

[yamllint-fixer] Reduce yamllint trailing-spaces noise in generated lock files#46699

Merged
pelikhan merged 9 commits into
mainfrom
fix/yamllint-trailing-spaces-custom-steps-b09ee4f52f4963ce
Jul 20, 2026
Merged

[yamllint-fixer] Reduce yamllint trailing-spaces noise in generated lock files#46699
pelikhan merged 9 commits into
mainfrom
fix/yamllint-trailing-spaces-custom-steps-b09ee4f52f4963ce

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Reduces yamllint trailing-spaces noise in generated lock files by trimming trailing whitespace from structural YAML lines emitted by the compiler, while safely preserving trailing whitespace inside block scalar payloads where it is semantically significant.

Problem

The YAML compiler emitted lines verbatim from workflow Markdown sources, preserving any trailing whitespace. This caused yamllint trailing-spaces warnings in generated .lock.yml files. A naive trim-all approach is unsafe: trailing whitespace inside a block scalar run: script (backslash followed by spaces) must not be stripped, as it prevents the backslash from acting as a shell line-continuation character.

Changes

New: pkg/workflow/compiler_yaml_line_writer.go

  • yamlBlockScalarState — indent-based state machine tracking entry into and exit from YAML | and > block scalars. Zero value is ready to use; one instance per YAML stream.
  • appendYAMLLine — centralised line-writer that always emits blank lines as bare newlines, trims trailing whitespace from structural lines, and preserves block-scalar payload lines verbatim.

Refactored emitters

File Function(s)
compiler_yaml_runtime_setup.go addCustomStepsAsIs, addCustomStepsWithRuntimeInsertion
compiler_yaml_step_conversion.go ConvertStepToYAML
compiler_yaml_step_lifecycle.go writeStepsSection

All previously used ad-hoc yaml.WriteString patterns; now delegate to appendYAMLLine + yamlBlockScalarState.

Source file fixes

  • .github/workflows/issue-monster.md — trailing whitespace removed from JS arrow-function lines.
  • .github/workflows/shared/discussions-data-fetch.md — trailing whitespace removed from jq pipeline and documentation section.

Tests: pkg/workflow/compiler_yaml_test.go

New table-driven tests: TestYamlBlockScalarStateUpdate, TestAppendYAMLLine, TestWriteStepsSection, TestAddCustomStepsAsIsTrimsStructuralTrailingSpaces.

Key invariant

Trailing whitespace after a backslash in a block-scalar run: script must not be trimmed: removing it would activate shell line-continuation, silently changing script behaviour.

Testing

All new tests are in pkg/workflow/compiler_yaml_test.go. Existing compiler tests continue to pass.

Generated by PR Description Updater for #46699 · 30.3 AIC · ⌖ 5.59 AIC · ⊞ 4.8K ·

Custom steps (agent-job `steps:`) and pre-activation `on.steps` embed
user-authored shell/jq/js content verbatim. When those source lines
carry trailing whitespace, it survived into the generated `*.lock.yml`,
which yamllint flags as trailing-spaces.

Right-trim each content line in the three step-emission paths:
- addCustomStepsAsIs / addCustomStepsWithRuntimeInsertion (agent job)
- ConvertStepToYAML (on.steps in pre-activation job)
- writeStepsSection (pre/post/pre-agent steps)

Blank/whitespace-only lines were already collapsed to bare newlines;
this extends the same treatment to trailing whitespace on content lines.
Trailing whitespace is insignificant for the shell/script content these
steps carry.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pelikhan
pelikhan marked this pull request as ready for review July 20, 2026 04:17
Copilot AI review requested due to automatic review settings July 20, 2026 04:17
@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR. Test Quality Sentinel skipped.

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

⚠️ PR Code Quality Reviewer failed to deliver outputs during code quality review.

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #46699 does not have the 'implementation' label and has only 22 new lines of code in business logic directories (threshold: 100).

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Reduces yamllint trailing-space warnings by trimming generated step lines.

Changes:

  • Trims emitted custom and lifecycle step lines.
  • Trims serialized on.steps content.
Show a summary per file
File Description
pkg/workflow/compiler_yaml_step_lifecycle.go Trims lifecycle step lines.
pkg/workflow/compiler_yaml_step_conversion.go Trims converted step YAML.
pkg/workflow/compiler_yaml_runtime_setup.go Trims custom runtime-step output.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (2)

pkg/workflow/compiler_yaml_runtime_setup.go:357

  • The runtime-insertion path now mutates trailing whitespace inside custom step block scalars. This can change shell continuation behavior and the contents of heredocs or action with: scripts, despite the source workflow being valid. Track whether the current line is structural YAML or block-scalar payload and preserve payload exactly rather than applying TrimRight unconditionally.
		// Add the line with proper indentation. Right-trim so trailing whitespace
		// carried in from source step content doesn't survive into the generated
		// YAML, which yamllint flags as trailing-spaces.
		yaml.WriteString("      " + strings.TrimRight(line, " \t") + "\n")

pkg/workflow/compiler_yaml_runtime_setup.go:400

  • Lines copied from the checkout step can also belong to block scalars (for example multiline with.sparse-checkout input). Unconditionally trimming them changes the action input value. Apply the same block-scalar-aware preservation here as in the main custom-step loop; only structural YAML should be right-trimmed.
					if nextTrimmed == "" {
						yaml.WriteString("\n")
					} else {
						yaml.WriteString("      " + strings.TrimRight(nextLine, " \t") + "\n")
  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Medium

Comment on lines +44 to +47
if strings.HasPrefix(trimmed, " ") {
yaml.WriteString(" " + trimmed[2:] + "\n")
} else {
yaml.WriteString(" " + line + "\n")
yaml.WriteString(" " + trimmed + "\n")
Comment on lines +49 to +52
if trimmed := strings.TrimRight(line, " \t"); strings.TrimSpace(trimmed) == "" {
result.WriteString("\n")
} else {
result.WriteString(" " + line + "\n")
result.WriteString(" " + trimmed + "\n")
Comment on lines +322 to +326
// Simply add 6 spaces for job context indentation. Right-trim so any
// trailing whitespace carried in from source step content (e.g. embedded
// shell/jq/js scripts) doesn't survive into the generated YAML, which
// yamllint flags as trailing-spaces.
yaml.WriteString(" " + strings.TrimRight(line, " \t") + "\n")
@github-actions

Copy link
Copy Markdown
Contributor Author

🧪 Test Quality Sentinel Report

No Test Files Modified

This PR ([yamllint-fixer] Reduce yamllint trailing-spaces noise in generated lock files) contains only production code changes to three files:

  • pkg/workflow/compiler_yaml_runtime_setup.go (+10, -5)
  • pkg/workflow/compiler_yaml_step_conversion.go (+6, -2)
  • pkg/workflow/compiler_yaml_step_lifecycle.go (+6, -3)

Since no test files were added or modified, the Test Quality Sentinel skipped analysis. No test quality assessment is needed for this change.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

🧪 Test quality analysis by Test Quality Sentinel · 6.61 AIC · ⌖ 8.56 AIC · ⊞ 7K ·
Comment /review to run again

@github-actions github-actions Bot mentioned this pull request Jul 20, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: trailing-spaces fix

The changes are correct and consistent. Each of the three emitter sites now right-trims content lines before writing them, eliminating the source of yamllint trailing-spaces warnings without affecting runtime behavior.

Minor inconsistency (non-blocking): compiler_yaml_step_lifecycle.go line 36 trims only " " (spaces), while compiler_yaml_runtime_setup.go and compiler_yaml_step_conversion.go both trim " \t" (spaces and tabs). Tabs as trailing whitespace in embedded scripts are unlikely but the inconsistency is worth aligning in a follow-up.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · 11.4 AIC · ⌖ 4.34 AIC · ⊞ 5K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /diagnosing-bugs — one inconsistency to address before merging.

📋 Key Themes & Highlights

Issues Found

  • Tab vs space inconsistency: compiler_yaml_step_lifecycle.go line 36 trims only spaces (" "), while the other two changed files trim both spaces and tabs (" \t"). Tabs in embedded content lines would still trigger yamllint trailing-spaces.

Positive Highlights

  • ✅ Clear, accurate root-cause analysis in PR description
  • ✅ Latent bug in writeStepsSection (trimmed but then writing untrimmed) correctly identified and fixed
  • ✅ Comments are concise and explain why trimming is safe for shell/script content
  • ✅ The TrimRight approach (preserving leading whitespace/indentation) is exactly right — TrimSpace would break YAML structure

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 20.5 AIC · ⌖ 4.5 AIC · ⊞ 6.7K
Comment /matt to run again

// Emit the right-trimmed line so trailing whitespace carried in from the
// source step content (e.g. embedded shell/jq/js scripts) doesn't survive
// into the generated YAML, which yamllint flags as trailing-spaces.
if strings.HasPrefix(trimmed, " ") {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/diagnosing-bugs] The trimmed variable at line 36 is defined as strings.TrimRight(line, " ") — trimming spaces only — while the other two changed files use strings.TrimRight(line, " \t"). Any trailing tab character on a content line will survive into the generated YAML and still trigger a yamllint trailing-spaces warning.

💡 Suggested fix

Change line 36 from:

trimmed := strings.TrimRight(line, " ")

to:

trimmed := strings.TrimRight(line, " \t")

This makes the trim consistent with compiler_yaml_runtime_setup.go and compiler_yaml_step_conversion.go.

@copilot please address this.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot create/find and reuse helper to write / trim string in yaml

Copilot AI and others added 2 commits July 20, 2026 04:51
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
The three emission functions trimmed trailing whitespace from every
line including literal/folded block-scalar payloads (run:, script:
bodies). This is semantically unsafe: a backslash followed by spaces
becomes a bare backslash (line continuation), heredoc indentation can
shift, and template literal content can change.

The normalizeBlankLines pass already preserves block-scalar content
byte-for-byte (documented invariant in compiler_yaml_normalize.go).
Trimming at the emission point conflicts with that contract. The 8
trailing-spaces yamllint warnings that prompted this PR all originate
from user-authored block-scalar content; they are accepted as a
known limitation rather than risking a semantic change.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@copilot run pr-finisher skill

Reverted all three emission-level trimming changes in commit $(git rev-parse --short HEAD). The reviewer is correct — trimming every emitted line is block-scalar-unsafe (e.g. \ \ flips shell line-continuation semantics). All 8 trailing-spaces warnings originate from user-authored block-scalar content (run: / script: bodies), so they're accepted as a known limitation consistent with the normalizeBlankLines preservation contract. Local validation (fmt, lint, go test ./pkg/workflow/) is green.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot yamllint issues in .md files when applicable

Copilot AI and others added 3 commits July 20, 2026 05:06
…ross emitters

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
… emitters

Introduces yamlBlockScalarState (update method) and appendYAMLLine in a new
compiler_yaml_line_writer.go so that the logic for "trim structural lines,
preserve block-scalar payload verbatim" lives in one place and is reused by:

  - writeStepsSection (compiler_yaml_step_lifecycle.go)
  - ConvertStepToYAML  (compiler_yaml_step_conversion.go)
  - addCustomStepsAsIs + addCustomStepsWithRuntimeInsertion
    (compiler_yaml_runtime_setup.go)

The helper trims trailing whitespace from structural YAML lines (fixing the
yamllint trailing-spaces warnings) while writing block-scalar payload lines
verbatim so that semantically significant whitespace — shell backslash-newline
continuations, heredoc indentation, template literal spacing — is preserved.
Blank lines are always emitted as bare newlines regardless of block-scalar
state to avoid trailing-space violations in the generated YAML.

The yamlBlockScalarState.update method reuses the blockScalarHeaderIndentForLine
and countLeadingSpaces helpers from compiler_yaml_normalize.go, applying the
same detection logic that normalizeBlankLines already uses.

Tests added in compiler_yaml_test.go: TestYamlBlockScalarStateUpdate (6
sub-cases) and TestAppendYAMLLine (3 sub-cases).

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@copilot create/find and reuse helper to write / trim string in yaml

Done in commits 35817dc (and refactor: rename bs → blockScalarState). Added yamlBlockScalarState + appendYAMLLine in compiler_yaml_line_writer.go and wired all four emitters through it:

  • writeStepsSection (lifecycle.go) — calls blockScalarState.update(line) with the original source line (before the 2-space indent strip) so indent-based entry/exit detection stays accurate, then delegates to appendYAMLLine with the appropriate prefix and adjusted content.
  • ConvertStepToYAML (conversion.go) — replaces the inline blank/non-blank branch with a single appendYAMLLine call per line.
  • addCustomStepsAsIs / addCustomStepsWithRuntimeInsertion (runtime_setup.go) — the blockScalarState instance is shared across both loops in addCustomStepsWithRuntimeInsertion so state persists correctly through checkout-step look-ahead.

appendYAMLLine trims trailing whitespace on structural lines and writes block-scalar payload verbatim, reusing the same blockScalarHeaderIndentForLine / countLeadingSpaces helpers that normalizeBlankLines already uses.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot recompile, add tests

… warnings in lock files

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@copilot yamllint issues in .md files when applicable

Done in commit fix: remove trailing whitespace from .md source files to fix yamllint warnings in lock files.

Fixed trailing whitespace directly in the source .md files (the safe alternative to generator-level trimming):

  • issue-monster.md — removed trailing spaces from 2 lines in a JS filter (pr =>, OPEN &&)
  • shared/discussions-data-fetch.md — removed trailing spaces from 3 lines in a jq filter (.discussions.nodes, number,, createdAt,)

The affected lock files were recompiled. yamllint now reports 1 warning (down from 9) — only the known deployment-incident-monitor comments-indentation edge case remains.

Copilot AI and others added 2 commits July 20, 2026 05:59
…uralTrailingSpaces

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ll continuation risk

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@copilot recompile, add tests

Done in commits test: add TestWriteStepsSection... and test: clarify backslash-space test cases....

Tests added (both in pkg/workflow/compiler_yaml_test.go):

  • TestWriteStepsSection — verifies writeStepsSection trims structural trailing spaces and preserves block-scalar payload verbatim (including the \ backslash+spaces case)
  • TestAddCustomStepsAsIsTrimsStructuralTrailingSpaces — same verification for addCustomStepsAsIs

TestYamlBlockScalarStateUpdate and TestAppendYAMLLine (the helper-level tests) were already added in commit ab845fa.

Recompile: make recompile ran 258 workflows with 0 errors; all lock files confirmed in sync by check-stale-lock-files.

@pelikhan
pelikhan merged commit f380e90 into main Jul 20, 2026
@pelikhan
pelikhan deleted the fix/yamllint-trailing-spaces-custom-steps-b09ee4f52f4963ce branch July 20, 2026 06:02
@github-actions

Copy link
Copy Markdown
Contributor Author

Hey team 👋 — thanks for the yamllint trailing-spaces fix! The core technical change is solid: the new appendYAMLLine helper in compiler_yaml_line_writer.go and its reuse across emitters directly addresses issue #41507 and should reduce warnings from 9 to 1.

However, this PR mixes multiple concerns that would benefit from separation:

1. Diff Is Unfocused (6,132 lines across 34 files)

The changes span three distinct goals:

  • Trailing-space trimming logic (compiler_yaml_*.go, compiler_yaml_test.go) — direct fix
  • Regenerated lock files (.lock.yml files) — expected output of the logic change
  • ⚠️ Other file changes (source markdown cleanup, test removals, blog posts, scripts) — unrelated maintenance

Consider extracting non-yamllint-essential changes into a separate housekeeping PR. This would make the yamllint fix reviewable in isolation.

2. Test Coverage Notes

The new test file (136 lines) is good. Verify it covers:

  • Trailing spaces in block-scalar content (especially multiline jq/script pipelines where the fix matters)
  • Edge case: empty lines and lines with only whitespace

What Would Help

Review PR 46699 and make these improvements:

1. **Identify unrelated changes**: List all files modified that do NOT directly support yamllint trailing-space fixes. These are candidates for extraction into a separate PR.
2. **Check test coverage**: Ensure compiler_yaml_test.go tests include:
   - Multiline block scalars with embedded trailing spaces
   - Confirmation that workflow behavior is unchanged (semantics preserved)
3. **Clean up commit history**: Either rebase onto a recent main, or squash commits with a clear narrative (implement helper → apply across emitters → regenerate outputs).

The technical direction is right—just needs tighter focus!

Generated by ✅ Contribution Check · 58.5 AIC · ⌖ 11.1 AIC · ⊞ 6.2K ·

@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v0.82.14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants