-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmain.go
More file actions
81 lines (68 loc) · 2.13 KB
/
main.go
File metadata and controls
81 lines (68 loc) · 2.13 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
package main
import (
"fmt"
"runtime/debug"
"strings"
"github.com/github/gh-aw-mcpg/internal/cmd"
"github.com/github/gh-aw-mcpg/internal/logger"
)
var log = logger.New("main:main")
func main() {
log.Print("Starting MCP Gateway application")
// Build version string with metadata
versionStr := buildVersionString()
log.Printf("Built version string: %s", versionStr)
// Set the version for the CLI
cmd.SetVersion(versionStr)
// Execute the root command
log.Print("Executing root command")
cmd.Execute()
}
const (
shortHashLength = 7 // Length for short git commit hash
)
// buildVersionString constructs a detailed version string with build metadata
func buildVersionString() string {
log.Print("Building version string from build metadata")
var parts []string
// Add main version
if Version != "" {
log.Printf("Using version from ldflags: %s", Version)
parts = append(parts, Version)
} else {
log.Print("No version set, using 'dev'")
parts = append(parts, "dev")
}
// Add git commit if available
if GitCommit != "" {
log.Printf("Using git commit from ldflags: %s", GitCommit)
parts = append(parts, fmt.Sprintf("commit: %s", GitCommit))
} else if buildInfo, ok := debug.ReadBuildInfo(); ok {
log.Print("Extracting commit hash from build info")
// Try to extract commit from build info if not set via ldflags
for _, setting := range buildInfo.Settings {
if setting.Key == "vcs.revision" {
commitHash := setting.Value
if len(commitHash) > shortHashLength {
commitHash = commitHash[:shortHashLength] // Short hash
}
log.Printf("Found commit hash in build info: %s", commitHash)
parts = append(parts, fmt.Sprintf("commit: %s", commitHash))
break
}
}
}
// Add build date if available
if BuildDate != "" {
parts = append(parts, fmt.Sprintf("built: %s", BuildDate))
} else if buildInfo, ok := debug.ReadBuildInfo(); ok {
// Try to extract build time from build info if not set via ldflags
for _, setting := range buildInfo.Settings {
if setting.Key == "vcs.time" {
parts = append(parts, fmt.Sprintf("built: %s", setting.Value))
break
}
}
}
return strings.Join(parts, ", ")
}