Commit 234c991
Eric Bower
·
2026-08-09 10:42:26 -0400 EDT
parent 8394af3
fix: default to local so pici-monitor doesn't get the report
2 files changed,
+20,
-11
M
main.go
M
main.go
+13,
-4
| ... | ... | @@ -692,7 +692,11 @@ func eventHandler(cfg *Cfg, eventData *Event) error { | |
| 692 | 692 | } | |
| 693 | 693 | ||
| 694 | 694 | eventBytes, _ := json.Marshal(eventData) | |
| 695 | - | fmt.Fprintf(os.Stdout, "🚀 starting job ci.%s.%s\n", eventData.Name, jobID) //nolint:errcheck | |
| 695 | + | domain := "ci" | |
| 696 | + | if eventData.Type == "local" { | |
| 697 | + | domain = "local" | |
| 698 | + | } | |
| 699 | + | fmt.Fprintf(os.Stdout, "🚀 starting job %s.%s.%s\n", domain, eventData.Name, jobID) //nolint:errcheck | |
| 696 | 700 | fmt.Fprintf(os.Stdout, " event: type=%s name=%s workspace=%s\n", eventData.Type, eventData.Name, eventData.Workspace) //nolint:errcheck | |
| 697 | 701 | fmt.Fprintf(os.Stdout, " %s\n", string(eventBytes)) //nolint:errcheck | |
| 698 | 702 |
| ... | ... | @@ -799,7 +803,11 @@ See: https://github.com/picosh/pici | |
| 799 | 803 | return nil | |
| 800 | 804 | } | |
| 801 | 805 | ||
| 802 | - | session := fmt.Sprintf("ci.%s.%s.runner", eventData.Name, jobID) | |
| 806 | + | domain = "ci" | |
| 807 | + | if eventData.Type == "local" { | |
| 808 | + | domain = "local" | |
| 809 | + | } | |
| 810 | + | session := fmt.Sprintf("%s.%s.%s.runner", domain, eventData.Name, jobID) | |
| 803 | 811 | fmt.Fprintf(os.Stdout, " zmx tail %s\n", session) //nolint:errcheck | |
| 804 | 812 | fmt.Fprintf(os.Stdout, " zmx history %s\n", session) //nolint:errcheck | |
| 805 | 813 | fmt.Fprintf(os.Stdout, " zmx attach %s\n", session) //nolint:errcheck |
| ... | ... | @@ -1798,7 +1806,7 @@ func findRunningJobs(name string) ([]string, []SessionInfo) { | |
| 1798 | 1806 | var runners []string | |
| 1799 | 1807 | for _, s := range sessions { | |
| 1800 | 1808 | // Match ci.<name>.*.runner sessions that are still active (no ended) | |
| 1801 | - | if strings.HasPrefix(s.Name, "ci."+name+".") && strings.HasSuffix(s.Name, ".runner") && s.Ended == "" { | |
| 1809 | + | if (strings.HasPrefix(s.Name, "ci."+name+".") || strings.HasPrefix(s.Name, "local."+name+".")) && strings.HasSuffix(s.Name, ".runner") && s.Ended == "" { | |
| 1802 | 1810 | runners = append(runners, s.Name) | |
| 1803 | 1811 | } | |
| 1804 | 1812 | } |
| ... | ... | @@ -1811,6 +1819,7 @@ func extractJobID(runnerName string) string { | |
| 1811 | 1819 | // Remove "ci." prefix and ".runner" suffix, then take the part after the first "." | |
| 1812 | 1820 | name := strings.TrimSuffix(runnerName, ".runner") | |
| 1813 | 1821 | name = strings.TrimPrefix(name, "ci.") | |
| 1822 | + | name = strings.TrimPrefix(name, "local.") | |
| 1814 | 1823 | // name is now <name>.<jobID>, take the jobID part | |
| 1815 | 1824 | parts := strings.SplitN(name, ".", 2) | |
| 1816 | 1825 | if len(parts) == 2 { |
| ... | ... | @@ -2084,7 +2093,7 @@ func runLocal(cfg *Cfg, dest string) error { | |
| 2084 | 2093 | } | |
| 2085 | 2094 | ||
| 2086 | 2095 | repoName := filepath.Base(cwd) | |
| 2087 | - | jobID := fmt.Sprintf("local-%d", time.Now().Unix()) | |
| 2096 | + | jobID := fmt.Sprintf("%d", time.Now().Unix()) | |
| 2088 | 2097 | ||
| 2089 | 2098 | eventData := &Event{ | |
| 2090 | 2099 | Type: "local", |
+7,
-7
| ... | ... | @@ -51,7 +51,7 @@ zmx run step2 echo "hello from step2" | |
| 51 | 51 | _ = exec.Command("zmx", "kill", "-f", fmt.Sprintf("ci.test-repo.%s", testJobID)).Run() | |
| 52 | 52 | }) | |
| 53 | 53 | event := Event{ | |
| 54 | - | Type: "build", | |
| 54 | + | Type: "ci", | |
| 55 | 55 | Name: "test-repo", | |
| 56 | 56 | JobID: testJobID, | |
| 57 | 57 | Workspace: workspaceDir, |
| ... | ... | @@ -239,7 +239,7 @@ zmx run step2 echo "hello from step2" | |
| 239 | 239 | ||
| 240 | 240 | // Cleanup any leftover zmx sessions for this job | |
| 241 | 241 | if finalPayload != nil { | |
| 242 | - | _ = exec.Command("zmx", "kill", "-f", fmt.Sprintf("ci.test-repo.%s", finalPayload.JobID)).Run() | |
| 242 | + | _ = exec.Command("zmx", "kill", "-f", fmt.Sprintf("local.test-repo.%s", finalPayload.JobID)).Run() | |
| 243 | 243 | } | |
| 244 | 244 | } | |
| 245 | 245 |
| ... | ... | @@ -299,7 +299,7 @@ zmx run fast-step echo "done" | |
| 299 | 299 | } | |
| 300 | 300 | ||
| 301 | 301 | // 3. Start first job (slow) | |
| 302 | - | event1 := Event{Type: "build", Name: "dup-repo", Workspace: workspaceDir} | |
| 302 | + | event1 := Event{Type: "local", Name: "dup-repo", Workspace: workspaceDir} | |
| 303 | 303 | event1JSON, _ := json.Marshal(event1) | |
| 304 | 304 | cfg1 := makeCfg(io.NopCloser(bytes.NewReader(append(event1JSON, '\n')))) | |
| 305 | 305 |
| ... | ... | @@ -308,7 +308,7 @@ zmx run fast-step echo "done" | |
| 308 | 308 | }() | |
| 309 | 309 | ||
| 310 | 310 | // Wait for the first job's runner session to appear | |
| 311 | - | if !waitForSessionPrefix(t, "ci.dup-repo.", 10*time.Second) { | |
| 311 | + | if !waitForSessionPrefix(t, "local.dup-repo.", 10*time.Second) { | |
| 312 | 312 | t.Fatal("first job's runner session never appeared") | |
| 313 | 313 | } | |
| 314 | 314 |
| ... | ... | @@ -320,7 +320,7 @@ zmx run fast-step echo "done" | |
| 320 | 320 | t.Logf("first job runner: %s", firstRunner) | |
| 321 | 321 | ||
| 322 | 322 | // 4. Start second job (same repo name, should cancel the first) | |
| 323 | - | event2 := Event{Type: "build", Name: "dup-repo", Workspace: workspaceDir2} | |
| 323 | + | event2 := Event{Type: "local", Name: "dup-repo", Workspace: workspaceDir2} | |
| 324 | 324 | event2JSON, _ := json.Marshal(event2) | |
| 325 | 325 | cfg2 := makeCfg(io.NopCloser(bytes.NewReader(append(event2JSON, '\n')))) | |
| 326 | 326 |
| ... | ... | @@ -356,7 +356,7 @@ zmx run fast-step echo "done" | |
| 356 | 356 | } | |
| 357 | 357 | ||
| 358 | 358 | // Cleanup | |
| 359 | - | _ = exec.Command("zmx", "kill", "-f", "ci.dup-repo").Run() | |
| 359 | + | _ = exec.Command("zmx", "kill", "-f", "local.dup-repo").Run() | |
| 360 | 360 | } | |
| 361 | 361 | ||
| 362 | 362 | // waitForSessionPrefix returns true if a session with the given prefix appears within the timeout. |
| ... | ... | @@ -385,7 +385,7 @@ func findRunnerSession(t *testing.T, name string) string { | |
| 385 | 385 | } | |
| 386 | 386 | sessions := parseZMXList(string(listOutput)) | |
| 387 | 387 | for _, s := range sessions { | |
| 388 | - | if strings.HasPrefix(s.Name, "ci."+name+".") && strings.HasSuffix(s.Name, ".runner") { | |
| 388 | + | if (strings.HasPrefix(s.Name, "local."+name+".") || strings.HasPrefix(s.Name, "ci."+name+".")) && strings.HasSuffix(s.Name, ".runner") { | |
| 389 | 389 | return s.Name | |
| 390 | 390 | } | |
| 391 | 391 | } |