@@ -2,8 +2,10 @@ package stream
22
33import (
44 "github.com/ddkwork/golibrary/safemap"
5+ "golang.org/x/mod/modfile"
56 "os"
67 "path/filepath"
8+ "runtime"
79 "strconv"
810 "strings"
911 "sync"
@@ -27,137 +29,34 @@ var skips = []string{
2729// git ls-remote https://github.com/ddkwork/toolbox refs/heads/master
2830// git ls-remote https://github.com/gioui/gio refs/heads/main
2931// 但是要传递本地的仓库目录,太麻烦了
30- func GetLastCommitHash (repositoryName string ) string {
31- //理论上获取到hash再使用模块代理,这样才刷新的快?
32- //或者使用action得到hash先?
33-
34- mylog .Check (os .Setenv ("GOPROXY" , "direct" )) // 如果模块代理导致获取到的不是最新的提交哈希那么需要禁用模块代理,最可靠的方式是 GetLastCommitHashLocal
35- defer mylog .Check (os .Setenv ("GOPROXY" , "https://goproxy.cn,direct" ))
36-
37- //defer RunCommand("go env -w GOPROXY=https://goproxy.cn,direct")
38- s := RunCommand ("git ls-remote " + repositoryName + " refs/heads/master" ).Output .String ()
39- for hash := range strings .FieldsSeq (s ) {
40- return hash
41- }
42- s = RunCommand ("git ls-remote " + repositoryName + " refs/heads/main" ).Output .String ()
43- for hash := range strings .FieldsSeq (s ) {
44- return hash
45- }
46- panic ("no commit hash found in master and main branch" )
47- /*
48- # 获取最新提交哈希
49- $hash = (git ls-remote https://github.com/ddkwork/toolbox refs/heads/master).Split("`t")[0]
50- # 带哈希安装
51- go get -x "github.com/ddkwork/toolbox@$hash"
52-
53- powershell:
54- $env:GOPROXY="direct"; go get -x github.com/ddkwork/toolbox@$(git ls-remote https://github.com/ddkwork/toolbox refs/heads/master | ForEach-Object { $_.Split()[0] })
55-
56- */
57- }
58-
59- type ModInfo struct {
60- ModName string //gioui.org
61- RepositoryUrl string //https://github.com/gioui/gio
62- repositoryDir string //GetLastCommitHashLocal
63- Hash string //GetLastCommitHash or GetLastCommitHashLocal
64- UpdateCommand string //go get -x gioui.org@hash
65- }
66-
67- var m = safemap.NewOrdered [string , ModInfo ](func (yield func (string , ModInfo ) bool ) {
68- yield ("https://github.com/gioui/gio" , ModInfo {
69- ModName : "gioui.org" ,
70- RepositoryUrl : "https://github.com/gioui/gio" ,
71- repositoryDir : "" ,
72- Hash : "" ,
73- UpdateCommand : "" ,
74- })
75- yield ("https://github.com/gioui/gio/cmd" , ModInfo {
76- ModName : "gioui.org/cmd" ,
77- RepositoryUrl : "https://github.com/gioui/gio/cmd" ,
78- repositoryDir : "" ,
79- Hash : "" ,
80- UpdateCommand : "" ,
81- })
82- yield ("https://github.com/gioui/gio/example" , ModInfo {
83- ModName : "gioui.org/example" ,
84- RepositoryUrl : "https://github.com/gioui/gio/example" ,
85- repositoryDir : "" ,
86- Hash : "" ,
87- UpdateCommand : "" ,
88- })
89- yield ("https://github.com/gioui/gio/x" , ModInfo {
90- ModName : "gioui.org/x" ,
91- RepositoryUrl : "https://github.com/gioui/gio/x" ,
92- repositoryDir : "" ,
93- Hash : "" ,
94- UpdateCommand : "" ,
95- })
96- yield ("https://github.com/oligo/gvcode" , ModInfo {
97- ModName : "github.com/oligo/gvcode" ,
98- RepositoryUrl : "https://github.com/oligo/gvcode" ,
99- repositoryDir : "" ,
100- Hash : "" ,
101- UpdateCommand : "" ,
102- })
103- yield ("https://github.com/ddkwork/golibrary" , ModInfo {
104- ModName : "github.com/ddkwork/golibrary" ,
105- RepositoryUrl : "https://github.com/ddkwork/golibrary" ,
106- repositoryDir : "" ,
107- Hash : "" ,
108- UpdateCommand : "" ,
109- })
110- yield ("https://github.com/ddkwork/ux" , ModInfo {
111- ModName : "github.com/ddkwork/ux" ,
112- RepositoryUrl : "https://github.com/ddkwork/ux" ,
113- repositoryDir : "" ,
114- Hash : "" ,
115- UpdateCommand : "" ,
116- })
117- yield ("https://github.com/google/go-cmp" , ModInfo {
118- ModName : "github.com/google/go-cmp" ,
119- RepositoryUrl : "https://github.com/google/go-cmp" ,
120- repositoryDir : "" ,
121- Hash : "" ,
122- UpdateCommand : "" ,
123- })
124- yield ("https://github.com/ddkwork/app" , ModInfo {
125- ModName : "github.com/ddkwork/app" ,
126- RepositoryUrl : "https://github.com/ddkwork/app" ,
127- repositoryDir : "" ,
128- Hash : "" ,
129- UpdateCommand : "" ,
130- })
131- yield ("https://github.com/ddkwork/toolbox" , ModInfo {
132- ModName : "github.com/ddkwork/toolbox" ,
133- RepositoryUrl : "https://github.com/ddkwork/toolbox" ,
134- repositoryDir : "" ,
135- Hash : "" ,
136- UpdateCommand : "" ,
137- })
138- yield ("https://github.com/ddkwork/unison" , ModInfo {
139- ModName : "github.com/ddkwork/unison" ,
140- RepositoryUrl : "https://github.com/ddkwork/unison" ,
141- repositoryDir : "" ,
142- Hash : "" ,
143- UpdateCommand : "" ,
144- })
145- yield ("https://github.com/ebitengine/purego" , ModInfo {
146- ModName : "github.com/ebitengine/purego" ,
147- RepositoryUrl : "https://github.com/ebitengine/purego" ,
148- repositoryDir : "" ,
149- Hash : "" ,
150- UpdateCommand : "" ,
151- })
152- yield ("https://github.com/saferwall/pe" , ModInfo {
153- ModName : "github.com/saferwall/pe" ,
154- RepositoryUrl : "https://github.com/saferwall/pe" ,
155- repositoryDir : "" ,
156- Hash : "" ,
157- UpdateCommand : "" ,
158- })
159-
160- })
32+ //func GetLastCommitHash(repositoryName string) string {
33+ // //理论上获取到hash再使用模块代理,这样才刷新的快?
34+ // //或者使用action得到hash先?
35+ //
36+ // mylog.Check(os.Setenv("GOPROXY", "direct")) // 如果模块代理导致获取到的不是最新的提交哈希那么需要禁用模块代理,最可靠的方式是 GetLastCommitHashLocal
37+ // defer mylog.Check(os.Setenv("GOPROXY", "https://goproxy.cn,direct"))
38+ //
39+ // //defer RunCommand("go env -w GOPROXY=https://goproxy.cn,direct")
40+ // s := RunCommand("git ls-remote " + repositoryName + " refs/heads/master").Output.String()
41+ // for hash := range strings.FieldsSeq(s) {
42+ // return hash
43+ // }
44+ // s = RunCommand("git ls-remote " + repositoryName + " refs/heads/main").Output.String()
45+ // for hash := range strings.FieldsSeq(s) {
46+ // return hash
47+ // }
48+ // panic("no commit hash found in master and main branch")
49+ // /*
50+ // # 获取最新提交哈希
51+ // $hash = (git ls-remote https://github.com/ddkwork/toolbox refs/heads/master).Split("`t")[0]
52+ // # 带哈希安装
53+ // go get -x "github.com/ddkwork/toolbox@$hash"
54+ //
55+ // powershell:
56+ // $env:GOPROXY="direct"; go get -x github.com/ddkwork/toolbox@$(git ls-remote https://github.com/ddkwork/toolbox refs/heads/master | ForEach-Object { $_.Split()[0] })
57+ //
58+ // */
59+ //}
16160
16261func GetLastCommitHashLocal (repositoryName , repositoryDir string ) string {
16362 originPath := mylog .Check2 (os .Getwd ())
@@ -167,32 +66,38 @@ func GetLastCommitHashLocal(repositoryName, repositoryDir string) string {
16766 return hash
16867}
16968
170- func UpdateDependencies () { //模块代理刷新的不及时,需要禁用代理
171- mylog .Check (os .Setenv ("GOPROXY" , "direct" ))
172- for s := range strings .Lines (`
173- go get -x gioui.org@main
174- go get -x gioui.org/cmd@main
175- go get -x gioui.org/example@main
176- go get -x gioui.org/x@main
177- go get -x github.com/oligo/gvcode@main
178- go get -x github.com/ddkwork/golibrary@master
179- go get -x github.com/ddkwork/ux@master
180- go get -x github.com/google/go-cmp@master
181- go get -x github.com/ddkwork/app@master
182- go get -x github.com/ddkwork/toolbox@master
183- go get -x github.com/ddkwork/unison@master
184- go get -x github.com/ebitengine/purego@main
185- go get -x github.com/saferwall/pe@main
186- ::go get -u -x all
187- go mod tidy
69+ func ParseGoMod () * safemap.M [string , string ] {
70+ path := "go.mod"
71+ f := mylog .Check2 (modfile .Parse (path , mylog .Check2 (os .ReadFile (path )), nil ))
72+ return safemap.NewOrdered [string , string ](func (yield func (string , string ) bool ) {
73+ for _ , req := range f .Require {
74+ yield (req .Mod .Path , req .Mod .Version )
75+ }
76+ })
77+ }
18878
189- go install mvdan.cc/gofumpt@latest
190- gofumpt -l -w .
191- //go install honnef.co/go/tools/cmd/staticcheck@latest
192- //staticcheck ./...
193- //go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
79+ func GetDesktopDir () string {
80+ // 获取用户主目录
81+ homeDir := mylog .Check2 (os .UserHomeDir ())
82+ // 根据操作系统处理路径
83+ switch runtime .GOOS {
84+ case "windows" , "darwin" :
85+ // Windows和macOS直接拼接Desktop
86+ return filepath .Join (homeDir , "Desktop" )
87+ case "linux" :
88+ // Linux优先检查XDG环境变量
89+ if xdgDir := os .Getenv ("XDG_DESKTOP_DIR" ); xdgDir != "" {
90+ return xdgDir
91+ }
92+ // 默认使用主目录下的Desktop
93+ return filepath .Join (homeDir , "Desktop" )
94+ default :
95+ panic ("unsupported platform" )
96+ }
97+ }
19498
195- ` ) {
99+ func UpdateDependencies () { //模块代理刷新的不及时,需要禁用代理,已经使用clone仓库远程完成更新
100+ for s := range ReadFileToLines (filepath .Join (GetDesktopDir (), "dep.txt" )) { //因为要经常更新,我们不embed
196101 s = strings .TrimSpace (s )
197102 if strings .HasPrefix (s , "::" ) || strings .HasPrefix (s , "//" ) || s == "" {
198103 continue
@@ -248,6 +153,40 @@ func updateModsByWorkSpace(isUpdateAll bool) {
248153 mylog .Success ("all work finished" )
249154}
250155
156+ func updateDependencies () { //模块代理刷新的不及时,需要禁用代理,已经使用clone仓库远程完成更新
157+ mylog .Check (os .Setenv ("GOPROXY" , "direct" ))
158+ for s := range strings .Lines (`
159+ go get -x gioui.org@main
160+ go get -x gioui.org/cmd@main
161+ go get -x gioui.org/example@main
162+ go get -x gioui.org/x@main
163+ go get -x github.com/oligo/gvcode@main
164+ go get -x github.com/ddkwork/golibrary@master
165+ go get -x github.com/ddkwork/ux@master
166+ go get -x github.com/google/go-cmp@master
167+ go get -x github.com/ddkwork/app@master
168+ go get -x github.com/ddkwork/toolbox@master
169+ go get -x github.com/ddkwork/unison@master
170+ go get -x github.com/ebitengine/purego@main
171+ go get -x github.com/saferwall/pe@main
172+ ::go get -u -x all
173+ go mod tidy
174+
175+ go install mvdan.cc/gofumpt@latest
176+ gofumpt -l -w .
177+ //go install honnef.co/go/tools/cmd/staticcheck@latest
178+ //staticcheck ./...
179+ //go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
180+
181+ ` ) {
182+ s = strings .TrimSpace (s )
183+ if strings .HasPrefix (s , "::" ) || strings .HasPrefix (s , "//" ) || s == "" {
184+ continue
185+ }
186+ RunCommand (s )
187+ }
188+ }
189+
251190//type Cache struct {
252191// store map[string]string
253192// mu sync.RWMutex
0 commit comments