-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
106 lines (78 loc) · 2.48 KB
/
Copy pathmain.go
File metadata and controls
106 lines (78 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
"sync"
"github.com/bazaartechnologies/sdk-version-bumper/internal/gitops"
"github.com/bazaartechnologies/sdk-version-bumper/internal/notifier"
"github.com/bazaartechnologies/sdk-version-bumper/internal/report"
"github.com/bazaartechnologies/sdk-version-bumper/internal/util"
"github.com/bazaartechnologies/sdk-version-bumper/internal/workflow"
)
func main() {
GH_TOKEN := ""
sdkVersion := flag.String("version", "", "New SDK version to apply (e.g. 1.4.3)")
mode := flag.String("mode", "dev", "Mode to run in: dev or live")
flag.Parse()
if *sdkVersion == "" {
fmt.Println("❌ Please provide --version")
os.Exit(1)
}
if *mode != "dev" && *mode != "live" {
fmt.Println("❌ Invalid --mode (must be 'dev' or 'live')")
os.Exit(1)
}
log.Printf("👉 Running in mode: %s with SDK version: %s\n", *mode, *sdkVersion)
repos, err := gitops.FetchSpringBootRepos(GH_TOKEN)
if err != nil {
log.Fatalf("❌ Failed to fetch Spring Boot repos: %v", err)
}
fmt.Println("📦 Repositories to be processed:")
for i, fullName := range repos {
fmt.Printf("%2d. %s\n", i+1, fullName)
}
fmt.Println()
// Prompt user to continue
var confirm string
fmt.Print("❓ Do you want to continue bumping versions? (y/n): ")
fmt.Scanln(&confirm)
if confirm != "y" && confirm != "Y" {
fmt.Println("❌ Operation cancelled by user.")
os.Exit(0)
}
// Declared waitgroup and report
var wg sync.WaitGroup
var report report.RunReport
for _, repoUrl := range repos {
parts := strings.Split(repoUrl, "/")
repoName := parts[len(parts)-1]
wg.Add(1)
go workflow.Execute(GH_TOKEN, repoName, repoUrl, *sdkVersion, &report, &wg)
}
// Block main() thread until all goroutines finishes
wg.Wait()
// Clear cloned repo locally
if err := os.RemoveAll("repos"); err != nil {
log.Printf("> ⚠️ Failed to delete repos folder: %v", err)
}
println()
log.Print("> 🧹 Cleaned up local repos cache")
println()
log.Println("> 🎉 All repositories processed.")
log.Println("> 📊 Summary of the run:")
println()
report.PrintSummary()
// format slack message
slackMessage := notifier.FormatSlackMessage(*sdkVersion, report.Results)
done := make(chan struct{}) // start loading spinner
go util.StartSpinner(done)
// POST slack message
slackErr := notifier.SendSlackNotification(slackMessage, *mode)
close(done) // stop loading spinner
if slackErr != nil {
log.Printf("⚠️ Failed to send Slack message: %v\n\n", err)
}
}