Commit 643168c
Eric Bower
·
2026-05-06 20:49:43 -0400 EDT
parent e3aec66
chore: cleanup
M
main.go
+43,
-0
| ... | ... | @@ -120,6 +120,10 @@ func main() { | |
| 120 | 120 | ||
| 121 | 121 | switch cmd { | |
| 122 | 122 | case "runner": | |
| 123 | + | if flag.Arg(1) == "--help" || flag.Arg(1) == "help" { | |
| 124 | + | printRunnerHelp() | |
| 125 | + | return | |
| 126 | + | } | |
| 123 | 127 | cfg.Logger.Debug("starting runner") | |
| 124 | 128 | if err := RunRunner(cfg); err != nil { | |
| 125 | 129 | cfg.Logger.Error("runner failed", "err", err) |
| ... | ... | @@ -153,6 +157,34 @@ func main() { | |
| 153 | 157 | } | |
| 154 | 158 | } | |
| 155 | 159 | ||
| 160 | + | func printRunnerHelp() { | |
| 161 | + | fmt.Println(`pici runner — execute a CI job from an event JSON payload. | |
| 162 | + | ||
| 163 | + | USAGE | |
| 164 | + | echo '<event-json>' | pici runner [flags] | |
| 165 | + | pici runner --event '<event-json>' [flags] | |
| 166 | + | ||
| 167 | + | EVENT JSON FIELDS | |
| 168 | + | type (required) Event type, e.g. "push", "merge_request" | |
| 169 | + | name (required) Repository name, used for session naming | |
| 170 | + | workspace (required) SSH source path to rsync, e.g. "git@github.com:user/repo.git" | |
| 171 | + | artifact_dest (optional) SSH destination for artifact sync, e.g. "user@host:/path" | |
| 172 | + | artifact_url (optional) Public URL for artifacts, e.g. "https://artifacts.pgs.sh/repo" | |
| 173 | + | ||
| 174 | + | EXAMPLE | |
| 175 | + | echo '{"type":"push","name":"myrepo","workspace":"git@github.com:user/myrepo.git"}' | pici runner | |
| 176 | + | ||
| 177 | + | FLAGS | |
| 178 | + | -pk <path> SSH private key for authenticating with pico services | |
| 179 | + | -ck <path> SSH certificate public key (required when using SSH certificates) | |
| 180 | + | -artifact-dir <path> Local directory to stage artifacts (default: /tmp/pici-artifacts) | |
| 181 | + | -event <json> Event JSON string (alternative to reading from stdin) | |
| 182 | + | -monitor-interval <dur> Interval for monitoring zmx sessions (default: 5s) | |
| 183 | + | -log-level <level> Log level: debug, info, warn, error (default: info) | |
| 184 | + | -structured Use structured key=value log output | |
| 185 | + | -status-filter <filter> Status output filter: terminal (default) or all`) | |
| 186 | + | } | |
| 187 | + | ||
| 156 | 188 | func RunRunner(cfg *Cfg) error { | |
| 157 | 189 | var payload string | |
| 158 | 190 | if cfg.EventSource != nil { |
| ... | ... | @@ -176,6 +208,17 @@ func RunRunner(cfg *Cfg) error { | |
| 176 | 208 | return fmt.Errorf("unmarshal event: %w", err) | |
| 177 | 209 | } | |
| 178 | 210 | ||
| 211 | + | // Validate required fields | |
| 212 | + | if eventData.Type == "" { | |
| 213 | + | return fmt.Errorf("event missing required field: type") | |
| 214 | + | } | |
| 215 | + | if eventData.Name == "" { | |
| 216 | + | return fmt.Errorf("event missing required field: name") | |
| 217 | + | } | |
| 218 | + | if eventData.Workspace == "" { | |
| 219 | + | return fmt.Errorf("event missing required field: workspace") | |
| 220 | + | } | |
| 221 | + | ||
| 179 | 222 | cfg.Logger.Info("received event", "type", eventData.Type, "repo", eventData.Name, "workspace", eventData.Workspace) | |
| 180 | 223 | ||
| 181 | 224 | return eventHandler(cfg, &eventData) |
A
run.fish
+11,
-0
| ... | ... | @@ -0,0 +1,11 @@ | |
| 1 | + | #!/usr/bin/env fish | |
| 2 | + | ||
| 3 | + | # Continuously subscribe to build events and feed them to pici runner. | |
| 4 | + | # Usage: ./run.fish | |
| 5 | + | ||
| 6 | + | echo "subscribing to build events..." | |
| 7 | + | ssh pipe sub build.event | while read -l event | |
| 8 | + | if test -n "$event" | |
| 9 | + | echo "$event" | pici runner | |
| 10 | + | end | |
| 11 | + | end |