Skip to content
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
23 changes: 14 additions & 9 deletions cmd/src/batch_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"io"
cliLog "log"
"os"
"os/exec"
"os/signal"
Expand Down Expand Up @@ -48,6 +49,7 @@ type batchExecutionFlags struct {
api *api.Flags
clearCache bool
namespace string
skipErrors bool
}

func newBatchExecutionFlags(flagSet *flag.FlagSet) *batchExecutionFlags {
Expand All @@ -63,6 +65,10 @@ func newBatchExecutionFlags(flagSet *flag.FlagSet) *batchExecutionFlags {
&bef.clearCache, "clear-cache", false,
"If true, clears the execution cache and executes all steps anew.",
)
flagSet.BoolVar(
&bef.skipErrors, "skip-errors", false,
"If true, errors encountered won't stop the program, but only log them.",
)
flagSet.BoolVar(
&bef.allowIgnored, "force-override-ignore", false,
"Do not ignore repositories that have a .batchignore file.",
Expand Down Expand Up @@ -146,11 +152,6 @@ func newBatchExecuteFlags(flagSet *flag.FlagSet, cacheDir, tempDir string) *batc
"If true, deletes downloaded repository archives after executing batch spec steps. Note that only the archives related to the actual repositories matched by the batch spec will be cleaned up, and clean up will not occur if src exits unexpectedly.",
)

flagSet.BoolVar(
&caf.skipErrors, "skip-errors", false,
"If true, errors encountered while executing steps in a repository won't stop the execution of the batch spec but only cause that repository to be skipped.",
)

flagSet.StringVar(
&caf.workspace, "workspace", "auto",
`Workspace mode to use ("auto", "bind", or "volume")`,
Expand Down Expand Up @@ -290,7 +291,7 @@ func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error
Client: opts.client,
})

lr, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx)
lr, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx, opts.flags.skipErrors)
if err != nil {
return err
}
Expand All @@ -302,8 +303,12 @@ func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error

imageCache := docker.NewImageCache()

if err := validateSourcegraphVersionConstraint(ctx, ffs); err != nil {
return err
if err := validateSourcegraphVersionConstraint(ffs); err != nil {
if !opts.flags.skipErrors {
return err
} else {
cliLog.Printf("WARNING: %s", err)
}
}

if err := checkExecutable("git", "version"); err != nil {
Expand Down Expand Up @@ -655,7 +660,7 @@ func getBatchParallelism(ctx context.Context, flag int) (int, error) {
return docker.NCPU(ctx)
}

func validateSourcegraphVersionConstraint(ctx context.Context, ffs *batches.FeatureFlags) error {
func validateSourcegraphVersionConstraint(ffs *batches.FeatureFlags) error {
if ffs.Sourcegraph40 {
return nil
}
Expand Down
18 changes: 14 additions & 4 deletions cmd/src/batch_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"flag"
"fmt"
cliLog "log"

"github.com/sourcegraph/src-cli/internal/api"
"github.com/sourcegraph/src-cli/internal/batches/service"
Expand All @@ -30,7 +31,12 @@ Examples:
apiFlags := api.NewFlags(flagSet)

var (
fileFlag = flagSet.String("f", "batch.yaml", "The name of the batch spec file to create.")
fileFlag = flagSet.String("f", "batch.yaml", "The name of the batch spec file to create.")
skipErrors bool
)
flagSet.BoolVar(
&skipErrors, "skip-errors", false,
"If true, errors encountered won't stop the program, but only log them.",
)

handler := func(args []string) error {
Expand All @@ -48,13 +54,17 @@ Examples:
Client: cfg.apiClient(apiFlags, flagSet.Output()),
})

_, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx)
_, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx, skipErrors)
if err != nil {
return err
}

if err := validateSourcegraphVersionConstraint(ctx, ffs); err != nil {
return err
if err := validateSourcegraphVersionConstraint(ffs); err != nil {
if !skipErrors {
return err
} else {
cliLog.Printf("WARNING: %s", err)
}
}

if err := svc.GenerateExampleSpec(ctx, *fileFlag); err != nil {
Expand Down
11 changes: 8 additions & 3 deletions cmd/src/batch_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"flag"
"fmt"
cliLog "log"
"strings"
"time"

Expand Down Expand Up @@ -52,13 +53,17 @@ Examples:
Client: cfg.apiClient(flags.api, flagSet.Output()),
})

_, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx)
_, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx, flags.skipErrors)
if err != nil {
return err
}

