fix(ci): make no run and no check while no runner is registered
CI is on once a runner exists. The check is made by the worker, so a push is never slowed down.
- commit
- ce785bfd247feaff84105a8cc9174e3f0be115f8
- author
- brice · · 2026-10-12 19:08 UTC
- parent
- 5aba7f2
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +23 -0
M internal/app/ci_flow_test.go +14 -0
| @@ -580,3 +580,17 @@ func TestCIPushWithoutNewCommitsStillRuns(t *testing.T) { | |||
| 580 | 580 | c.waitFor("the rewind runs", func() bool { return len(c.runs()) == 4 }) | |
| 581 | 581 | assert.Equal(t, first, c.runs()[0].GetSha()) | |
| 582 | 582 | } | |
| 583 | + | ||
| 584 | + | // CI is on once a runner is registered: before that a push makes no run and no | |
| 585 | + | // check; after, it does. | |
| 586 | + | func TestCINoRunnerNoRunsNoChecks(t *testing.T) { | |
| 587 | + | c := newCIHarness(t, nil) | |
| 588 | + | sha := c.push("main", map[string]string{".github/workflows/ci.yml": ciWorkflow}, "") | |
| 589 | + | time.Sleep(400 * time.Millisecond) | |
| 590 | + | assert.Empty(t, c.runs()) | |
| 591 | + | assert.Empty(t, c.checks(sha)) | |
| 592 | + | ||
| 593 | + | c.registerRunner("alpha", "ubuntu-latest") | |
| 594 | + | c.push("main", map[string]string{"a.txt": "a\n"}, "") | |
| 595 | + | c.waitFor("a run once a runner exists", func() bool { return len(c.runs()) == 1 }) | |
| 596 | + | } | |
| @@ -580,3 +580,17 @@ func TestCIPushWithoutNewCommitsStillRuns(t *testing.T) { | |||||
| 580 | c.waitFor("the rewind runs", func() bool { return len(c.runs()) == 4 }) | 580 | c.waitFor("the rewind runs", func() bool { return len(c.runs()) == 4 }) | ||
| 581 | assert.Equal(t, first, c.runs()[0].GetSha()) | 581 | assert.Equal(t, first, c.runs()[0].GetSha()) | ||
| 582 | } | 582 | } | ||
| 583 | + | ||||
| 584 | + | // CI is on once a runner is registered: before that a push makes no run and no | |||
| 585 | + | // check; after, it does. | |||
| 586 | + | func TestCINoRunnerNoRunsNoChecks(t *testing.T) { | |||
| 587 | + | c := newCIHarness(t, nil) | |||
| 588 | + | sha := c.push("main", map[string]string{".github/workflows/ci.yml": ciWorkflow}, "") | |||
| 589 | + | time.Sleep(400 * time.Millisecond) | |||
| 590 | + | assert.Empty(t, c.runs()) | |||
| 591 | + | assert.Empty(t, c.checks(sha)) | |||
| 592 | + | ||||
| 593 | + | c.registerRunner("alpha", "ubuntu-latest") | |||
| 594 | + | c.push("main", map[string]string{"a.txt": "a\n"}, "") | |||
| 595 | + | c.waitFor("a run once a runner exists", func() bool { return len(c.runs()) == 1 }) | |||
| 596 | + | } | |||
M internal/usecase/ci_trigger.go +9 -0
| @@ -93,6 +93,15 @@ func (c *CI) planPush(t ciTrigger) { | |||
| 93 | 93 | ||
| 94 | 94 | // handlePush starts the workflows that match each ref of the push. | |
| 95 | 95 | func (c *CI) handlePush(ctx context.Context, t ciTrigger) error { | |
| 96 | + | // CI is on once a runner is registered (plan, "Config"): without one a push | |
| 97 | + | // makes no run and no check, so a forge that does not use CI shows nothing. | |
| 98 | + | runners, err := c.cfg.Store.ListRunners(ctx) | |
| 99 | + | if err != nil { | |
| 100 | + | return fmt.Errorf("list the runners: %w", err) | |
| 101 | + | } | |
| 102 | + | if len(runners) == 0 { | |
| 103 | + | return nil | |
| 104 | + | } | |
| 96 | 105 | tags := 0 | |
| 97 | 106 | for _, u := range t.updates { | |
| 98 | 107 | if strings.HasPrefix(u.Ref, "refs/tags/") { | |
| @@ -93,6 +93,15 @@ func (c *CI) planPush(t ciTrigger) { | |||||
| 93 | 93 | ||||
| 94 | // handlePush starts the workflows that match each ref of the push. | 94 | // handlePush starts the workflows that match each ref of the push. | ||
| 95 | func (c *CI) handlePush(ctx context.Context, t ciTrigger) error { | 95 | func (c *CI) handlePush(ctx context.Context, t ciTrigger) error { | ||
| 96 | + | // CI is on once a runner is registered (plan, "Config"): without one a push | |||
| 97 | + | // makes no run and no check, so a forge that does not use CI shows nothing. | |||
| 98 | + | runners, err := c.cfg.Store.ListRunners(ctx) | |||
| 99 | + | if err != nil { | |||
| 100 | + | return fmt.Errorf("list the runners: %w", err) | |||
| 101 | + | } | |||
| 102 | + | if len(runners) == 0 { | |||
| 103 | + | return nil | |||
| 104 | + | } | |||
| 96 | tags := 0 | 105 | tags := 0 | ||
| 97 | for _, u := range t.updates { | 106 | for _, u := range t.updates { | ||
| 98 | if strings.HasPrefix(u.Ref, "refs/tags/") { | 107 | if strings.HasPrefix(u.Ref, "refs/tags/") { | ||