Skip to content

Commit f380e90

Browse files
[yamllint-fixer] Reduce yamllint trailing-spaces noise in generated lock files (#46699)
1 parent 38bf71e commit f380e90

10 files changed

Lines changed: 377 additions & 40 deletions

.github/workflows/dataflow-pr-discussion-dataset.lock.yml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/deep-report.lock.yml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/issue-monster.lock.yml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/issue-monster.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ on:
284284
}
285285
286286
// Exclude issues with open PRs from Copilot coding agent
287-
const openCopilotPRs = issue.linkedPRs?.filter(pr =>
288-
pr.state === 'OPEN' &&
287+
const openCopilotPRs = issue.linkedPRs?.filter(pr =>
288+
pr.state === 'OPEN' &&
289289
(pr.author === 'copilot-swe-agent' || pr.author?.includes('copilot'))
290290
) || [];
291291
if (openCopilotPRs.length > 0) {

.github/workflows/shared/discussions-data-fetch.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ steps:
9797
9898
# Extract discussions and normalize structure
9999
echo "$RESULT" | jq -r '
100-
.data.repository.discussions.nodes
100+
.data.repository.discussions.nodes
101101
| map({
102-
number,
102+
number,
103103
title,
104104
body,
105-
createdAt,
105+
createdAt,
106106
updatedAt,
107107
url,
108108
category: .category.name,
@@ -180,7 +180,7 @@ This shared component fetches open discussions from the repository, with intelli
180180
- **Cache Key**: `discussions-data` for workflow-level sharing
181181
- **Cache Files**: Stored with today's date in the filename (e.g., `discussions-2024-11-18.json`)
182182
- **Cache Location**: `/tmp/gh-aw/cache-memory/`
183-
- **Cache Benefits**:
183+
- **Cache Benefits**:
184184
- Multiple workflows running on the same day share the same discussions data
185185
- Reduces GitHub API rate limit usage
186186
- Faster workflow execution after first fetch of the day
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package workflow
2+
3+
import "strings"
4+
5+
// yamlBlockScalarState tracks whether the scanner is currently inside a YAML
6+
// literal (|) or folded (>) block scalar. It is used by appendYAMLLine to
7+
// decide whether a line's trailing whitespace may be safely trimmed.
8+
//
9+
// The zero value is ready to use. Create a new instance per YAML stream and
10+
// pass it to every appendYAMLLine call in that stream.
11+
type yamlBlockScalarState struct {
12+
pending bool // saw a block-scalar header; waiting for the first content line
13+
active bool // inside a block scalar's payload
14+
headerIndent int // leading-space count of the block-scalar header line
15+
bodyIndent int // leading-space count of the first payload line
16+
}
17+
18+
// update advances the block-scalar state machine for sourceLine (the raw line
19+
// as it appears in the source YAML, before any prefix or indentation adjustment
20+
// is applied). It returns true when sourceLine is part of a block scalar's
21+
// payload and its content must NOT be right-trimmed.
22+
func (s *yamlBlockScalarState) update(sourceLine string) bool {
23+
trimmed := strings.TrimRight(sourceLine, " \t")
24+
25+
if s.pending || s.active {
26+
if trimmed == "" {
27+
// Blank lines keep the state alive without advancing it:
28+
// inside an active scalar they are payload; inside a pending
29+
// scalar they simply delay the first content line.
30+
return s.active
31+
}
32+
lineIndent := countLeadingSpaces(sourceLine)
33+
if s.pending {
34+
if lineIndent <= s.headerIndent {
35+
// No indented content followed the header; leave the scalar.
36+
s.pending = false
37+
// Fall through to structural handling below.
38+
} else {
39+
s.bodyIndent = lineIndent
40+
s.active = true
41+
s.pending = false
42+
return true // first payload line
43+
}
44+
}
45+
if s.active {
46+
if lineIndent < s.bodyIndent {
47+
// Outdented non-blank line: we have left the block scalar.
48+
s.active = false
49+
// Fall through to structural handling below.
50+
} else {
51+
return true // still inside the block scalar
52+
}
53+
}
54+
}
55+
56+
// Structural line: detect whether it introduces a new block scalar.
57+
if trimmed != "" {
58+
if headerIndent, ok := blockScalarHeaderIndentForLine(trimmed); ok {
59+
s.pending = true
60+
s.headerIndent = headerIndent
61+
}
62+
}
63+
return false
64+
}
65+
66+
// appendYAMLLine writes content to b with the given prefix.
67+
//
68+
// - Blank content (empty or whitespace-only) is always written as a bare
69+
// newline with no prefix, regardless of isBlockScalarContent, to avoid
70+
// emitting lines that contain only spaces (yamllint trailing-spaces).
71+
// - When isBlockScalarContent is true, non-blank content is written verbatim
72+
// so that trailing whitespace that is semantically significant inside a
73+
// shell script or template literal is preserved.
74+
// - When isBlockScalarContent is false, trailing whitespace is trimmed before
75+
// writing so that yamllint trailing-spaces warnings are suppressed.
76+
//
77+
// Callers obtain isBlockScalarContent by calling yamlBlockScalarState.update
78+
// with the original source line. When the source indentation is adjusted before
79+
// writing (e.g. a 2-space prefix is stripped in writeStepsSection), callers
80+
// must still pass the original source line to update so that indent-based
81+
// entry/exit detection remains accurate, and then pass the adjusted content
82+
// here.
83+
func appendYAMLLine(b *strings.Builder, prefix, content string, isBlockScalarContent bool) {
84+
// Always emit blank lines as bare newlines to avoid trailing-space violations.
85+
if strings.TrimRight(content, " \t") == "" {
86+
b.WriteByte('\n')
87+
return
88+
}
89+
if isBlockScalarContent {
90+
b.WriteString(prefix)
91+
b.WriteString(content)
92+
b.WriteByte('\n')
93+
return
94+
}
95+
b.WriteString(prefix)
96+
b.WriteString(strings.TrimRight(content, " \t"))
97+
b.WriteByte('\n')
98+
}

pkg/workflow/compiler_yaml_runtime_setup.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,10 @@ func (c *Compiler) addCustomStepsAsIs(yaml *strings.Builder, customSteps string)
312312
// Remove "steps:" line and adjust indentation
313313
lines := strings.Split(customSteps, "\n")
314314
if len(lines) > 1 {
315+
var blockScalarState yamlBlockScalarState
315316
for _, line := range lines[1:] {
316-
// Skip empty lines
317-
if strings.TrimSpace(line) == "" {
318-
yaml.WriteString("\n")
319-
continue
320-
}
321-
322-
// Simply add 6 spaces for job context indentation
323-
yaml.WriteString(" " + line + "\n")
317+
isBS := blockScalarState.update(line)
318+
appendYAMLLine(yaml, " ", line, isBS)
324319
}
325320
}
326321
}
@@ -337,9 +332,11 @@ func (c *Compiler) addCustomStepsWithRuntimeInsertion(yaml *strings.Builder, cus
337332

338333
insertedRuntime := false
339334
i := 1 // Start from index 1 to skip "steps:" line
335+
var blockScalarState yamlBlockScalarState
340336

341337
for i < len(lines) {
342338
line := lines[i]
339+
isBS := blockScalarState.update(line)
343340

344341
// Skip empty lines
345342
if strings.TrimSpace(line) == "" {
@@ -349,7 +346,7 @@ func (c *Compiler) addCustomStepsWithRuntimeInsertion(yaml *strings.Builder, cus
349346
}
350347

351348
// Add the line with proper indentation
352-
yaml.WriteString(" " + line + "\n")
349+
appendYAMLLine(yaml, " ", line, isBS)
353350

354351
// Check if this line starts a step with "- name:" or "- uses:"
355352
trimmed := strings.TrimSpace(line)
@@ -389,11 +386,8 @@ func (c *Compiler) addCustomStepsWithRuntimeInsertion(yaml *strings.Builder, cus
389386
}
390387

391388
// Add the line
392-
if nextTrimmed == "" {
393-
yaml.WriteString("\n")
394-
} else {
395-
yaml.WriteString(" " + nextLine + "\n")
396-
}
389+
nextIsBS := blockScalarState.update(nextLine)
390+
appendYAMLLine(yaml, " ", nextLine, nextIsBS)
397391
i++
398392
}
399393

0 commit comments

Comments
 (0)