Skip to content

Commit

Permalink
Always write update output file, even on container failure
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyskoedijk committed Oct 23, 2024
1 parent 9b18a3b commit 7160478
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions internal/infra/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
"os/signal"
"regexp"
"strings"
"syscall"
"time"

"github.com/dependabot/cli/internal/model"
"github.com/dependabot/cli/internal/server"
"github.com/docker/docker/api/types"
Expand All @@ -17,15 +27,6 @@ import (
"github.com/moby/moby/api/types/registry"
"github.com/moby/moby/client"
"gopkg.in/yaml.v3"
"io"
"log"
"net/http"
"os"
"os/signal"
"regexp"
"strings"
"syscall"
"time"
)

type RunParams struct {
Expand Down Expand Up @@ -131,12 +132,15 @@ func Run(params RunParams) error {
if params.ApiUrl == "" {
params.ApiUrl = fmt.Sprintf("http://host.docker.internal:%v", api.Port())
}
if err := runContainers(ctx, params); err != nil {
return err
}

// run the containers, but don't return the error until AFTER the output is generated.
// this ensures that the output is always written in the scenario where there are multiple outputs,
// some that succeed and some that fail; we still want to see the output of the successful ones.
runContainersErr := runContainers(ctx, params)

api.Complete()

// write the output to a file
output, err := generateOutput(params, api, outFile)
if err != nil {
return err
Expand All @@ -146,6 +150,11 @@ func Run(params RunParams) error {
return diff(params, outFile, output)
}

// if the containers failed, poperagate the error
if runContainersErr != nil {
return runContainersErr
}

return nil
}

Expand Down

0 comments on commit 7160478

Please sign in to comment.