Commit 71d9bd6
Eric Bower
·
2026-08-09 11:33:25 -0400 EDT
parent 1c94e4e
fix: naming ci
2 files changed,
+39,
-14
M
main.go
M
main.go
+16,
-14
| ... | ... | @@ -661,10 +661,21 @@ func (eng *JobEngine) Setup() error { | |
| 661 | 661 | return eng.Wk.Setup() | |
| 662 | 662 | } | |
| 663 | 663 | ||
| 664 | + | // getDomain maps an event type (e.g. "git.push", "git.tag", "local") to a session domain prefix ("ci", "local", etc.). | |
| 665 | + | func getDomain(eventType string) string { | |
| 666 | + | if eventType == "local" { | |
| 667 | + | return "local" | |
| 668 | + | } | |
| 669 | + | if eventType == "test-ci" || strings.HasPrefix(eventType, "test-") { | |
| 670 | + | return eventType | |
| 671 | + | } | |
| 672 | + | return "ci" | |
| 673 | + | } | |
| 674 | + | ||
| 664 | 675 | func (eng *JobEngine) Run(manifest string) error { | |
| 665 | 676 | domain := "ci" | |
| 666 | - | if eng.Ev != nil && eng.Ev.Type != "" { | |
| 667 | - | domain = eng.Ev.Type | |
| 677 | + | if eng.Ev != nil { | |
| 678 | + | domain = getDomain(eng.Ev.Type) | |
| 668 | 679 | } | |
| 669 | 680 | prefix := fmt.Sprintf("%s.%s.%s.", domain, eng.Ev.Name, eng.JobID) | |
| 670 | 681 | // Child sessions use ".step." sub-prefix so zmx wait "*" inside pico.sh |
| ... | ... | @@ -741,10 +752,7 @@ func eventHandler(cfg *Cfg, eventData *Event) error { | |
| 741 | 752 | } | |
| 742 | 753 | ||
| 743 | 754 | eventBytes, _ := json.Marshal(eventData) | |
| 744 | - | domain := "ci" | |
| 745 | - | if eventData.Type != "" { | |
| 746 | - | domain = eventData.Type | |
| 747 | - | } | |
| 755 | + | domain := getDomain(eventData.Type) | |
| 748 | 756 | fmt.Fprintf(os.Stdout, "🚀 starting job %s.%s.%s\n", domain, eventData.Name, jobID) //nolint:errcheck | |
| 749 | 757 | fmt.Fprintf(os.Stdout, " event: type=%s name=%s workspace=%s\n", eventData.Type, eventData.Name, eventData.Workspace) //nolint:errcheck | |
| 750 | 758 | fmt.Fprintf(os.Stdout, " %s\n", string(eventBytes)) //nolint:errcheck |
| ... | ... | @@ -852,10 +860,7 @@ See: https://github.com/picosh/pici | |
| 852 | 860 | return nil | |
| 853 | 861 | } | |
| 854 | 862 | ||
| 855 | - | domain = "ci" | |
| 856 | - | if eventData.Type != "" { | |
| 857 | - | domain = eventData.Type | |
| 858 | - | } | |
| 863 | + | domain = getDomain(eventData.Type) | |
| 859 | 864 | session := fmt.Sprintf("%s.%s.%s.runner", domain, eventData.Name, jobID) | |
| 860 | 865 | fmt.Fprintf(os.Stdout, " zmx tail %s\n", session) //nolint:errcheck | |
| 861 | 866 | fmt.Fprintf(os.Stdout, " zmx history %s\n", session) //nolint:errcheck |
| ... | ... | @@ -866,10 +871,7 @@ See: https://github.com/picosh/pici | |
| 866 | 871 | // waitAndReport polls the job's sessions until all complete, prints live | |
| 867 | 872 | // progress to stdout, then dumps session history and a final summary. | |
| 868 | 873 | func waitAndReport(cfg *Cfg, log *slog.Logger, name, jobID, eventType string) error { | |
| 869 | - | domain := "ci" | |
| 870 | - | if eventType != "" { | |
| 871 | - | domain = eventType | |
| 872 | - | } | |
| 874 | + | domain := getDomain(eventType) | |
| 873 | 875 | prefix := domain + "." + name + "." + jobID + "." | |
| 874 | 876 | interval := cfg.MonitorInterval | |
| 875 | 877 | if interval <= 0 { |
+23,
-0
| ... | ... | @@ -547,6 +547,29 @@ func TestParseZMXList(t *testing.T) { | |
| 547 | 547 | } | |
| 548 | 548 | } | |
| 549 | 549 | ||
| 550 | + | func TestGetDomain(t *testing.T) { | |
| 551 | + | tests := []struct { | |
| 552 | + | eventType string | |
| 553 | + | want string | |
| 554 | + | }{ | |
| 555 | + | {"git.push", "ci"}, | |
| 556 | + | {"git.tag", "ci"}, | |
| 557 | + | {"push", "ci"}, | |
| 558 | + | {"manual", "ci"}, | |
| 559 | + | {"ci", "ci"}, | |
| 560 | + | {"", "ci"}, | |
| 561 | + | {"local", "local"}, | |
| 562 | + | {"test-ci", "test-ci"}, | |
| 563 | + | } | |
| 564 | + | ||
| 565 | + | for _, tt := range tests { | |
| 566 | + | got := getDomain(tt.eventType) | |
| 567 | + | if got != tt.want { | |
| 568 | + | t.Errorf("getDomain(%q) = %q, want %q", tt.eventType, got, tt.want) | |
| 569 | + | } | |
| 570 | + | } | |
| 571 | + | } | |
| 572 | + | ||
| 550 | 573 | func TestExtractJobID(t *testing.T) { | |
| 551 | 574 | tests := []struct { | |
| 552 | 575 | runnerName string |