diff --git a/.github/conf/.goreleaser.yml b/.github/conf/.goreleaser.yml index 7ebd73a..51c2e29 100644 --- a/.github/conf/.goreleaser.yml +++ b/.github/conf/.goreleaser.yml @@ -23,7 +23,7 @@ builds: - goos: windows goarch: arm64 flags: [-trimpath] - ldflags: -s -w -X main.version={{ .Version }} -X main.commit={{ .ShortCommit }} -X main.date={{ .Date }} -X main.builtBy=goreleaser + ldflags: -s -w -X github.com/shadow1ng/fscan/common.version={{ .Version }} -X github.com/shadow1ng/fscan/common.commit={{ .ShortCommit }} -X github.com/shadow1ng/fscan/common.date={{ .Date }} mod_timestamp: "{{ .CommitTimestamp }}" # 无本地插件版 - 排除本地模块 @@ -42,7 +42,7 @@ builds: goarch: arm64 flags: [-trimpath] tags: [no_local] - ldflags: -s -w -X main.version={{ .Version }} -X main.commit={{ .ShortCommit }} -X main.date={{ .Date }} -X main.builtBy=goreleaser + ldflags: -s -w -X github.com/shadow1ng/fscan/common.version={{ .Version }} -X github.com/shadow1ng/fscan/common.commit={{ .ShortCommit }} -X github.com/shadow1ng/fscan/common.date={{ .Date }} mod_timestamp: "{{ .CommitTimestamp }}" # WebUI版 - 带Web管理界面 @@ -61,7 +61,7 @@ builds: goarch: arm64 flags: [-trimpath] tags: [web] - ldflags: -s -w -X main.version={{ .Version }} -X main.commit={{ .ShortCommit }} -X main.date={{ .Date }} -X main.builtBy=goreleaser + ldflags: -s -w -X github.com/shadow1ng/fscan/common.version={{ .Version }} -X github.com/shadow1ng/fscan/common.commit={{ .ShortCommit }} -X github.com/shadow1ng/fscan/common.date={{ .Date }} mod_timestamp: "{{ .CommitTimestamp }}" upx: diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index d99300a..73ad33d 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -4,6 +4,7 @@ on: push: branches: - dev + - dev-* - develop - feature/* paths-ignore: diff --git a/common/flag.go b/common/flag.go index 27bcf56..c5951a7 100644 --- a/common/flag.go +++ b/common/flag.go @@ -69,12 +69,15 @@ func Banner() { fmt.Println(bottomBorder) // 打印版本信息 + versionStr := fmt.Sprintf(" Fscan %s (%s %s)", version, commit, date) + if commit == "unknown" { + versionStr = fmt.Sprintf(" Fscan %s", version) + } if flagVars.NoColor { - // 无色彩模式下使用普通文本 - fmt.Printf(" Fscan Version: %s\n\n", version) + fmt.Printf("%s\n\n", versionStr) } else { c := color.New(colors[1]) - _, _ = c.Printf(" Fscan Version: %s\n\n", version) + _, _ = c.Printf("%s\n\n", versionStr) } } diff --git a/common/globals.go b/common/globals.go index 1cf8c42..bebeea4 100644 --- a/common/globals.go +++ b/common/globals.go @@ -60,7 +60,12 @@ const ( LogLevelBaseInfoSuccess = "base,info,success" ) -const version = "2.1.1" +// 版本信息,通过 ldflags 注入 +var ( + version = "2.1.1" + commit = "unknown" + date = "unknown" +) // 运行时数据已迁移到Config对象中,使用GetGlobalConfig()访问