feat(cmd/upgrade): compatible with go get and go install (#1255)

* feat(cmd/upgrade): compatible with go get and go install
pull/1257/head
包子 3 years ago committed by GitHub
parent c7fcd388b5
commit 9808ceb7a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      cmd/kratos/internal/base/install.go
  2. 24
      cmd/kratos/internal/base/install_compatible.go
  3. 9
      cmd/kratos/internal/change/change.go
  4. 17
      cmd/kratos/internal/change/get.go
  5. 2
      cmd/kratos/internal/upgrade/upgrade.go

@ -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
}

@ -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…
Cancel
Save