Skip to content

Commit e036e60

Browse files
committed
fix: add internal version package and update version handling
- Create internal/version/version.go with version variables - Update main.go to use internal version package instead of promexporter version - Set version information directly in metrics registry - This fixes the issue where version information shows as 'dev', 'unknown', 'unknown'
1 parent 7176e96 commit e036e60

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

cmd/main.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"ghcr-exporter/internal/collectors"
1010
"ghcr-exporter/internal/config"
1111
"ghcr-exporter/internal/metrics"
12+
"ghcr-exporter/internal/version"
1213
"github.com/d0ugal/promexporter/app"
1314
"github.com/d0ugal/promexporter/logging"
1415
promexporter_metrics "github.com/d0ugal/promexporter/metrics"
15-
"github.com/d0ugal/promexporter/version"
1616
)
1717

1818
func main() {
@@ -27,11 +27,9 @@ func main() {
2727

2828
// Show version if requested
2929
if showVersion {
30-
versionInfo := version.Get()
31-
fmt.Printf("ghcr-exporter %s\n", versionInfo.Version)
32-
fmt.Printf("Commit: %s\n", versionInfo.Commit)
33-
fmt.Printf("Build Date: %s\n", versionInfo.BuildDate)
34-
fmt.Printf("Go Version: %s\n", versionInfo.GoVersion)
30+
fmt.Printf("ghcr-exporter %s\n", version.Version)
31+
fmt.Printf("Commit: %s\n", version.Commit)
32+
fmt.Printf("Build Date: %s\n", version.BuildDate)
3533
os.Exit(0)
3634
}
3735

@@ -73,6 +71,9 @@ func main() {
7371
// Initialize metrics registry using promexporter
7472
metricsRegistry := promexporter_metrics.NewRegistry("ghcr_exporter_info")
7573

74+
// Set version info metric with ghcr-exporter version information
75+
metricsRegistry.VersionInfo.WithLabelValues(version.Version, version.Commit, version.BuildDate).Set(1)
76+
7677
// Add custom metrics to the registry
7778
ghcrRegistry := metrics.NewGHCRRegistry(metricsRegistry)
7879

internal/version/version.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package version
2+
3+
// Version information
4+
var (
5+
Version = "dev"
6+
Commit = "unknown"
7+
BuildDate = "unknown"
8+
)

0 commit comments

Comments
 (0)