👷 Replace commit with builder in version
This commit is contained in:
1 parent
86d87906f4
commit
ab8ca6d474
8 files changed
+42
-23
No files matched your search
@@ -10,6 +10,7 @@
|
||||
*.so
|
||||
*.dylib
|
||||
*.syso
|
||||
/yutu
|
||||
|
||||
# Generated by IDE
|
||||
.idea
|
||||
|
||||
+4
-3
@@ -10,7 +10,8 @@ version: 2
|
||||
project_name: yutu
|
||||
|
||||
env:
|
||||
- MODULE_PATH=github.com/{{ .Env.GITHUB_REPOSITORY }}
|
||||
- MODULE_PATH=github.com/{{ if index .Env "GITHUB_REPOSITORY" }}{{ .Env.GITHUB_REPOSITORY }}{{ else }}eat-pray-ai/yutu{{ end }}
|
||||
- Builder={{ if index .Env "GITHUB_ACTOR" }}{{ .Env.GITHUB_ACTOR }}{{ else }}Gopher{{ end }}
|
||||
|
||||
before:
|
||||
hooks:
|
||||
@@ -53,10 +54,11 @@ builds:
|
||||
- -X {{ .Env.MODULE_PATH }}/cmd.CommitDate={{ .CommitDate }}
|
||||
- -X {{ .Env.MODULE_PATH }}/cmd.Os={{ .Os }}
|
||||
- -X {{ .Env.MODULE_PATH }}/cmd.Arch={{ .Arch }}
|
||||
- -X {{ .Env.MODULE_PATH }}/cmd.Builder={{ .Env.Builder }}
|
||||
mod_timestamp: "{{ .CommitTimestamp }}"
|
||||
|
||||
archives:
|
||||
- formats: [ 'binary' ]
|
||||
- formats: ["binary"]
|
||||
ids:
|
||||
- yutu
|
||||
name_template: "{{ .Binary }}"
|
||||
@@ -96,4 +98,3 @@ changelog:
|
||||
|
||||
release:
|
||||
discussion_category_name: General
|
||||
|
||||
@@ -46,13 +46,6 @@ go_binary(
|
||||
name = "yutu",
|
||||
embed = [":yutu_lib"],
|
||||
visibility = ["//visibility:public"],
|
||||
x_defs = {
|
||||
"Version": "{STABLE_VERSION}",
|
||||
"Commit": "{STABLE_GIT_SHORT_SHA}",
|
||||
"CommitDate": "{STABLE_GIT_COMMIT_DATE}",
|
||||
"Os": "{STABLE_OS}",
|
||||
"Arch": "{STABLE_ARCH}",
|
||||
},
|
||||
)
|
||||
|
||||
go_cross_binary(
|
||||
|
||||
@@ -16,6 +16,7 @@ go_library(
|
||||
"CommitDate": "{STABLE_GIT_COMMIT_DATE}",
|
||||
"Os": "{STABLE_OS}",
|
||||
"Arch": "{STABLE_ARCH}",
|
||||
"Builder": "{STABLE_Builder}",
|
||||
},
|
||||
deps = [
|
||||
"//pkg",
|
||||
|
||||
+30
-9
@@ -4,13 +4,17 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/savioxavier/termlink"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const (
|
||||
versionShort = "Show the version of yutu"
|
||||
versionLong = "Show the version of yutu"
|
||||
verShort = "Show the version of yutu"
|
||||
verLong = "Show the version of yutu"
|
||||
repo = "Github/eat-pray-ai/yutu"
|
||||
repoUrl = "https://github.com/eat-pray-ai/yutu"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -19,20 +23,37 @@ var (
|
||||
CommitDate = ""
|
||||
Os = ""
|
||||
Arch = ""
|
||||
repo = "https://github.com/eat-pray-ai/yutu"
|
||||
Builder = "Gopher"
|
||||
)
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: versionShort,
|
||||
Long: versionLong,
|
||||
Short: verShort,
|
||||
Long: verLong,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmd.Printf("🐰yutu version %s %s/%s", Version, Os, Arch)
|
||||
if Commit != "" && CommitDate != "" {
|
||||
cmd.Printf("\n📦build %s-%s", Commit, CommitDate)
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if ok && Version == "" {
|
||||
Version = info.Main.Version
|
||||
|
||||
settings := make(map[string]string)
|
||||
for _, setting := range info.Settings {
|
||||
settings[setting.Key] = setting.Value
|
||||
}
|
||||
|
||||
if val, exists := settings["vcs.time"]; exists {
|
||||
CommitDate = val
|
||||
}
|
||||
if val, exists := settings["GOOS"]; exists {
|
||||
Os = val
|
||||
}
|
||||
if val, exists := settings["GOARCH"]; exists {
|
||||
Arch = val
|
||||
}
|
||||
}
|
||||
|
||||
cmd.Println("\n🌟Star:", termlink.Link("Github/eat-pray-ai/yutu", repo))
|
||||
cmd.Printf("🐰yutu %s %s/%s\n", Version, Os, Arch)
|
||||
cmd.Printf("📦build %s-%s\n", Builder, CommitDate)
|
||||
cmd.Printf("🌟Star: %s\n", termlink.Link(repo, repoUrl))
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,13 @@ Here are some commands which may useful.
|
||||
## run tests
|
||||
### unit tests
|
||||
❯ go test ./... -coverprofile=./cover.out -coverpkg="$(go list || go list -m | head -1)/pkg/..."
|
||||
❯ go tool cover -html=cover.out -o=cover.html
|
||||
❯ go tool cover -html=cover.out -o=cover.html
|
||||
|
||||
## build the binary
|
||||
### install goreleaser: https://goreleaser.com/install
|
||||
❯ GITHUB_REPOSITORY=eat-pray-ai/yutu goreleaser build --clean --auto-snapshot
|
||||
❯ goreleaser build --clean --auto-snapshot
|
||||
|
||||
❯ tree dist
|
||||
❯ tree dist
|
||||
dist
|
||||
├── artifacts.json
|
||||
├── config.yaml
|
||||
|
||||
@@ -19,3 +19,4 @@ fi
|
||||
|
||||
echo STABLE_OS "$(uname -s | tr '[:upper:]' '[:lower:]')"
|
||||
echo STABLE_ARCH "$(uname -m | sed 's/x86_64/amd64/' | tr '[:upper:]' '[:lower:]')"
|
||||
echo STABLE_Builder "${GITHUB_ACTOR:-$USER}"
|
||||
@@ -17,7 +17,8 @@ if [[ -z "$YUTU_PATH" ]]; then
|
||||
CommitDate="${MOD}.CommitDate=$(git log -1 --date='format:%Y-%m-%dT%H:%M:%SZ' --pretty=%cd)"
|
||||
Os="${MOD}.Os=$(go env GOOS)"
|
||||
Arch="${MOD}.Arch=$(go env GOARCH)"
|
||||
ldflags="-s -X ${Version} -X ${Commit} -X ${CommitDate} -X ${Os} -X ${Arch}"
|
||||
Builder="${MOD}.Builder=${GITHUB_ACTOR:-$USER}"
|
||||
ldflags="-s -X ${Version} -X ${Commit} -X ${CommitDate} -X ${Os} -X ${Arch} -X ${Builder}"
|
||||
|
||||
go mod download
|
||||
go build -ldflags "${ldflags}" -o yutu .
|
||||
|
||||
Reference in new issue
Block a user