Skip to content

Commit 1335f8c

Browse files
committed
comment 4
Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>
1 parent 00848f2 commit 1335f8c

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,7 @@ jobs:
109109
run: |
110110
# Handshake with server on port 8080
111111
percli login http://localhost:8080
112-
PLUGINS=("table" "tracetable")
113-
for plugin in "${PLUGINS[@]}"; do
114-
percli plugin start "./$plugin" &
115-
sleep 10
116-
npm run test:ci --prefix e2e -- "tests/$plugin"
117-
done
112+
go run scripts/manage_plugins/manage_plugins.go
118113
119114
type-check:
120115
name: "type-check"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"os/exec"
8+
"os/signal"
9+
"sync"
10+
"syscall"
11+
"time"
12+
)
13+
14+
func main() {
15+
plugins := []string{"table", "tracetable"}
16+
ctx, cancel := context.WithCancel(context.Background())
17+
defer cancel()
18+
19+
// Handle OS signals for termination (Ctrl+C, CI cancellation)
20+
// Signal(0xf) // 15 and Signal(0x2) // 2
21+
sigChan := make(chan os.Signal, 1)
22+
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
23+
24+
// Let's wait and catch the termination signals
25+
// If any of these signals are received, we will cancel the context which will stop all running plugin processes
26+
go func() {
27+
<-sigChan
28+
fmt.Println("\nTermination signal received. Cleaning up...")
29+
cancel()
30+
}()
31+
32+
// Let's make sure that the main function waits for all plugin processes to finish before exiting
33+
var wg sync.WaitGroup
34+
35+
for _, plugin := range plugins {
36+
wg.Add(1)
37+
go func(p string) {
38+
defer wg.Done()
39+
40+
// Start percli plugin in the background using the context
41+
cmd := exec.CommandContext(ctx, "percli", "plugin", "start", "./"+p)
42+
cmd.Stdout = os.Stdout
43+
cmd.Stderr = os.Stderr
44+
45+
fmt.Printf("Starting plugin: %s\n", p)
46+
if err := cmd.Start(); err != nil {
47+
fmt.Errorf("failed to start %s: %v\n", p, err)
48+
return
49+
}
50+
51+
// Instead of a blind sleep 10, could we do a health logic here? I am not sure!
52+
// Plugins start on an arbitrary port, how could we check if they are ruining or not?!
53+
time.Sleep(10 * time.Second)
54+
55+
// Run your test command
56+
testCmd := exec.Command("npm", "run", "test:ci", "--prefix", "e2e", "--", "tests/"+p)
57+
testCmd.Stdout = os.Stdout
58+
testCmd.Stderr = os.Stderr
59+
if err := testCmd.Run(); err != nil {
60+
fmt.Errorf("tests failed for plugin %s: %v\n", p, err)
61+
}
62+
}(plugin)
63+
}
64+
65+
wg.Wait()
66+
fmt.Println("All plugin tests completed.")
67+
}

0 commit comments

Comments
 (0)