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
5 changes: 5 additions & 0 deletions pkg/types/input_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package types
import (
"fmt"
"strconv"

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

var inputDefinitionLog = logger.New("types:input_definition")

// InputDefinition defines an input parameter for workflows, safe-jobs, and imported workflows.
// The structure follows the workflow_dispatch input schema from GitHub Actions:
// https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onworkflow_dispatchinputs
Expand Down Expand Up @@ -41,6 +45,7 @@ func (i *InputDefinition) GetDefaultAsString() string {
}
return fmt.Sprintf("%g", v)
default:
inputDefinitionLog.Printf("Coercing default value of unexpected type %T to string via fallback formatting", v)
return fmt.Sprintf("%v", v)
}
}
2 changes: 2 additions & 0 deletions pkg/typeutil/effective_token_limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ func ParseInt64KMSuffix(raw string) (int64, bool) {

parsed, err := strconv.ParseInt(trimmed, 10, 64)
if err != nil || parsed <= 0 {
typeutilLog.Printf("Rejected K/M-suffixed value %q: not a positive base-10 integer", raw)
return 0, false
}
if parsed > math.MaxInt64/multiplier {
typeutilLog.Printf("Rejected K/M-suffixed value %q: would overflow int64 (multiplier=%d)", raw, multiplier)
return 0, false
}
return parsed * multiplier, true
Expand Down
8 changes: 8 additions & 0 deletions pkg/workflow/daily_effective_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (
"strconv"
"strings"

"github.com/github/gh-aw/pkg/logger"
"github.com/github/gh-aw/pkg/typeutil"
"github.com/github/gh-aw/pkg/workflow/compilerenv"
)

var dailyEffectiveWorkflowLog = logger.New("workflow:daily_effective_workflow")

const maxDailyEffectiveTokensField = "max-daily-effective-tokens"

// parseMaxDailyEffectiveTokensValue normalizes max-daily-effective-tokens
Expand Down Expand Up @@ -70,20 +73,25 @@ func resolveMaxDailyEffectiveTokensFromRaw(raw any) (*string, bool) {

func resolveMaxDailyEffectiveTokens(frontmatter map[string]any, importedJSON string) *string {
if value, found := resolveMaxDailyEffectiveTokensFromRaw(frontmatter[maxDailyEffectiveTokensField]); found {
dailyEffectiveWorkflowLog.Print("Resolved max-daily-effective-tokens from workflow frontmatter")
return value
}
if importedJSON == "" {
dailyEffectiveWorkflowLog.Print("No frontmatter value and no imported config; falling back to default max-daily-effective-tokens")
defaultValue := compilerenv.ResolveDefaultMaxDailyEffectiveTokens("")
return parseMaxDailyEffectiveTokensValue(defaultValue)
}
var imported any
if err := json.Unmarshal([]byte(importedJSON), &imported); err != nil {
dailyEffectiveWorkflowLog.Printf("Failed to unmarshal imported max-daily-effective-tokens JSON, using default: %v", err)
defaultValue := compilerenv.ResolveDefaultMaxDailyEffectiveTokens("")
return parseMaxDailyEffectiveTokensValue(defaultValue)
}
if value, found := resolveMaxDailyEffectiveTokensFromRaw(imported); found {
dailyEffectiveWorkflowLog.Print("Resolved max-daily-effective-tokens from imported config")
return value
}
dailyEffectiveWorkflowLog.Print("Imported config did not provide a usable value; falling back to default max-daily-effective-tokens")
defaultValue := compilerenv.ResolveDefaultMaxDailyEffectiveTokens("")
return parseMaxDailyEffectiveTokensValue(defaultValue)
}
Expand Down
30 changes: 25 additions & 5 deletions pkg/workflow/utc_offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,39 @@ import (
"strconv"
"strings"
"time"

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

var utcOffsetLog = logger.New("workflow:utc_offset")

var utcOffsetPattern = regexp.MustCompile(`^([+-])(\d{2}):(\d{2})$`)

// NormalizeUTCOffset validates and normalizes a numeric UTC offset.
func NormalizeUTCOffset(raw string) (string, error) {
trimmed := strings.TrimSpace(raw)
matches := utcOffsetPattern.FindStringSubmatch(trimmed)
if matches == nil {
utcOffsetLog.Printf("UTC offset %q does not match expected +HH:MM/-HH:MM format", trimmed)
return "", fmt.Errorf("must be a numeric UTC offset like +00:00 or -08:00")
}

hours, _ := strconv.Atoi(matches[2])
minutes, _ := strconv.Atoi(matches[3])
hours, err := strconv.Atoi(matches[2])
if err != nil {
return "", fmt.Errorf("must be a numeric UTC offset like +00:00 or -08:00")
}
minutes, err := strconv.Atoi(matches[3])
if err != nil {
return "", fmt.Errorf("must be a numeric UTC offset like +00:00 or -08:00")
}
if hours > 14 || minutes > 59 || (hours == 14 && minutes != 0) {
utcOffsetLog.Printf("UTC offset %q out of range (hours=%d, minutes=%d)", trimmed, hours, minutes)
return "", fmt.Errorf("must be a numeric UTC offset like +00:00 or -08:00")
}

return fmt.Sprintf("%s%02d:%02d", matches[1], hours, minutes), nil
normalized := fmt.Sprintf("%s%02d:%02d", matches[1], hours, minutes)
utcOffsetLog.Printf("Normalized UTC offset %q to %q", trimmed, normalized)
return normalized, nil
}

// ParseUTCOffsetLocation converts a numeric UTC offset to a fixed time.Location.
Expand All @@ -34,8 +48,14 @@ func ParseUTCOffsetLocation(raw string) (*time.Location, error) {
return nil, err
}

hours, _ := strconv.Atoi(normalized[1:3])
minutes, _ := strconv.Atoi(normalized[4:6])
hours, err := strconv.Atoi(normalized[1:3])
if err != nil {
return nil, fmt.Errorf("invalid UTC offset format: %w", err)
}
minutes, err := strconv.Atoi(normalized[4:6])
if err != nil {
return nil, fmt.Errorf("invalid UTC offset format: %w", err)
}
offsetSeconds := hours*60*60 + minutes*60
if normalized[0] == '-' {
offsetSeconds = -offsetSeconds
Expand Down
Loading