Skip to content

Commit ab8ca6d

Browse files
committed
👷 Replace commit with builder in version
1 parent 86d8790 commit ab8ca6d

File tree

8 files changed

+42
-23
lines changed

8 files changed

+42
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*.so
1111
*.dylib
1212
*.syso
13+
/yutu
1314

1415
# Generated by IDE
1516
.idea

.goreleaser.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ version: 2
1010
project_name: yutu
1111

1212
env:
13-
- MODULE_PATH=github.com/{{ .Env.GITHUB_REPOSITORY }}
13+
- MODULE_PATH=github.com/{{ if index .Env "GITHUB_REPOSITORY" }}{{ .Env.GITHUB_REPOSITORY }}{{ else }}eat-pray-ai/yutu{{ end }}
14+
- Builder={{ if index .Env "GITHUB_ACTOR" }}{{ .Env.GITHUB_ACTOR }}{{ else }}Gopher{{ end }}
1415

1516
before:
1617
hooks:
@@ -53,10 +54,11 @@ builds:
5354
- -X {{ .Env.MODULE_PATH }}/cmd.CommitDate={{ .CommitDate }}
5455
- -X {{ .Env.MODULE_PATH }}/cmd.Os={{ .Os }}
5556
- -X {{ .Env.MODULE_PATH }}/cmd.Arch={{ .Arch }}
57+
- -X {{ .Env.MODULE_PATH }}/cmd.Builder={{ .Env.Builder }}
5658
mod_timestamp: "{{ .CommitTimestamp }}"
5759

5860
archives:
59-
- formats: [ 'binary' ]
61+
- formats: ["binary"]
6062
ids:
6163
- yutu
6264
name_template: "{{ .Binary }}"
@@ -96,4 +98,3 @@ changelog:
9698

9799
release:
98100
discussion_category_name: General
99-

BUILD.bazel

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ go_binary(
4646
name = "yutu",
4747
embed = [":yutu_lib"],
4848
visibility = ["//visibility:public"],
49-
x_defs = {
50-
"Version": "{STABLE_VERSION}",
51-
"Commit": "{STABLE_GIT_SHORT_SHA}",
52-
"CommitDate": "{STABLE_GIT_COMMIT_DATE}",
53-
"Os": "{STABLE_OS}",
54-
"Arch": "{STABLE_ARCH}",
55-
},
5649
)
5750

5851
go_cross_binary(

cmd/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ go_library(
1616
"CommitDate": "{STABLE_GIT_COMMIT_DATE}",
1717
"Os": "{STABLE_OS}",
1818
"Arch": "{STABLE_ARCH}",
19+
"Builder": "{STABLE_Builder}",
1920
},
2021
deps = [
2122
"//pkg",

cmd/version.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
package cmd
55

66
import (
7+
"runtime/debug"
8+
79
"github.com/savioxavier/termlink"
810
"github.com/spf13/cobra"
911
)
1012

1113
const (
12-
versionShort = "Show the version of yutu"
13-
versionLong = "Show the version of yutu"
14+
verShort = "Show the version of yutu"
15+
verLong = "Show the version of yutu"
16+
repo = "Github/eat-pray-ai/yutu"
17+
repoUrl = "https://github.com/eat-pray-ai/yutu"
1418
)
1519

1620
var (
@@ -19,20 +23,37 @@ var (
1923
CommitDate = ""
2024
Os = ""
2125
Arch = ""
22-
repo = "https://github.com/eat-pray-ai/yutu"
26+
Builder = "Gopher"
2327
)
2428

2529
var versionCmd = &cobra.Command{
2630
Use: "version",
27-
Short: versionShort,
28-
Long: versionLong,
31+
Short: verShort,
32+
Long: verLong,
2933
Run: func(cmd *cobra.Command, args []string) {
30-
cmd.Printf("🐰yutu version %s %s/%s", Version, Os, Arch)
31-
if Commit != "" && CommitDate != "" {
32-
cmd.Printf("\n📦build %s-%s", Commit, CommitDate)
34+
info, ok := debug.ReadBuildInfo()
35+
if ok && Version == "" {
36+
Version = info.Main.Version
37+
38+
settings := make(map[string]string)
39+
for _, setting := range info.Settings {
40+
settings[setting.Key] = setting.Value
41+
}
42+
43+
if val, exists := settings["vcs.time"]; exists {
44+
CommitDate = val
45+
}
46+
if val, exists := settings["GOOS"]; exists {
47+
Os = val
48+
}
49+
if val, exists := settings["GOARCH"]; exists {
50+
Arch = val
51+
}
3352
}
3453

35-
cmd.Println("\n🌟Star:", termlink.Link("Github/eat-pray-ai/yutu", repo))
54+
cmd.Printf("🐰yutu %s %s/%s\n", Version, Os, Arch)
55+
cmd.Printf("📦build %s-%s\n", Builder, CommitDate)
56+
cmd.Printf("🌟Star: %s\n", termlink.Link(repo, repoUrl))
3657
},
3758
}
3859

docs/CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Here are some commands which may useful.
1616
## run tests
1717
### unit tests
1818
❯ go test ./... -coverprofile=./cover.out -coverpkg="$(go list || go list -m | head -1)/pkg/..."
19-
❯ go tool cover -html=cover.out -o=cover.html
19+
❯ go tool cover -html=cover.out -o=cover.html
2020

2121
## build the binary
2222
### install goreleaser: https://goreleaser.com/install
23-
GITHUB_REPOSITORY=eat-pray-ai/yutu goreleaser build --clean --auto-snapshot
23+
❯ goreleaser build --clean --auto-snapshot
2424

25-
❯ tree dist
25+
❯ tree dist
2626
dist
2727
├── artifacts.json
2828
├── config.yaml

scripts/bazel-status.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ fi
1919

2020
echo STABLE_OS "$(uname -s | tr '[:upper:]' '[:lower:]')"
2121
echo STABLE_ARCH "$(uname -m | sed 's/x86_64/amd64/' | tr '[:upper:]' '[:lower:]')"
22+
echo STABLE_Builder "${GITHUB_ACTOR:-$USER}"

scripts/command-test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ if [[ -z "$YUTU_PATH" ]]; then
1717
CommitDate="${MOD}.CommitDate=$(git log -1 --date='format:%Y-%m-%dT%H:%M:%SZ' --pretty=%cd)"
1818
Os="${MOD}.Os=$(go env GOOS)"
1919
Arch="${MOD}.Arch=$(go env GOARCH)"
20-
ldflags="-s -X ${Version} -X ${Commit} -X ${CommitDate} -X ${Os} -X ${Arch}"
20+
Builder="${MOD}.Builder=${GITHUB_ACTOR:-$USER}"
21+
ldflags="-s -X ${Version} -X ${Commit} -X ${CommitDate} -X ${Os} -X ${Arch} -X ${Builder}"
2122

2223
go mod download
2324
go build -ldflags "${ldflags}" -o yutu .

0 commit comments

Comments
 (0)