Skip to content

Commit 913aa1c

Browse files
committed
Add background update check, update URLs to open.devicelab.dev
1 parent 1fedc57 commit 913aa1c

3 files changed

Lines changed: 78 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
[![codecov](https://codecov.io/gh/devicelab-dev/maestro-runner/branch/main/graph/badge.svg)](https://codecov.io/gh/devicelab-dev/maestro-runner)
2020
[![Go Report Card](https://goreportcard.com/badge/github.com/devicelab-dev/maestro-runner?v=2)](https://goreportcard.com/report/github.com/devicelab-dev/maestro-runner)
2121

22-
<b><a href="https://devicelab.dev/open-source/maestro-runner">Documentation</a></b> | <b><a href="#install">Get Started</a></b> | <b><a href="https://devicelab.dev/open-source/maestro-runner/docs/cli-reference">CLI Reference</a></b> | <b><a href="https://devicelab.dev/open-source/maestro-runner/docs/flow-commands">Flow Commands</a></b> | <b><a href="CONTRIBUTING.md">Contributing</a></b>
22+
<b><a href="https://open.devicelab.dev/maestro-runner">Documentation</a></b> | <b><a href="#install">Get Started</a></b> | <b><a href="https://open.devicelab.dev/maestro-runner/docs/cli-reference">CLI Reference</a></b> | <b><a href="https://open.devicelab.dev/maestro-runner/docs/flow-commands">Flow Commands</a></b> | <b><a href="CONTRIBUTING.md">Contributing</a></b>
2323

2424
</div>
2525

@@ -36,7 +36,7 @@
3636
go install github.com/devicelab-dev/maestro-runner@latest
3737
```
3838

39-
Or download a pre-built binary from [releases](https://devicelab.dev/open-source/maestro-runner).
39+
Or download a pre-built binary from [releases](https://github.com/devicelab-dev/maestro-runner/releases).
4040

4141
## Run Tests
4242

pkg/cli/test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ func runTest(c *cli.Context) error {
477477
// Print banner at start
478478
printBanner()
479479

480-
// Check for updates (non-blocking, 3s timeout)
481-
checkForUpdate()
480+
// Check for updates in background (prints at end)
481+
startUpdateCheck()
482482

483483
// Helper to get flag value from current or parent context
484484
// When run as subcommand, global flags are in parent context
@@ -769,7 +769,10 @@ func executeTest(cfg *RunConfig) error {
769769
}
770770
fmt.Printf(" JSON: %s\n", jsonPath)
771771

772-
// 7. Print footer
772+
// 7. Print update notice if available
773+
printUpdateNotice()
774+
775+
// 8. Print footer
773776
printFooter()
774777

775778
// Exit with code 1 if any flows failed (summary already printed)

pkg/cli/update.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package cli
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
"time"
8+
)
9+
10+
const updateCheckURL = "https://open.devicelab.dev/api/maestro-runner/updates"
11+
12+
// updateNotice receives the update message from the background check.
13+
var updateNotice = make(chan string, 1)
14+
15+
type updateResponse struct {
16+
LatestVersion string `json:"latest_version"`
17+
}
18+
19+
// startUpdateCheck kicks off a background update check.
20+
// Call printUpdateNotice() later to print the result.
21+
func startUpdateCheck() {
22+
ch := updateNotice
23+
go func() {
24+
client := &http.Client{Timeout: 3 * time.Second}
25+
26+
req, err := http.NewRequest("GET", updateCheckURL, nil)
27+
if err != nil {
28+
ch <- ""
29+
return
30+
}
31+
32+
req.Header.Set("User-Agent", "maestro-runner")
33+
34+
resp, err := client.Do(req)
35+
if err != nil {
36+
ch <- ""
37+
return
38+
}
39+
defer resp.Body.Close()
40+
41+
if resp.StatusCode != http.StatusOK {
42+
ch <- ""
43+
return
44+
}
45+
46+
var result updateResponse
47+
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
48+
ch <- ""
49+
return
50+
}
51+
52+
if result.LatestVersion != "" && result.LatestVersion != Version {
53+
ch <- fmt.Sprintf("\n Update available: %s → %s\n Run: curl -fsSL https://open.devicelab.dev/install/maestro-runner.sh | bash\n", Version, result.LatestVersion)
54+
} else {
55+
ch <- ""
56+
}
57+
}()
58+
}
59+
60+
// printUpdateNotice prints the update message if one is available.
61+
func printUpdateNotice() {
62+
select {
63+
case msg := <-updateNotice:
64+
if msg != "" {
65+
fmt.Print(msg)
66+
}
67+
default:
68+
// Check not finished yet, don't block
69+
}
70+
}

0 commit comments

Comments
 (0)