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
9 changes: 9 additions & 0 deletions pkg/cli/bootstrap_profile_actions_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import (

"github.com/cli/go-gh/v2/pkg/api"
"github.com/github/gh-aw/pkg/console"
"github.com/github/gh-aw/pkg/logger"
"github.com/github/gh-aw/pkg/repoutil"
"github.com/github/gh-aw/pkg/stringutil"
)

var bootstrapActionsRepoLog = logger.New("cli:bootstrap_profile_actions_repo")

func runBootstrapRepoVariableAction(ctx context.Context, repo string, action repositoryPackageBootstrapAction, state *bootstrapProfileExistingState) (bool, error) {
bootstrapActionsRepoLog.Printf("Running repo variable action: repo=%s, name=%s", repo, action.Name)
if _, exists := state.variables[action.Name]; exists {
bootstrapActionsRepoLog.Printf("Skipping variable %s: already set on repo", action.Name)
return false, nil
}
value, ok, err := resolveBootstrapTextValue(bootstrapRepositoryVariableEnvName(action.Name), action.Prompt, action.Description, action.Default, action.Enum, action.Optional)
Expand All @@ -30,7 +35,9 @@ func runBootstrapRepoVariableAction(ctx context.Context, repo string, action rep
}

func runBootstrapRepoSecretAction(ctx context.Context, repo string, action repositoryPackageBootstrapAction, state *bootstrapProfileExistingState) (bool, error) {
bootstrapActionsRepoLog.Printf("Running repo secret action: repo=%s, name=%s", repo, action.Name)
if _, exists := state.secrets[action.Name]; exists {
bootstrapActionsRepoLog.Printf("Skipping secret %s: already set on repo", action.Name)
return false, nil
}
value, ok, err := resolveBootstrapSecretValue(bootstrapRepositorySecretEnvName(action.Name), action.Prompt, action.Description, action.Optional)
Expand All @@ -48,7 +55,9 @@ func runBootstrapRepoSecretAction(ctx context.Context, repo string, action repos
}

func runBootstrapCopilotAuthAction(ctx context.Context, repo string, action repositoryPackageBootstrapAction, state *bootstrapProfileExistingState, usesActionsToken bool) (bool, error) {
bootstrapActionsRepoLog.Printf("Running Copilot auth action: repo=%s, usesActionsToken=%v", repo, usesActionsToken)
if usesActionsToken {
bootstrapActionsRepoLog.Print("Skipping Copilot PAT setup: workflows already support Actions token auth")
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Skipping Copilot PAT setup because selected workflows already support GitHub Actions token auth."))
return false, nil
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/cli/bootstrap_profile_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ import (
"strings"

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

var bootstrapGitLog = logger.New("cli:bootstrap_profile_git")

func runBootstrapCommitAndPushAction(ctx context.Context, repoDir string, action repositoryPackageBootstrapAction) error {
bootstrapGitLog.Printf("Running commit-and-push action: repoDir=%q", repoDir)
if repoDir == "" {
bootstrapGitLog.Print("Rejecting commit-and-push: no local checkout directory provided")
return errors.New("bootstrap commit-and-push requires a local checkout directory. Example: rerun from a git checkout and then rerun gh aw add from that checkout")
}

Expand All @@ -21,6 +26,7 @@ func runBootstrapCommitAndPushAction(ctx context.Context, repoDir string, action
return err
}
if !pending {
bootstrapGitLog.Print("Skipping commit-and-push: local checkout is already clean")
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Skipping commit and push because the local checkout is already clean."))
return nil
}
Expand All @@ -35,10 +41,12 @@ func runBootstrapCommitAndPushAction(ctx context.Context, repoDir string, action
if err != nil {
return fmt.Errorf("failed to determine current branch for bootstrap commit-and-push: %w", err)
}
bootstrapGitLog.Printf("Pushing bootstrap changes to origin: branch=%s", branch)
if _, err := runBootstrapGitCommand(ctx, repoDir, "push", "-u", "origin", branch); err != nil {
return err
}

bootstrapGitLog.Print("Committed and pushed bootstrap changes successfully")
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Committed and pushed bootstrap changes"))
return nil
}
Expand All @@ -52,6 +60,7 @@ func bootstrapRepoHasPendingChanges(ctx context.Context, repoDir string) (bool,
}

func runBootstrapGitCommand(ctx context.Context, repoDir string, args ...string) ([]byte, error) {
bootstrapGitLog.Printf("Running git command in %s: git %s", repoDir, strings.Join(args, " "))
cmd := exec.CommandContext(ctx, "git", args...)
cmd.Dir = repoDir
output, err := cmd.CombinedOutput()
Expand Down
9 changes: 9 additions & 0 deletions pkg/cli/bootstrap_profile_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ import (

"charm.land/huh/v2"
"github.com/github/gh-aw/pkg/console"
"github.com/github/gh-aw/pkg/logger"
"github.com/github/gh-aw/pkg/parser"
"github.com/github/gh-aw/pkg/repoutil"
"github.com/github/gh-aw/pkg/tty"
"github.com/github/gh-aw/pkg/workflow"
)

var bootstrapProfileHelpersLog = logger.New("cli:bootstrap_profile_helpers")

func runBootstrapRequireOwnerType(ctx context.Context, repo string, action repositoryPackageBootstrapAction) error {
owner, _, err := repoutil.SplitRepoSlug(repo)
if err != nil {
Expand Down Expand Up @@ -69,13 +72,16 @@ func parseBootstrapNames(output []byte) []string {
}

func resolveBootstrapTextValue(envName, title, description, defaultValue string, allowed []string, optional bool) (string, bool, error) {
bootstrapProfileHelpersLog.Printf("Resolving text value: env=%s, optional=%v, hasDefault=%v", envName, optional, defaultValue != "")
if envValue := strings.TrimSpace(os.Getenv(envName)); envValue != "" {
bootstrapProfileHelpersLog.Printf("Resolved %s from environment variable", envName)
if err := validateBootstrapEnumValue(envValue, allowed, optional); err != nil {
return "", false, err
}
return envValue, true, nil
}
if !tty.IsStderrTerminal() {
bootstrapProfileHelpersLog.Printf("Resolving %s non-interactively (stderr is not a terminal)", envName)
if defaultValue != "" {
if err := validateBootstrapEnumValue(defaultValue, allowed, optional); err != nil {
return "", false, err
Expand Down Expand Up @@ -321,6 +327,7 @@ func htmlEscape(value string) string {
}

func openBootstrapBrowser(url string) bool {
bootstrapProfileHelpersLog.Printf("Opening browser for bootstrap URL: goos=%s", runtime.GOOS)
commands := [][]string{{"gh", "browse", url}}
switch runtime.GOOS {
case "darwin":
Expand All @@ -333,12 +340,14 @@ func openBootstrapBrowser(url string) bool {
for _, args := range commands {
cmd := exec.Command(args[0], args[1:]...)
if err := cmd.Start(); err == nil {
bootstrapProfileHelpersLog.Printf("Launched browser via %q", args[0])
go func() {
_ = cmd.Wait()
}()
return true
}
}
bootstrapProfileHelpersLog.Print("Failed to launch a browser: no launcher command succeeded")
return false
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/console/timezone.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import (
"fmt"
"sync"
"time"

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

var timezoneLog = logger.New("console:timezone")

var (
timeLocationMu sync.RWMutex
timeLocation *time.Location
)

// SetTimeLocation configures the location used when rendering time.Time values.
func SetTimeLocation(location *time.Location) {
timezoneLog.Printf("Setting time location override: location=%v", location)
timeLocationMu.Lock()
defer timeLocationMu.Unlock()
timeLocation = location
Expand All @@ -35,6 +40,7 @@ func formatConfiguredTimeValue(timeVal time.Time) string {
return timeVal.Format("2006-01-02 15:04:05")
}

timezoneLog.Printf("Formatting time value in configured location: %v", location)
localTime := timeVal.In(location)
_, offsetSeconds := localTime.Zone()
return fmt.Sprintf("%s UTC%s", localTime.Format("2006-01-02 15:04:05"), formatUTCOffset(offsetSeconds))
Expand Down
11 changes: 10 additions & 1 deletion pkg/workflow/compiler_yaml_line_writer.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 yamlLineWriterLog = logger.New("workflow:compiler_yaml_line_writer")

// yamlBlockScalarState tracks whether the scanner is currently inside a YAML
// literal (|) or folded (>) block scalar. It is used by appendYAMLLine to
Expand Down Expand Up @@ -39,13 +45,15 @@ func (s *yamlBlockScalarState) update(sourceLine string) bool {
s.bodyIndent = lineIndent
s.active = true
s.pending = false
yamlLineWriterLog.Printf("Entering block scalar payload: headerIndent=%d, bodyIndent=%d", s.headerIndent, s.bodyIndent)
return true // first payload line
}
}
if s.active {
if lineIndent < s.bodyIndent {
// Outdented non-blank line: we have left the block scalar.
s.active = false
yamlLineWriterLog.Printf("Leaving block scalar payload: lineIndent=%d < bodyIndent=%d", lineIndent, s.bodyIndent)
// Fall through to structural handling below.
} else {
return true // still inside the block scalar
Expand All @@ -58,6 +66,7 @@ func (s *yamlBlockScalarState) update(sourceLine string) bool {
if headerIndent, ok := blockScalarHeaderIndentForLine(trimmed); ok {
s.pending = true
s.headerIndent = headerIndent
yamlLineWriterLog.Printf("Detected block scalar header: headerIndent=%d", headerIndent)
}
}
return false
Expand Down
Loading