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

Split test runs among deployments #707

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: cimg/go:1.20
- image: cimg/go:1.22
steps:
- checkout
- run: go install github.com/mitchellh/[email protected]
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.DS_Store
metadata/
src/
.sfdx/

# Force CLI specific things
force
metadata
test
test

*.json

Expand Down
97 changes: 59 additions & 38 deletions command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"

. "github.com/ForceCLI/force/error"
. "github.com/ForceCLI/force/lib"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -38,53 +38,41 @@ func defaultDeployOutputOptions() *deployOutputOptions {

var testFailureError = errors.New("Apex tests failed")

func monitorDeploy(deployId string) (ForceCheckDeploymentStatusResult, error) {
var result ForceCheckDeploymentStatusResult
var err error
retrying := false
for {
result, err = force.Metadata.CheckDeployStatus(deployId)
if err != nil {
if retrying {
return result, fmt.Errorf("Error getting deploy status: %w", err)
} else {
retrying = true
Log.Info(fmt.Sprintf("Received error checking deploy status: %s. Will retry once before aborting.", err.Error()))
}
} else {
retrying = false
}
if result.Done {
break
}
if !retrying {
Log.Info(result)
}
time.Sleep(5000 * time.Millisecond)
}
return result, err
type deployStatus struct {
mu sync.Mutex
aborted bool
}

func deploy(force *Force, files ForceMetadataFiles, deployOptions *ForceDeployOptions, outputOptions *deployOutputOptions) error {
if outputOptions.quiet {
previousLogger := Log
var l quietLogger
Log = l
defer func() {
Log = previousLogger
}()
}
func (c *deployStatus) abort() {
c.mu.Lock()
c.aborted = true
c.mu.Unlock()
}

func (c *deployStatus) isAborted() bool {
c.mu.Lock()
defer c.mu.Unlock()
return c.aborted
}

func deploy(force *Force, files ForceMetadataFiles, deployOptions ForceDeployOptions, outputOptions *deployOutputOptions) error {
status := deployStatus{aborted: false}

return deployWith(force, &status, files, deployOptions, outputOptions)
}

func deployWith(force *Force, status *deployStatus, files ForceMetadataFiles, deployOptions ForceDeployOptions, outputOptions *deployOutputOptions) error {
startTime := time.Now()
deployId, err := force.Metadata.StartDeploy(files, *deployOptions)
deployId, err := force.Metadata.StartDeploy(files, deployOptions)
if err != nil {
ErrorAndExit(err.Error())
return err
}
stopDeployUponSignal(force, deployId)
if outputOptions.interactive {
watchDeploy(deployId)
return nil
}
result, err := monitorDeploy(deployId)
result, err := monitorDeploy(force, deployId, status)
if err != nil {
return err
}
Expand Down Expand Up @@ -156,6 +144,39 @@ func deploy(force *Force, files ForceMetadataFiles, deployOptions *ForceDeployOp
return nil
}

func monitorDeploy(force *Force, deployId string, status *deployStatus) (ForceCheckDeploymentStatusResult, error) {
var result ForceCheckDeploymentStatusResult
var err error
retrying := false
for {
if status.isAborted() {
fmt.Fprintf(os.Stderr, "Cancelling deploy %s\n", deployId)
force.Metadata.CancelDeploy(deployId)
return result, nil
}
result, err = force.Metadata.CheckDeployStatus(deployId)
if err != nil {
if retrying {
return result, fmt.Errorf("Error getting deploy status: %w", err)
} else {
retrying = true
Log.Info(fmt.Sprintf("Received error checking deploy status: %s. Will retry once before aborting.", err.Error()))
}
} else {
retrying = false
}
result.UserName = force.GetCredentials().UserInfo.UserName
if result.Done {
break
}
if !retrying {
Log.Info(result)
}
time.Sleep(5000 * time.Millisecond)
}
return result, err
}

func stopDeployUponSignal(force *Force, deployId string) {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
Expand Down
2 changes: 1 addition & 1 deletion command/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func updateFLSOnProfile(force *Force, objectName string, fieldName string) (err
}
displayOptions := defaultDeployOutputOptions()
displayOptions.quiet = true
return deploy(force, pb.ForceMetadataFiles(), new(ForceDeployOptions), displayOptions)
return deploy(force, pb.ForceMetadataFiles(), ForceDeployOptions{}, displayOptions)
}

func getFLSUpdateXML(objectName string, fieldName string) string {
Expand Down
Loading