mirror of https://github.com/Xhofe/alist
refactor(cmd): use std `runtime` package to get go version info (#7964)
* refactor(cmd): use std `runtime` package to get go version info - Remove the `GoVersion` variable. - Remove overriding `GoVersion` by ldflags in `build.sh`. - Get go version, OS and arch from the constants in the std `runtime` package instead of compile time. * chore(ci): remove `GoVersion` flag from workflows Remove GoVersion flag from beta_release.yml and build.yml workflows. > Reduce compile-time dependencies.pull/7976/head
parent
f795807753
commit
d983a4ebcb
|
@ -94,7 +94,6 @@ jobs:
|
||||||
out-dir: build
|
out-dir: build
|
||||||
x-flags: |
|
x-flags: |
|
||||||
github.com/alist-org/alist/v3/internal/conf.BuiltAt=$built_at
|
github.com/alist-org/alist/v3/internal/conf.BuiltAt=$built_at
|
||||||
github.com/alist-org/alist/v3/internal/conf.GoVersion=$go_version
|
|
||||||
github.com/alist-org/alist/v3/internal/conf.GitAuthor=Xhofe
|
github.com/alist-org/alist/v3/internal/conf.GitAuthor=Xhofe
|
||||||
github.com/alist-org/alist/v3/internal/conf.GitCommit=$git_commit
|
github.com/alist-org/alist/v3/internal/conf.GitCommit=$git_commit
|
||||||
github.com/alist-org/alist/v3/internal/conf.Version=$tag
|
github.com/alist-org/alist/v3/internal/conf.Version=$tag
|
||||||
|
|
|
@ -49,7 +49,6 @@ jobs:
|
||||||
out-dir: build
|
out-dir: build
|
||||||
x-flags: |
|
x-flags: |
|
||||||
github.com/alist-org/alist/v3/internal/conf.BuiltAt=$built_at
|
github.com/alist-org/alist/v3/internal/conf.BuiltAt=$built_at
|
||||||
github.com/alist-org/alist/v3/internal/conf.GoVersion=$go_version
|
|
||||||
github.com/alist-org/alist/v3/internal/conf.GitAuthor=Xhofe
|
github.com/alist-org/alist/v3/internal/conf.GitAuthor=Xhofe
|
||||||
github.com/alist-org/alist/v3/internal/conf.GitCommit=$git_commit
|
github.com/alist-org/alist/v3/internal/conf.GitCommit=$git_commit
|
||||||
github.com/alist-org/alist/v3/internal/conf.Version=$tag
|
github.com/alist-org/alist/v3/internal/conf.Version=$tag
|
||||||
|
|
2
build.sh
2
build.sh
|
@ -1,6 +1,5 @@
|
||||||
appName="alist"
|
appName="alist"
|
||||||
builtAt="$(date +'%F %T %z')"
|
builtAt="$(date +'%F %T %z')"
|
||||||
goVersion=$(go version | sed 's/go version //')
|
|
||||||
gitAuthor="Xhofe <i@nn.ci>"
|
gitAuthor="Xhofe <i@nn.ci>"
|
||||||
gitCommit=$(git log --pretty=format:"%h" -1)
|
gitCommit=$(git log --pretty=format:"%h" -1)
|
||||||
|
|
||||||
|
@ -22,7 +21,6 @@ echo "frontend version: $webVersion"
|
||||||
ldflags="\
|
ldflags="\
|
||||||
-w -s \
|
-w -s \
|
||||||
-X 'github.com/alist-org/alist/v3/internal/conf.BuiltAt=$builtAt' \
|
-X 'github.com/alist-org/alist/v3/internal/conf.BuiltAt=$builtAt' \
|
||||||
-X 'github.com/alist-org/alist/v3/internal/conf.GoVersion=$goVersion' \
|
|
||||||
-X 'github.com/alist-org/alist/v3/internal/conf.GitAuthor=$gitAuthor' \
|
-X 'github.com/alist-org/alist/v3/internal/conf.GitAuthor=$gitAuthor' \
|
||||||
-X 'github.com/alist-org/alist/v3/internal/conf.GitCommit=$gitCommit' \
|
-X 'github.com/alist-org/alist/v3/internal/conf.GitCommit=$gitCommit' \
|
||||||
-X 'github.com/alist-org/alist/v3/internal/conf.Version=$version' \
|
-X 'github.com/alist-org/alist/v3/internal/conf.Version=$version' \
|
||||||
|
|
|
@ -6,6 +6,7 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/conf"
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -16,14 +17,15 @@ var VersionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Show current version of AList",
|
Short: "Show current version of AList",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
goVersion := fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH)
|
||||||
|
|
||||||
fmt.Printf(`Built At: %s
|
fmt.Printf(`Built At: %s
|
||||||
Go Version: %s
|
Go Version: %s
|
||||||
Author: %s
|
Author: %s
|
||||||
Commit ID: %s
|
Commit ID: %s
|
||||||
Version: %s
|
Version: %s
|
||||||
WebVersion: %s
|
WebVersion: %s
|
||||||
`,
|
`, conf.BuiltAt, goVersion, conf.GitAuthor, conf.GitCommit, conf.Version, conf.WebVersion)
|
||||||
conf.BuiltAt, conf.GoVersion, conf.GitAuthor, conf.GitCommit, conf.Version, conf.WebVersion)
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
BuiltAt string
|
BuiltAt string
|
||||||
GoVersion string
|
|
||||||
GitAuthor string
|
GitAuthor string
|
||||||
GitCommit string
|
GitCommit string
|
||||||
Version string = "dev"
|
Version string = "dev"
|
||||||
|
|
Loading…
Reference in New Issue