Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/rollback #4

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ chmod +x code-push-go

#Update react native
./code-push-go create_bundle -t <TargetVersion> -n <AppName> -d <DeploymentName> -p <(*Optional) React native project default:./> --description <(*Optional) Description default: ""/>

#More command
./code-push-go
```

## License
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ func main() {
" login Authenticate in order to begin managing your apps\n" +
" logout Log out of the current session\n" +
" app View and manage your CodePush apps\n" +
" create_bundle Create react native hotfix bundle"
" create_bundle Create react native hotfix bundle\n" +
" rollback Rollback last dundle"

var command string
if len(args) <= 0 {
fmt.Println(help)
Expand All @@ -46,6 +48,8 @@ func main() {
opt.App{}.CreateBundle()
case "app":
opt.App{}.App(args)
case "rollback":
opt.App{}.Rollback()
default:
fmt.Println(help)
return
Expand Down
74 changes: 74 additions & 0 deletions opt/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os/exec"
"strconv"
"strings"
"time"

"com.lc.go.codepush/client/constants"
"com.lc.go.codepush/client/utils"
Expand Down Expand Up @@ -591,3 +592,76 @@ func (App) deleteDeployment() {
fmt.Println("Delete deployment " + deploymentName + " success")
}
}

type rollbackReq struct {
AppName *string `json:"appName" binding:"required"`
Deployment *string `json:"deployment" binding:"required"`
Version *string `json:"version" binding:"required"`
}

type rollbackRep struct {
Success *bool `json:"success"`
Version *string `json:"version"`
PackId *int `json:"packId"`
Size *int64 `json:"size"`
Hash *string `json:"hash"`
CreateTime *int64 `json:"createTime"`
}

func (App) Rollback() {
saveLoginInfo, err := utils.GetLoginfo()
if err != nil {
log.Println(err.Error())
return
}

var targetVersion string
var appName string
var deployment string

flag.StringVar(&targetVersion, "t", "", "Target version")
flag.StringVar(&appName, "n", "", "AppName")
flag.StringVar(&deployment, "d", "", "DeploymentName")
flag.Parse()

if appName == "" || deployment == "" || targetVersion == "" {
fmt.Println("Usage: code-push-go rollback -n <AppName> -d <deployment> -t <TargetVersion>")
return
}

rollbackReq := rollbackReq{
AppName: &appName,
Deployment: &deployment,
Version: &targetVersion,
}

jsonByte, _ := json.Marshal(rollbackReq)
Url, err := url.Parse(saveLoginInfo.ServerUrl + "/rollback")
if err != nil {
log.Panic("server url error :", err.Error())
}
reqStatus, err := utils.HttpPostToken[rollbackRep](Url.String(), jsonByte, &saveLoginInfo.Token)
if err != nil {
fmt.Println(err.Error())
return
}
if *reqStatus.Success {
fmt.Println("Rollback " + deployment + " success,currut version:")
titles := []string{"DeploymentName", "AppVersion", "PackId", "Size", "Hash", "CreateTime"}
table, err := gotable.Create(titles...)
if err != nil {
fmt.Println(err.Error())
return
}
var columns []string
if reqStatus.PackId == nil {
columns = []string{deployment, *reqStatus.Version}
} else {
columns = []string{deployment, *reqStatus.Version, strconv.Itoa(*reqStatus.PackId), strconv.FormatInt(*reqStatus.Size, 10), *reqStatus.Hash, time.Unix(0, *reqStatus.CreateTime*1e6).String()}
}

table.AddRow(columns)
fmt.Println(table)

}
}
Loading