Commit b036a5e
Eric Bower
·
2026-05-07 12:43:12 -0400 EDT
parent 85f918b
chore: cleanup
2 files changed,
+19,
-16
M
main.go
M
main.go
+18,
-15
| ... | ... | @@ -18,8 +18,6 @@ import ( | |
| 18 | 18 | "strings" | |
| 19 | 19 | "syscall" | |
| 20 | 20 | "time" | |
| 21 | - | ||
| 22 | - | ||
| 23 | 21 | ) | |
| 24 | 22 | ||
| 25 | 23 | type WorkspaceFactory func(cfg *Cfg, logger *slog.Logger, source string) Workspace |
| ... | ... | @@ -44,7 +42,7 @@ type Cfg struct { | |
| 44 | 42 | MonitorInterval time.Duration | |
| 45 | 43 | NewWorkspace WorkspaceFactory | |
| 46 | 44 | StatusOutput io.Writer // where status JSONL is written (default: os.Stdout) | |
| 47 | - | StatusFilter string // "terminal" (default) or "all" | |
| 45 | + | IncludeRunning bool // emit running status updates in addition to terminal | |
| 48 | 46 | HumanOutput bool // human-readable output instead of JSONL / slog | |
| 49 | 47 | Wait bool // block until job completes, print history and summary | |
| 50 | 48 | } |
| ... | ... | @@ -67,10 +65,10 @@ func NewCfg() (*Cfg, string, bool) { | |
| 67 | 65 | flag.StringVar(&event, "event", "", "event JSON to run (alternative to reading from stdin)") | |
| 68 | 66 | flag.DurationVar(&monitorInterval, "monitor-interval", 5*time.Second, "interval for monitoring zmx sessions") | |
| 69 | 67 | flag.StringVar(&logLevel, "log-level", "info", "log level: debug, info, warn, error") | |
| 70 | - | var statusFilter string | |
| 68 | + | var includeRunning bool | |
| 71 | 69 | var human bool | |
| 72 | 70 | var wait bool | |
| 73 | - | flag.StringVar(&statusFilter, "status-filter", "terminal", "status output filter: terminal (default) or all") | |
| 71 | + | flag.BoolVar(&includeRunning, "include-running", false, "emit running status updates in addition to terminal (default: terminal only)") | |
| 74 | 72 | flag.BoolVar(&human, "human", false, "human-readable output (default: JSONL / slog)") | |
| 75 | 73 | flag.BoolVar(&wait, "wait", false, "block until job completes, printing session history and summary") | |
| 76 | 74 |
| ... | ... | @@ -91,7 +89,7 @@ func NewCfg() (*Cfg, string, bool) { | |
| 91 | 89 | ArtifactDir: artifactDir, | |
| 92 | 90 | Event: event, | |
| 93 | 91 | MonitorInterval: monitorInterval, | |
| 94 | - | StatusFilter: statusFilter, | |
| 92 | + | IncludeRunning: includeRunning, | |
| 95 | 93 | HumanOutput: human, | |
| 96 | 94 | Wait: wait, | |
| 97 | 95 | }, cmd, wantHelp |
| ... | ... | @@ -190,16 +188,18 @@ func printMonitorHelp() { | |
| 190 | 188 | fmt.Println(`pici monitor — poll ci.* zmx sessions, stage artifacts, publish status. | |
| 191 | 189 | ||
| 192 | 190 | USAGE | |
| 193 | - | pici monitor [flags] | |
| 194 | - | pici monitor --human | ssh pipe.pico.sh "pub build.status -b=false" | |
| 191 | + | pici monitor [flags] # JSONL to stdout (pipe to webhooks) | |
| 192 | + | pici monitor --human # human-readable terminal output | |
| 195 | 193 | ||
| 196 | 194 | OUTPUT MODES | |
| 197 | - | Default (JSONL): One JSON object per line to stdout, suitable for piping. | |
| 195 | + | Default (JSONL): One JSON object per line, suitable for piping to notifications. | |
| 198 | 196 | pici monitor > status.jsonl | |
| 197 | + | pici monitor | ssh pipe.pico.sh "pub build.status -b=false" | |
| 199 | 198 | pici monitor | while read -r line; do curl -sd"$line" $WEBHOOK; done | |
| 200 | 199 | ||
| 201 | - | --human: Selfci-style progress output for terminal viewing. | |
| 202 | - | pici monitor --human --status-filter all | |
| 200 | + | --human: Selfci-style progress output for terminal viewing (do not pipe). | |
| 201 | + | pici monitor --human | |
| 202 | + | pici monitor --human --include-running | |
| 203 | 203 | [2/3] 🚀 running: myrepo (1m23s) | |
| 204 | 204 | [3/3] ✅ success: myrepo (2m34s) | |
| 205 | 205 |
| ... | ... | @@ -208,8 +208,8 @@ FLAGS | |
| 208 | 208 | -ck <path> SSH certificate public key | |
| 209 | 209 | -artifact-dir <path> Local directory to stage artifacts (default: /tmp/pici-artifacts) | |
| 210 | 210 | -monitor-interval <dur> Poll interval (default: 5s) | |
| 211 | - | -status-filter <filter> "terminal" (default) or "all" | |
| 212 | - | -human Human-readable output instead of JSONL | |
| 211 | + | -include-running Emit running status updates in addition to terminal (default: terminal only) | |
| 212 | + | -human Human-readable output instead of JSONL (for terminal, not piping) | |
| 213 | 213 | -log-level <level> Log level: debug, info, warn, error (default: info)`) | |
| 214 | 214 | } | |
| 215 | 215 |
| ... | ... | @@ -345,6 +345,7 @@ type SessionInfo struct { | |
| 345 | 345 | } | |
| 346 | 346 | ||
| 347 | 347 | type StatusPayload struct { | |
| 348 | + | Timestamp string `json:"timestamp"` | |
| 348 | 349 | Name string `json:"name"` | |
| 349 | 350 | JobID string `json:"job_id"` | |
| 350 | 351 | Status string `json:"status"` |
| ... | ... | @@ -924,6 +925,7 @@ func monitorTick(cfg *Cfg, log *slog.Logger, output io.Writer, jobStates map[str | |
| 924 | 925 | renderJobFinal(output, name, jobID, group, duration, status, exitCode == 0, eventData.Workspace, cfg.ArtifactDir, artifactURL) | |
| 925 | 926 | } else { | |
| 926 | 927 | payload := StatusPayload{ | |
| 928 | + | Timestamp: time.Now().UTC().Format(time.RFC3339), | |
| 927 | 929 | Name: name, | |
| 928 | 930 | JobID: jobID, | |
| 929 | 931 | Status: status, |
| ... | ... | @@ -945,12 +947,13 @@ func monitorTick(cfg *Cfg, log *slog.Logger, output io.Writer, jobStates map[str | |
| 945 | 947 | } | |
| 946 | 948 | } else { | |
| 947 | 949 | log.Debug("job still running", "sessions", len(group)) | |
| 948 | - | // Publish running status only when filter is "all" | |
| 949 | - | if cfg.StatusFilter != "terminal" { | |
| 950 | + | // Publish running status only when --include-running is set | |
| 951 | + | if cfg.IncludeRunning { | |
| 950 | 952 | if cfg.HumanOutput { | |
| 951 | 953 | renderJobRunning(output, name, jobID, group, duration, jobStates) | |
| 952 | 954 | } else { | |
| 953 | 955 | payload := StatusPayload{ | |
| 956 | + | Timestamp: time.Now().UTC().Format(time.RFC3339), | |
| 954 | 957 | Name: name, | |
| 955 | 958 | JobID: jobID, | |
| 956 | 959 | Status: "running", |
+1,
-1
| ... | ... | @@ -59,7 +59,7 @@ zmx run step2 echo "hello from step2" | |
| 59 | 59 | MonitorInterval: 200 * time.Millisecond, | |
| 60 | 60 | NewWorkspace: defaultWorkspaceFactory, | |
| 61 | 61 | StatusOutput: statusBuf, | |
| 62 | - | StatusFilter: "all", | |
| 62 | + | IncludeRunning: true, | |
| 63 | 63 | } | |
| 64 | 64 | ||
| 65 | 65 | // 3. Run the runner (fire-and-forget, exits quickly) |