Skip to content

Commit

Permalink
make cmd upgrade using go install
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Apr 14, 2024
1 parent b0dd187 commit a9cbbd9
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 7 deletions.
32 changes: 32 additions & 0 deletions cmd/xgo/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ const latestURL = "https://github.com/xhd2015/xgo/releases/latest"

func Upgrade(installDir string) error {
ctx := context.Background()
if true {
curXgoVersion, err := cmdXgoVersion()
if err != nil {
return err
}
// always run a simple go install command
err = cmdInstallXgo()
if err != nil {
return err
}
xgoVersionAfterUpdate, err := cmdXgoVersion()
if err != nil {
return err
}
if xgoVersionAfterUpdate == "" {
fmt.Fprintf(os.Stderr, "command 'xgo' not found, you may need to add $GOPATH/bin to your PATH\n")
return nil
}
if curXgoVersion == xgoVersionAfterUpdate {
fmt.Printf("upgraded xgo v%s\n", xgoVersionAfterUpdate)
return nil
}
fmt.Printf("upgraded xgo v%s -> v%s\n", curXgoVersion, xgoVersionAfterUpdate)
return nil
}

fmt.Printf("checking latest version...\n")
latestVersion, err := GetLatestVersion(ctx, 60*time.Second, latestURL)
if err != nil {
Expand Down Expand Up @@ -137,6 +163,12 @@ func cmdXgoVersion() (string, error) {
}
return version, nil
}
func cmdInstallXgo() error {
cmd := exec.Command("go", "install", "github.com/xhd2015/xgo/cmd/xgo@latest")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
return cmd.Run()
}

func cmdOutput(cmd string, args ...string) (string, error) {
exeCmd := exec.Command(cmd, args...)
Expand Down
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import "fmt"

const VERSION = "1.0.24"
const REVISION = "b70bf6dce3af4317cb6a3b2b18dc30e2b36b8afa+1"
const NUMBER = 179
const REVISION = "b0dd1873bc3e5e5464f55c7b01a077712dc4c818+1"
const NUMBER = 180

func getRevision() string {
revSuffix := ""
Expand Down
2 changes: 1 addition & 1 deletion install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $XgoInstallSrc = mkdir -Force "${XgoRoot}\install-src"

Remove-Item -Recurse -Force "${XgoInstallSrc}"

$URL = "https://github.com/xhd2015/xgo/releases/download/v1.0.19/install-src.zip"
$URL = "https://github.com/xhd2015/xgo/releases/download/v1.0.24/install-src.zip"
$ZipPath = "${XgoBin}\install-src.zip"

# curl.exe is faster than PowerShell 5's 'Invoke-WebRequest'
Expand Down
6 changes: 3 additions & 3 deletions runtime/core/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
)

const VERSION = "1.0.24"
const REVISION = "b70bf6dce3af4317cb6a3b2b18dc30e2b36b8afa+1"
const NUMBER = 179
const REVISION = "b0dd1873bc3e5e5464f55c7b01a077712dc4c818+1"
const NUMBER = 180

// these fields will be filled by compiler
const XGO_VERSION = ""
Expand Down Expand Up @@ -45,7 +45,7 @@ func checkVersion() error {
}
var updateCmd string
if XGO_NUMBER < NUMBER {
updateCmd = "xgo update"
updateCmd = "xgo upgrade"
} else {
updateCmd = "go get github.com/xhd2015/xgo/runtime@latest"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/xhd2015/xgo/runtime/trace"
)

func TestMarshalWithTrace(t *testing.T) {
func TestSubTestTraces(t *testing.T) {
const N = 10
traces := make([]*trace.Root, N)
for i := 0; i < 10; i++ {
Expand Down
32 changes: 32 additions & 0 deletions script/install/upgrade/upgrade.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a9cbbd9

Please sign in to comment.