if err := validateSourcegraphVersionConstraint(ctx, ffs); err != nil {
return err
if err := validateSourcegraphVersionConstraint(ffs); err != nil {
if !flags.skipErrors {
return err
} else {
cliLog.Printf("WARNING: %s", err)
}
}

out := output.NewOutput(flagSet.Output(), output.OutputOpts{Verbose: *verbose})
Expand Down
16 changes: 13 additions & 3 deletions cmd/src/batch_repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"flag"
"fmt"
cliLog "log"

"github.com/sourcegraph/sourcegraph/lib/errors"
"github.com/sourcegraph/sourcegraph/lib/output"
Expand Down Expand Up @@ -42,6 +43,7 @@ Examples:
var (
allowUnsupported bool
allowIgnored bool
skipErrors bool
)
flagSet.BoolVar(
&allowUnsupported, "allow-unsupported", false,
Expand All @@ -51,6 +53,10 @@ Examples:
&allowIgnored, "force-override-ignore", false,
"Do not ignore repositories that have a .batchignore file.",
)
flagSet.BoolVar(
&skipErrors, "skip-errors", false,
"If true, errors encountered won't stop the program, but only log them.",
)

handler := func(args []string) error {
if err := flagSet.Parse(args); err != nil {
Expand All @@ -69,13 +75,17 @@ Examples:
Client: client,
})

_, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx)
_, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx, skipErrors)
if err != nil {
return err
}

if err := validateSourcegraphVersionConstraint(ctx, ffs); err != nil {
return err
if err := validateSourcegraphVersionConstraint(ffs); err != nil {
if !skipErrors {
return err
} else {
cliLog.Printf("WARNING: %s", err)
}
}

out := output.NewOutput(flagSet.Output(), output.OutputOpts{Verbose: *verbose})
Expand Down
18 changes: 14 additions & 4 deletions cmd/src/batch_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"flag"
"fmt"
cliLog "log"

"github.com/sourcegraph/sourcegraph/lib/output"

Expand Down Expand Up @@ -36,6 +37,7 @@ Examples:
var (
allowUnsupported bool
allowIgnored bool
skipErrors bool
)
flagSet.BoolVar(
&allowUnsupported, "allow-unsupported", false,
Expand All @@ -45,6 +47,10 @@ Examples:
&allowIgnored, "force-override-ignore", false,
"Do not ignore repositories that have a .batchignore file.",
)
flagSet.BoolVar(
&skipErrors, "skip-errors", false,
"If true, errors encountered won't stop the program, but only log them.",
)

handler := func(args []string) error {
ctx := context.Background()
Expand All @@ -63,14 +69,18 @@ Examples:
Client: cfg.apiClient(apiFlags, flagSet.Output()),
})

_, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx)
_, ffs, err := svc.DetermineLicenseAndFeatureFlags(ctx, skipErrors)
if err != nil {
return err
}

if err := validateSourcegraphVersionConstraint(ctx, ffs); err != nil {
ui.ExecutionError(err)
return err
if err := validateSourcegraphVersionConstraint(ffs); err != nil {
if !skipErrors {
ui.ExecutionError(err)
return err
} else {
cliLog.Printf("WARNING: %s", err)
}
}

file, err := getBatchSpecFile(flagSet, fileFlag)
Expand Down
11 changes: 9 additions & 2 deletions internal/batches/features.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package batches

import (
"fmt"
"log"

"github.com/sourcegraph/sourcegraph/lib/api"
"github.com/sourcegraph/sourcegraph/lib/errors"
)
Expand All @@ -12,7 +15,7 @@ type FeatureFlags struct {
BinaryDiffs bool
}

func (ff *FeatureFlags) SetFromVersion(version string) error {
func (ff *FeatureFlags) SetFromVersion(version string, skipErrors bool) error {
for _, feature := range []struct {
flag *bool
constraint string
Expand All @@ -32,7 +35,11 @@ func (ff *FeatureFlags) SetFromVersion(version string) error {
} {
value, err := api.CheckSourcegraphVersion(version, feature.constraint, feature.minDate)
if err != nil {
return errors.Wrap(err, "failed to check version returned by Sourcegraph")
if skipErrors {
log.Printf("failed to check version returned by Sourcegraph: %s. Assuming no feature flags.", version)
} else {
return errors.Wrap(err, fmt.Sprintf("failed to check version returned by Sourcegraph: %s", version))
}
}
*feature.flag = value
}
Expand Down
4 changes: 2 additions & 2 deletions internal/batches/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (svc *Service) getSourcegraphVersionAndMaxChangesetsCount(ctx context.Conte

// DetermineLicenseAndFeatureFlags returns the enabled features and license restrictions
// configured for the Sourcegraph instance.
func (svc *Service) DetermineLicenseAndFeatureFlags(ctx context.Context) (*batches.LicenseRestrictions, *batches.FeatureFlags, error) {
func (svc *Service) DetermineLicenseAndFeatureFlags(ctx context.Context, skipErrors bool) (*batches.LicenseRestrictions, *batches.FeatureFlags, error) {
version, mc, err := svc.getSourcegraphVersionAndMaxChangesetsCount(ctx)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to query Sourcegraph version and license info for instance")
Expand All @@ -87,7 +87,7 @@ func (svc *Service) DetermineLicenseAndFeatureFlags(ctx context.Context) (*batch
}

ffs := &batches.FeatureFlags{}
return lr, ffs, ffs.SetFromVersion(version)
return lr, ffs, ffs.SetFromVersion(version, skipErrors)

}

Expand Down
Loading