mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
feat(cmd/upgrade): compatible with go get and go install (#1255)
* feat(cmd/upgrade): compatible with go get and go install
This commit is contained in:
parent
c7fcd388b5
commit
9808ceb7a8
24
cmd/kratos/internal/base/install.go
Normal file
24
cmd/kratos/internal/base/install.go
Normal file
@ -0,0 +1,24 @@
|
||||
//go:build go1.17
|
||||
// +build go1.17
|
||||
|
||||
package base
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// GoInstall go get path.
|
||||
func GoInstall(path ...string) error {
|
||||
for _, p := range path {
|
||||
fmt.Printf("go install %s@latest\n", p)
|
||||
cmd := exec.Command("go", "install", fmt.Sprintf("%s@latest", p))
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
24
cmd/kratos/internal/base/install_compatible.go
Normal file
24
cmd/kratos/internal/base/install_compatible.go
Normal file
@ -0,0 +1,24 @@
|
||||
//go:build !go1.17
|
||||
// +build !go1.17
|
||||
|
||||
package base
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// GoInstall go get path.
|
||||
func GoInstall(path ...string) error {
|
||||
for _, p := range path {
|
||||
fmt.Printf("go get -u %s\n", p)
|
||||
cmd := exec.Command("go", "get", "-u", p)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/go-kratos/kratos/cmd/kratos/v2/internal/base"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -27,17 +26,17 @@ func init() {
|
||||
}
|
||||
|
||||
func run(cmd *cobra.Command, args []string) {
|
||||
owner, repo := base.ParseGithubUrl(repoURL)
|
||||
api := base.GithubApi{Owner: owner, Repo: repo, Token: token}
|
||||
owner, repo := ParseGithubUrl(repoURL)
|
||||
api := GithubApi{Owner: owner, Repo: repo, Token: token}
|
||||
version := "latest"
|
||||
if len(args) > 0 {
|
||||
version = args[0]
|
||||
}
|
||||
if version == "dev" {
|
||||
info := api.GetCommitsInfo()
|
||||
fmt.Print(base.ParseCommitsInfo(info))
|
||||
fmt.Print(ParseCommitsInfo(info))
|
||||
} else {
|
||||
info := api.GetReleaseInfo(version)
|
||||
fmt.Print(base.ParseReleaseInfo(info))
|
||||
fmt.Print(ParseReleaseInfo(info))
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package base
|
||||
package change
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@ -8,26 +8,11 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GoGet go get path.
|
||||
func GoGet(path ...string) error {
|
||||
for _, p := range path {
|
||||
fmt.Printf("go get -u %s\n", p)
|
||||
cmd := exec.Command("go", "get", "-u", p)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ReleaseInfo struct {
|
||||
Author struct {
|
||||
Login string `json:"login"`
|
@ -18,7 +18,7 @@ var CmdUpgrade = &cobra.Command{
|
||||
|
||||
// Run upgrade the kratos tools.
|
||||
func Run(cmd *cobra.Command, args []string) {
|
||||
err := base.GoGet(
|
||||
err := base.GoInstall(
|
||||
"github.com/go-kratos/kratos/cmd/kratos/v2",
|
||||
"github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2",
|
||||
"github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2",
|
||||
|
Loading…
x
Reference in New Issue
Block a user