Skip to content

Commit 0ec15ed

Browse files
13791379
1379
authored andcommitted
feat: assign a version number at compile time
1 parent 53027c7 commit 0ec15ed

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

.github/workflows/release.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
- name: Show workflow information
5555
run: |
5656
echo "GOOS: $GOOS, GOARCH: $GOARCH"
57+
echo "BUILD_TIME=$(date --rfc-3339=seconds)" >> $GITHUB_ENV
5758
5859
- name: Build
5960
uses: crazy-max/ghaction-xgo@v2
@@ -66,7 +67,7 @@ jobs:
6667
v: true
6768
x: false
6869
race: false
69-
ldflags: -s -w
70+
ldflags: -s -w -X 'github.com/go-sonic/sonic/consts.SonicVersion=${{github.ref_name}}' -X 'github.com/go-sonic/sonic/consts.BuildCommit=${{github.sha}}' -X 'github.com/go-sonic/sonic/consts.BuildTime=${{env.BUILD_TIME}}'
7071
buildmode: default
7172
trimpath: true
7273

consts/consts.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const (
1919
)
2020

2121
const (
22-
SonicVersion = "1.0.0"
2322
SonicBackupPrefix = "sonic-backup-"
2423
SonicDataExportPrefix = "sonic-data-export-"
2524
SonicBackupMarkdownPrefix = "sonic-backup-markdown-"
@@ -40,7 +39,10 @@ const (
4039
ThemeCustomPostPrefix = "post_"
4140
)
4241

43-
// StartTime 系统启动时间
44-
var StartTime time.Time
45-
46-
var DatabaseVersion string
42+
var (
43+
StartTime time.Time = time.Now()
44+
DatabaseVersion string
45+
SonicVersion = "v1.0.0"
46+
BuildTime string
47+
BuildCommit string
48+
)

event/listener/start.go

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package listener
33
import (
44
"context"
55
"fmt"
6-
"time"
76

87
"go.uber.org/zap"
98
"gorm.io/gorm"
@@ -37,7 +36,6 @@ func (s *StartListener) HandleEvent(ctx context.Context, startEvent event.Event)
3736
if _, ok := startEvent.(*event.StartEvent); !ok {
3837
return nil
3938
}
40-
consts.StartTime = time.Now()
4139

4240
err := s.createOptions()
4341
if err != nil {

service/impl/admin.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"math/rand"
99
"os"
1010
"path/filepath"
11-
"runtime"
1211
"time"
1312

1413
uuid2 "github.com/google/uuid"
@@ -184,7 +183,7 @@ func (a *adminServiceImpl) RefreshToken(ctx context.Context, refreshToken string
184183
func (a *adminServiceImpl) GetEnvironments(ctx context.Context) *dto.EnvironmentDTO {
185184
environments := &dto.EnvironmentDTO{
186185
Database: string(dal.DBType) + " " + consts.DatabaseVersion,
187-
Version: runtime.Version(),
186+
Version: consts.SonicVersion,
188187
StartTime: consts.StartTime.UnixMilli(),
189188
Mode: util.IfElse(a.Config.Sonic.Mode == "", "production", a.Config.Sonic.Mode).(string),
190189
}

0 commit comments

Comments
 (0)