Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/release.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/cli/doctor_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package cli
import (
"errors"

"github.com/github/gh-aw/pkg/logger"
"github.com/spf13/cobra"
)

var doctorCommandLog = logger.New("cli:doctor_command")

var runDoctorSetupAuth = RunSetupAuth
var runDoctorSetupRepositoryCheck = RunSetupRepositoryCheck

Expand Down Expand Up @@ -35,9 +38,11 @@ repository exists, resolves the owner type, and inspects checkout state.`,
return errors.New("--dir and --require-owner-type require --repo")
}

doctorCommandLog.Print("Running authentication diagnostics (no --repo provided)")
return runDoctorSetupAuth(SetupAuthOptions{Ctx: cmd.Context(), JSON: jsonOutput})
}

doctorCommandLog.Printf("Running repository diagnostics for %q (require-owner-type=%q)", repo, requireOwnerType)
return runDoctorSetupRepositoryCheck(SetupRepositoryCheckOptions{
Ctx: cmd.Context(),
Repo: repo,
Expand Down
11 changes: 10 additions & 1 deletion pkg/workflow/compiler_yaml_normalize.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package workflow

import "strings"
import (
"strings"

"github.com/github/gh-aw/pkg/logger"
)

var compilerYAMLNormalizeLog = logger.New("workflow:compiler_yaml_normalize")

// maxConsecutiveBlankLines is the largest run of blank lines allowed in the
// normalized YAML. yamllint's empty-lines rule flags more than two consecutive
Expand All @@ -22,6 +28,7 @@ const maxConsecutiveBlankLines = 2
// This implementation avoids strings.Split/strings.Join to reduce allocations: it scans
// the input byte-by-byte and builds the result with a single pre-allocated strings.Builder.
func normalizeBlankLines(yamlContent string) string {
compilerYAMLNormalizeLog.Printf("Normalizing blank lines in %d bytes of YAML", len(yamlContent))
var b strings.Builder
b.Grow(len(yamlContent))

Expand Down Expand Up @@ -118,11 +125,13 @@ func normalizeBlankLines(yamlContent string) string {
// the original strings.TrimRight(…, "\n") + "\n" behaviour for that case.
// NOTE: b.String()[:0] must NOT be used here; the early return is intentional.
if lastNonBlankEnd == 0 {
compilerYAMLNormalizeLog.Print("Input contained no non-blank lines, returning single newline")
return "\n"
}
// Slice the builder string to drop trailing blank lines. b.String() copies
// the builder's internal buffer into a new string once; the slice avoids a
// second copy that a separate strings.Builder trim would incur.
compilerYAMLNormalizeLog.Printf("Normalized YAML to %d bytes", lastNonBlankEnd)
return b.String()[:lastNonBlankEnd]
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/workflow/compiler_yaml_policy.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package workflow

import "github.com/github/gh-aw/pkg/logger"

var compilerYAMLPolicyLog = logger.New("workflow:compiler_yaml_policy")

// effectiveStrictMode computes the effective strict mode for a workflow.
// Priority: CLI flag (c.strictMode) > frontmatter strict field > default (true).
// This should be used when emitting metadata/env vars to correctly reflect the
// workflow's strictness as inferred from the source (frontmatter).
func (c *Compiler) effectiveStrictMode(frontmatter map[string]any) bool {
if c.strictMode {
// CLI flag takes precedence
compilerYAMLPolicyLog.Print("Strict mode enabled by CLI flag")
return true
}
if strictVal, exists := frontmatter["strict"]; exists {
if strictBool, ok := strictVal.(bool); ok {
compilerYAMLPolicyLog.Printf("Strict mode resolved from frontmatter strict field: %v", strictBool)
return strictBool
}
}
// Default: strict mode is on when no explicit setting
compilerYAMLPolicyLog.Print("Strict mode defaulting to true (no explicit setting)")
return true
}

Expand All @@ -25,6 +32,7 @@ func (c *Compiler) effectiveStrictMode(frontmatter map[string]any) bool {
// to approve all changes.
func (c *Compiler) effectiveSafeUpdate(data *WorkflowData) bool {
if c.approve {
compilerYAMLPolicyLog.Print("Safe update disabled: --approve flag set")
return false
}
return c.effectiveStrictMode(data.RawFrontmatter)
Expand Down
8 changes: 8 additions & 0 deletions pkg/workflow/frontmatter_trigger_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import (
"fmt"
"slices"
"strings"

"github.com/github/gh-aw/pkg/logger"
)

var frontmatterTriggerLog = logger.New("workflow:frontmatter_trigger_helpers")

// extractOnTriggerValue returns the raw value for on.<trigger> when the frontmatter
// contains an "on" map with that trigger configured.
func extractOnTriggerValue(frontmatter map[string]any, trigger string) (any, bool) {
Expand Down Expand Up @@ -76,8 +80,10 @@ func extractDeploymentStatusStateCondition(frontmatter map[string]any) (string,
return "", nil
}

frontmatterTriggerLog.Printf("Building deployment_status state condition from %d state value(s)", len(states))
for _, s := range states {
if !isValidDeploymentStatusState(s) {
frontmatterTriggerLog.Printf("Rejecting invalid on.deployment_status.state value %q", s)
return "", fmt.Errorf("invalid on.deployment_status.state value %q: must be one of %s",
s, strings.Join(validDeploymentStatusStates, ", "))
}
Expand Down Expand Up @@ -134,8 +140,10 @@ func extractWorkflowRunConclusionCondition(frontmatter map[string]any) (string,
return "", nil
}

frontmatterTriggerLog.Printf("Building workflow_run conclusion condition from %d conclusion value(s)", len(conclusions))
for _, c := range conclusions {
if !isValidWorkflowRunConclusion(c) {
frontmatterTriggerLog.Printf("Rejecting invalid on.workflow_run.conclusion value %q", c)
return "", fmt.Errorf("invalid on.workflow_run.conclusion value %q: must be one of %s",
c, strings.Join(validWorkflowRunConclusions, ", "))
}
Expand Down
Loading