Skip to content

Commit

Permalink
feat: adds wait option for sf deploys #300 (#301)
Browse files Browse the repository at this point in the history
* feat: adds wait option for sf deploys  #300

* chore: fix linting issues  #300
  • Loading branch information
srinandan authored Sep 20, 2023
1 parent ba4ea88 commit 0ef1ca9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
43 changes: 42 additions & 1 deletion cmd/sharedflows/depsf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
package sharedflows

import (
"encoding/json"
"time"

"internal/apiclient"
"internal/clilog"

"internal/client/sharedflows"

Expand All @@ -38,15 +42,49 @@ var DepCmd = &cobra.Command{
}
}
_, err = sharedflows.Deploy(name, revision, overrides, serviceAccountName)
apiclient.DisableCmdPrintHttpResponse()

if wait {
clilog.Info.Printf("Checking deployment status in %d seconds\n", interval)

stop := apiclient.Every(interval*time.Second, func(time.Time) bool {
var respBody []byte
respMap := make(map[string]interface{})
if respBody, err = sharedflows.ListRevisionDeployments(name, revision); err != nil {
clilog.Error.Printf("Error fetching sharedflow revision status: %v", err)
return false
}

if err = json.Unmarshal(respBody, &respMap); err != nil {
return true
}

if respMap["state"] == "PROGRESSING" {
clilog.Info.Printf("Sharedflow deployment status is: %s. Waiting %d seconds.\n", respMap["state"], interval)
return true
} else if respMap["state"] == "READY" {
clilog.Info.Println("Sharedflow deployment completed with status: ", respMap["state"])
return false
} else {
clilog.Info.Println("Sharedflow deployment failed with status: ", respMap["state"])
return false
}
})

<-stop
}

return err
},
}

var (
overrides bool
overrides, wait bool
serviceAccountName string
)

const interval = 10

func init() {
DepCmd.Flags().StringVarP(&name, "name", "n",
"", "Sharedflow name")
Expand All @@ -56,6 +94,9 @@ func init() {
-1, "Sharedflow revision. If not set, the highest revision is used")
DepCmd.Flags().BoolVarP(&overrides, "ovr", "r",
false, "Forces deployment of the new revision")
DepCmd.Flags().BoolVarP(&wait, "wait", "",
false, "Waits for the deployment to finish, with success or error")

DepCmd.Flags().StringVarP(&serviceAccountName, "sa", "s",
"", "The format must be {ACCOUNT_ID}@{PROJECT}.iam.gserviceaccount.com.")

Expand Down
7 changes: 4 additions & 3 deletions internal/bundlegen/proxybundle/proxybundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ import (
"golang.org/x/oauth2"
)

var proxyRootDir = "apiproxy"
var sfRootDir = "sharedflowbundle"
var (
proxyRootDir = "apiproxy"
sfRootDir = "sharedflowbundle"
)

func GenerateAPIProxyBundleFromOAS(name string,
content string,
Expand Down Expand Up @@ -692,7 +694,6 @@ func archiveBundle(pathToZip, destinationPath string, sharedflow bool) (err erro
}

func GitHubImportBundle(owner string, repo string, repopath string, sharedflow bool) (err error) {

var rootDir string

if sharedflow {
Expand Down
2 changes: 1 addition & 1 deletion internal/client/appgroups/appgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func Update(name string, channelURI string, channelID string, displayName string
developerDetailsAttribute.Value = getDeveloperDetails(devs)
}

//clear existing attributes
// clear existing attributes
a.Attributes = nil

if len(attrs) != 0 {
Expand Down

0 comments on commit 0ef1ca9

Please sign in to comment.