From 25dbfa549983e7a016a67fea3c246885d98a697e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliv=C3=A9r=20Falvai?= Date: Tue, 26 Nov 2024 17:07:37 +0100 Subject: [PATCH] Remove metrics collection option (#109) --- README.md | 1 - main.go | 37 ---- metrics/init.gradle.gotemplate | 26 --- metrics/initscript.go | 46 ---- metrics/initscript_test.go | 85 -------- metrics/metrics.go | 138 ------------ step.yml | 8 - .../github.com/bitrise-io/go-utils/v2/LICENSE | 22 -- .../bitrise-io/go-utils/v2/command/command.go | 198 ------------------ .../go-utils/v2/command/errorcollector.go | 18 -- .../bitrise-io/go-utils/v2/env/env.go | 58 ----- .../go-utils/v2/errorutil/formatted_error.go | 68 ------ .../v2/log/colorstring/colorstring.go | 111 ---------- .../bitrise-io/go-utils/v2/log/log.go | 139 ------------ .../bitrise-io/go-utils/v2/log/severity.go | 35 ---- .../go-utils/v2/pathutil/pathutil.go | 127 ----------- vendor/modules.txt | 6 - 17 files changed, 1123 deletions(-) delete mode 100644 metrics/init.gradle.gotemplate delete mode 100644 metrics/initscript.go delete mode 100644 metrics/initscript_test.go delete mode 100644 metrics/metrics.go delete mode 100644 vendor/github.com/bitrise-io/go-utils/v2/LICENSE delete mode 100644 vendor/github.com/bitrise-io/go-utils/v2/command/command.go delete mode 100644 vendor/github.com/bitrise-io/go-utils/v2/command/errorcollector.go delete mode 100644 vendor/github.com/bitrise-io/go-utils/v2/env/env.go delete mode 100644 vendor/github.com/bitrise-io/go-utils/v2/errorutil/formatted_error.go delete mode 100644 vendor/github.com/bitrise-io/go-utils/v2/log/colorstring/colorstring.go delete mode 100644 vendor/github.com/bitrise-io/go-utils/v2/log/log.go delete mode 100644 vendor/github.com/bitrise-io/go-utils/v2/log/severity.go delete mode 100644 vendor/github.com/bitrise-io/go-utils/v2/pathutil/pathutil.go diff --git a/README.md b/README.md index a3feef7..0737a4a 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,6 @@ You can also set up file path filters to avoid exporting unwanted archives or ma | `mapping_file_exclude_filter` | The Step will **not** copy the generated mapping files that match this filter into the Bitrise deploy directory. You can use this input to avoid moving a beta mapping file, for example. If you specify an empty filter, every mapping file (selected by `mapping_file_include_filter`) will be copied. Example: Do not copy any mapping.txt file that is in a `beta` directoy: ``` */beta/mapping.txt ``` | | `*/tmp/*` | | `cache_level` | `all` - will cache build-cache and dependencies `only_deps` - will cache dependencies only `none` - won't cache any of the above | required | `only_deps` | | `gradle_options` | Flags added to the end of the Gradle call. You can use multiple options, separated by a space. Example: `--stacktrace --debug` If `--debug` or `-d` options are set then only the last 20 lines of the raw gradle output will be visible in the build log. The full raw output will be exported to the `$BITRISE_GRADLE_RAW_RESULT_TEXT_PATH` variable and will be added as a build artifact. | | `--stacktrace` | -| `collect_metrics` | Enable Gradle metrics collection and send data to Bitrise. | | `no` |
diff --git a/main.go b/main.go index e1c9a51..fa08afc 100644 --- a/main.go +++ b/main.go @@ -16,12 +16,6 @@ import ( "github.com/bitrise-io/go-utils/log" "github.com/bitrise-io/go-utils/pathutil" "github.com/bitrise-io/go-utils/retry" - v2command "github.com/bitrise-io/go-utils/v2/command" - "github.com/bitrise-io/go-utils/v2/env" - v2errorutil "github.com/bitrise-io/go-utils/v2/errorutil" - v2log "github.com/bitrise-io/go-utils/v2/log" - v2pathutil "github.com/bitrise-io/go-utils/v2/pathutil" - "github.com/bitrise-steplib/steps-gradle-runner/metrics" "github.com/kballard/go-shellquote" ) @@ -50,9 +44,6 @@ type Config struct { // Other configs DeployDir string `env:"BITRISE_DEPLOY_DIR"` - - // Metrics - CollectMetrics bool `env:"collect_metrics,opt[yes,no]"` } func runGradleTask(gradleTool, buildFile, tasks, options string, destDir string) error { @@ -196,23 +187,6 @@ func main() { failf("Failed to add executable permission on gradlew file (%s): %s", gradlewPath, err) } - // Enable metrics collection - envRepo := env.NewRepository() - cmdFactory := v2command.NewFactory(envRepo) - pathProvider := v2pathutil.NewPathProvider() - logger := v2log.NewLogger() - collector := metrics.NewCollector(envRepo, cmdFactory, pathProvider, logger, gradlewPath, configs.GradleFile) - if configs.CollectMetrics && collector.CanBeEnabled(configs.GradleOptions) { - err = collector.SetupMetricsCollection() - if err == nil { - configs.GradleOptions = collector.UpdateGradleFlagsWithInitScript(configs.GradleOptions) - log.Donef("Metrics collection is set up") - } else { - log.Warnf(v2errorutil.FormattedError(err)) - log.Infof("Continuing task execution without metrics collection") - } - } - gradleStarted := time.Now() log.Infof("Running gradle task...") @@ -405,15 +379,4 @@ func main() { } log.Donef("The mapping path is now available in the Environment Variable: $BITRISE_MAPPING_PATH (value: %s)", lastCopiedMappingFile) } - - if configs.CollectMetrics { - log.Printf("\n") - log.Infof("Sending collected metrics...") - err := collector.SendMetrics() - if err != nil { - log.Warnf(v2errorutil.FormattedError(err)) - } else { - log.Donef("Done") - } - } } diff --git a/metrics/init.gradle.gotemplate b/metrics/init.gradle.gotemplate deleted file mode 100644 index 79a6eda..0000000 --- a/metrics/init.gradle.gotemplate +++ /dev/null @@ -1,26 +0,0 @@ -initscript { - repositories { - maven { - url 'https://plugins.gradle.org/m2/' - } - mavenCentral() - } - dependencies { - classpath 'io.bitrise.gradle:gradle-analytics:{{ .Version }}' - } -} - -rootProject { - apply plugin: io.bitrise.gradle.analytics.AnalyticsPlugin - - analytics { - ignoreErrors = false - bitrise { - remote { - authorization = '{{ .AuthToken }}' - endpoint = '{{ .Endpoint }}' - port = {{ .Port }} - } - } - } -} diff --git a/metrics/initscript.go b/metrics/initscript.go deleted file mode 100644 index d2d3504..0000000 --- a/metrics/initscript.go +++ /dev/null @@ -1,46 +0,0 @@ -package metrics - -import ( - "bytes" - _ "embed" - "fmt" - "text/template" -) - -//go:embed init.gradle.gotemplate -var initTemplate string - -type templateInventory struct { - Version string - Endpoint string - Port int - AuthToken string -} - -func renderTemplate(inventory templateInventory) (string, error) { - if inventory.Version == "" { - return "", fmt.Errorf("version cannot be empty") - } - if inventory.Endpoint == "" { - return "", fmt.Errorf("endpoint cannot be empty") - } - - if inventory.AuthToken == "" { - return "", fmt.Errorf("auth token cannot be empty") - } - - if inventory.Port == 0 { - return "", fmt.Errorf("invalid port number: %d", inventory.Port) - } - - tmpl, err := template.New("init.gradle").Parse(initTemplate) - if err != nil { - return "", fmt.Errorf("invalid template: %w", err) - } - - resultBuffer := bytes.Buffer{} - if err = tmpl.Execute(&resultBuffer, inventory); err != nil { - return "", err - } - return resultBuffer.String(), nil -} diff --git a/metrics/initscript_test.go b/metrics/initscript_test.go deleted file mode 100644 index 07ab2c5..0000000 --- a/metrics/initscript_test.go +++ /dev/null @@ -1,85 +0,0 @@ -package metrics - -import ( - "strings" - "testing" -) - -func Test_renderTemplate(t *testing.T) { - tests := []struct { - name string - inventory templateInventory - want string - wantErr bool - }{ - { - name: "happy path", - inventory: templateInventory{ - Version: "1.+", - Endpoint: "gradle-analytics.services.bitrise.io", - AuthToken: "example_token", - Port: 443, - }, - want: expectedInitScript, - }, - { - name: "invalid endpoint", - inventory: templateInventory{ - Version: "1.0.0", - Endpoint: "", - AuthToken: "example_token", - }, - wantErr: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := renderTemplate(tt.inventory) - if (err != nil) != tt.wantErr { - t.Errorf("renderTemplate() error = %v, wantErr %v", err, tt.wantErr) - return - } - gotTrimmed := trimAllWhitespace(got) - wantTrimmed := trimAllWhitespace(tt.want) - if gotTrimmed != wantTrimmed { - t.Errorf("renderTemplate() got = %v, want %v", gotTrimmed, wantTrimmed) - } - }) - } -} - -func trimAllWhitespace(s string) string { - trimmed := strings.ReplaceAll(s, "\n", "") - trimmed = strings.ReplaceAll(trimmed, "\t", "") - trimmed = strings.ReplaceAll(trimmed, " ", "") - return trimmed -} - -const expectedInitScript = ` -initscript { - repositories { - maven { - url 'https://plugins.gradle.org/m2/' - } - mavenCentral() - } - dependencies { - classpath 'io.bitrise.gradle:gradle-analytics:1.+' - } -} - -rootProject { - apply plugin: io.bitrise.gradle.analytics.AnalyticsPlugin - - analytics { - ignoreErrors = false - bitrise { - remote { - authorization = 'example_token' - endpoint = 'gradle-analytics.services.bitrise.io' - port = 443 - } - } - } -} -` diff --git a/metrics/metrics.go b/metrics/metrics.go deleted file mode 100644 index 4833b86..0000000 --- a/metrics/metrics.go +++ /dev/null @@ -1,138 +0,0 @@ -package metrics - -import ( - "fmt" - "os" - "path" - "strings" - - "github.com/bitrise-io/go-utils/v2/command" - "github.com/bitrise-io/go-utils/v2/env" - "github.com/bitrise-io/go-utils/v2/log" - "github.com/bitrise-io/go-utils/v2/pathutil" -) - -const defaultEndpoint = "gradle-analytics.services.bitrise.io" -const defaultPort = 443 - -// Sync the major version of this step and the plugin. -// Use the latest 1.x version of the plugin, so we don't have to update this definition after every plugin release. -// But don't forget to update this to `2.+` if the library reaches version 2.0! -const defaultPluginVersion = "0.+" // TODO: change to 1.+ - -type Collector struct { - envRepo env.Repository - cmdFactory command.Factory - pathProvider pathutil.PathProvider - logger log.Logger - gradlewPath string - buildFilePath string - - initScriptPath string -} - -func NewCollector( - envRepo env.Repository, - cmdFactory command.Factory, - pathProvider pathutil.PathProvider, - logger log.Logger, - gradlewPath string, - buildFilePath string, -) Collector { - return Collector{ - envRepo: envRepo, - cmdFactory: cmdFactory, - pathProvider: pathProvider, - logger: logger, - gradlewPath: gradlewPath, - buildFilePath: buildFilePath, - } -} - -func (c *Collector) CanBeEnabled(gradleFlags string) bool { - initScriptDefined := strings.Contains(gradleFlags, "--init-script") - if initScriptDefined { - c.logger.Warnf("An init script is already defined via the additional Gradle flags step input. Metrics collection will be disabled.") - } - return !initScriptDefined -} - -func (c *Collector) SetupMetricsCollection() error { - authToken := c.envRepo.Get("BITRISEIO_BITRISE_SERVICES_ACCESS_TOKEN") - if authToken == "" { - return fmt.Errorf("$BITRISEIO_BITRISE_SERVICES_ACCESS_TOKEN is empty. This step is only supposed to run in Bitrise CI builds") - } - - return c.createInitScript(authToken) -} - -func (c *Collector) UpdateGradleFlagsWithInitScript(gradleFlags string) string { - if c.initScriptPath == "" { - return gradleFlags - } - - return fmt.Sprintf("%s --init-script %s", gradleFlags, c.initScriptPath) -} - -func (c *Collector) SendMetrics() error { - if c.initScriptPath == "" { - return fmt.Errorf("init script path is empty, this can't run without an existing init script") - } - - if err := c.runGradleTask(c.initScriptPath); err != nil { - return err - } - - return nil -} - -func (c *Collector) runGradleTask(initScriptPath string) error { - args := []string{ - "producer", - "--init-script", initScriptPath, - } - if c.buildFilePath != "" { - args = append(args, "--build-file", c.buildFilePath) - } - - opts := command.Opts{ - Stdout: os.Stdout, - Stderr: os.Stderr, - } - cmd := c.cmdFactory.Create(c.gradlewPath, args, &opts) - err := cmd.Run() - if err != nil { - c.logger.Warnf("Failed to run Gradle task: %s", err) - } - return nil -} - -func (c *Collector) createInitScript(authToken string) error { - inventory := templateInventory{ - Endpoint: defaultEndpoint, - Port: defaultPort, - Version: defaultPluginVersion, - AuthToken: authToken, - } - scriptContent, err := renderTemplate(inventory) - if err != nil { - return fmt.Errorf("failed to create init script contents: %w", err) - } - - dir, err := c.pathProvider.CreateTempDir("gradle-runner") - if err != nil { - return fmt.Errorf("failed to create temp dir for init script: %w", err) - } - initPath := path.Join(dir, "init-analytics.gradle") - if err != nil { - return fmt.Errorf("failed to create temp file for init script: %w", err) - } - - err = os.WriteFile(initPath, []byte(scriptContent), 0755) - if err != nil { - return err - } - - c.initScriptPath = initPath - return nil -} diff --git a/step.yml b/step.yml index 323c276..1f027e4 100644 --- a/step.yml +++ b/step.yml @@ -210,14 +210,6 @@ inputs: You can use multiple options, separated by a space. Example: `--stacktrace --debug` If `--debug` or `-d` options are set then only the last 20 lines of the raw gradle output will be visible in the build log. The full raw output will be exported to the `$BITRISE_GRADLE_RAW_RESULT_TEXT_PATH` variable and will be added as a build artifact. -- collect_metrics: "no" - opts: - title: Collect Gradle metrics - description: | - Enable Gradle metrics collection and send data to Bitrise. - value_options: - - "yes" - - "no" outputs: - BITRISE_APK_PATH: opts: diff --git a/vendor/github.com/bitrise-io/go-utils/v2/LICENSE b/vendor/github.com/bitrise-io/go-utils/v2/LICENSE deleted file mode 100644 index a6a5c39..0000000 --- a/vendor/github.com/bitrise-io/go-utils/v2/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Bitrise - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - diff --git a/vendor/github.com/bitrise-io/go-utils/v2/command/command.go b/vendor/github.com/bitrise-io/go-utils/v2/command/command.go deleted file mode 100644 index 4206c2b..0000000 --- a/vendor/github.com/bitrise-io/go-utils/v2/command/command.go +++ /dev/null @@ -1,198 +0,0 @@ -package command - -import ( - "errors" - "fmt" - "io" - "os/exec" - "strconv" - "strings" - - "github.com/bitrise-io/go-utils/v2/env" -) - -// ErrorFinder ... -type ErrorFinder func(out string) []string - -// Opts ... -type Opts struct { - Stdout io.Writer - Stderr io.Writer - Stdin io.Reader - Env []string - Dir string - ErrorFinder ErrorFinder -} - -// Factory ... -type Factory interface { - Create(name string, args []string, opts *Opts) Command -} - -type factory struct { - envRepository env.Repository -} - -// NewFactory ... -func NewFactory(envRepository env.Repository) Factory { - return factory{envRepository: envRepository} -} - -// Create ... -func (f factory) Create(name string, args []string, opts *Opts) Command { - cmd := exec.Command(name, args...) - var collector *errorCollector - - if opts != nil { - if opts.ErrorFinder != nil { - collector = &errorCollector{errorFinder: opts.ErrorFinder} - } - - cmd.Stdout = opts.Stdout - cmd.Stderr = opts.Stderr - cmd.Stdin = opts.Stdin - - // If Env is nil, the new process uses the current process's - // environment. - // If we pass env vars we want to append them to the - // current process's environment. - cmd.Env = append(f.envRepository.List(), opts.Env...) - cmd.Dir = opts.Dir - } - return &command{ - cmd: cmd, - errorCollector: collector, - } -} - -// Command ... -type Command interface { - PrintableCommandArgs() string - Run() error - RunAndReturnExitCode() (int, error) - RunAndReturnTrimmedOutput() (string, error) - RunAndReturnTrimmedCombinedOutput() (string, error) - Start() error - Wait() error -} - -type command struct { - cmd *exec.Cmd - errorCollector *errorCollector -} - -// PrintableCommandArgs ... -func (c command) PrintableCommandArgs() string { - return printableCommandArgs(false, c.cmd.Args) -} - -// Run ... -func (c *command) Run() error { - c.wrapOutputs() - - if err := c.cmd.Run(); err != nil { - return c.wrapError(err) - } - - return nil -} - -// RunAndReturnExitCode ... -func (c command) RunAndReturnExitCode() (int, error) { - c.wrapOutputs() - err := c.cmd.Run() - if err != nil { - err = c.wrapError(err) - } - - exitCode := c.cmd.ProcessState.ExitCode() - return exitCode, err -} - -// RunAndReturnTrimmedOutput ... -func (c command) RunAndReturnTrimmedOutput() (string, error) { - outBytes, err := c.cmd.Output() - outStr := string(outBytes) - if err != nil { - if c.errorCollector != nil { - c.errorCollector.collectErrors(outStr) - } - err = c.wrapError(err) - } - - return strings.TrimSpace(outStr), err -} - -// RunAndReturnTrimmedCombinedOutput ... -func (c command) RunAndReturnTrimmedCombinedOutput() (string, error) { - outBytes, err := c.cmd.CombinedOutput() - outStr := string(outBytes) - if err != nil { - if c.errorCollector != nil { - c.errorCollector.collectErrors(outStr) - } - err = c.wrapError(err) - } - - return strings.TrimSpace(outStr), err -} - -// Start ... -func (c command) Start() error { - c.wrapOutputs() - return c.cmd.Start() -} - -// Wait ... -func (c command) Wait() error { - err := c.cmd.Wait() - if err != nil { - err = c.wrapError(err) - } - - return err -} - -func printableCommandArgs(isQuoteFirst bool, fullCommandArgs []string) string { - var cmdArgsDecorated []string - for idx, anArg := range fullCommandArgs { - quotedArg := strconv.Quote(anArg) - if idx == 0 && !isQuoteFirst { - quotedArg = anArg - } - cmdArgsDecorated = append(cmdArgsDecorated, quotedArg) - } - - return strings.Join(cmdArgsDecorated, " ") -} - -func (c command) wrapError(err error) error { - var exitErr *exec.ExitError - if errors.As(err, &exitErr) { - if c.errorCollector != nil && len(c.errorCollector.errorLines) > 0 { - return fmt.Errorf("command failed with exit status %d (%s): %w", exitErr.ExitCode(), c.PrintableCommandArgs(), errors.New(strings.Join(c.errorCollector.errorLines, "\n"))) - } - return fmt.Errorf("command failed with exit status %d (%s): %w", exitErr.ExitCode(), c.PrintableCommandArgs(), errors.New("check the command's output for details")) - } - return fmt.Errorf("executing command failed (%s): %w", c.PrintableCommandArgs(), err) -} - -func (c command) wrapOutputs() { - if c.errorCollector == nil { - return - } - - if c.cmd.Stdout != nil { - outWriter := io.MultiWriter(c.errorCollector, c.cmd.Stdout) - c.cmd.Stdout = outWriter - } else { - c.cmd.Stdout = c.errorCollector - } - - if c.cmd.Stderr != nil { - errWriter := io.MultiWriter(c.errorCollector, c.cmd.Stderr) - c.cmd.Stderr = errWriter - } else { - c.cmd.Stderr = c.errorCollector - } -} diff --git a/vendor/github.com/bitrise-io/go-utils/v2/command/errorcollector.go b/vendor/github.com/bitrise-io/go-utils/v2/command/errorcollector.go deleted file mode 100644 index 945e3ff..0000000 --- a/vendor/github.com/bitrise-io/go-utils/v2/command/errorcollector.go +++ /dev/null @@ -1,18 +0,0 @@ -package command - -type errorCollector struct { - errorLines []string - errorFinder ErrorFinder -} - -func (e *errorCollector) Write(p []byte) (n int, err error) { - e.collectErrors(string(p)) - return len(p), nil -} - -func (e *errorCollector) collectErrors(output string) { - lines := e.errorFinder(output) - if len(lines) > 0 { - e.errorLines = append(e.errorLines, lines...) - } -} diff --git a/vendor/github.com/bitrise-io/go-utils/v2/env/env.go b/vendor/github.com/bitrise-io/go-utils/v2/env/env.go deleted file mode 100644 index 85cf1ae..0000000 --- a/vendor/github.com/bitrise-io/go-utils/v2/env/env.go +++ /dev/null @@ -1,58 +0,0 @@ -package env - -import ( - "os" - "os/exec" -) - -// CommandLocator ... -type CommandLocator interface { - LookPath(file string) (string, error) -} - -type commandLocator struct{} - -// NewCommandLocator ... -func NewCommandLocator() CommandLocator { - return commandLocator{} -} - -// LookPath ... -func (l commandLocator) LookPath(file string) (string, error) { - return exec.LookPath(file) -} - -// Repository ... -type Repository interface { - List() []string - Unset(key string) error - Get(key string) string - Set(key, value string) error -} - -// NewRepository ... -func NewRepository() Repository { - return repository{} -} - -type repository struct{} - -// Get ... -func (d repository) Get(key string) string { - return os.Getenv(key) -} - -// Set ... -func (d repository) Set(key, value string) error { - return os.Setenv(key, value) -} - -// Unset ... -func (d repository) Unset(key string) error { - return os.Unsetenv(key) -} - -// List ... -func (d repository) List() []string { - return os.Environ() -} diff --git a/vendor/github.com/bitrise-io/go-utils/v2/errorutil/formatted_error.go b/vendor/github.com/bitrise-io/go-utils/v2/errorutil/formatted_error.go deleted file mode 100644 index 842c74b..0000000 --- a/vendor/github.com/bitrise-io/go-utils/v2/errorutil/formatted_error.go +++ /dev/null @@ -1,68 +0,0 @@ -package errorutil - -import ( - "errors" - "strings" -) - -// FormattedError ... -func FormattedError(err error) string { - var formatted string - - i := -1 - for { - i++ - - reason := err.Error() - - if err = errors.Unwrap(err); err == nil { - formatted = appendError(formatted, reason, i, true) - return formatted - } - - reason = strings.TrimSuffix(reason, err.Error()) - reason = strings.TrimRight(reason, " ") - reason = strings.TrimSuffix(reason, ":") - - formatted = appendError(formatted, reason, i, false) - } -} - -func appendError(errorMessage, reason string, i int, last bool) string { - if i == 0 { - errorMessage = indentedReason(reason, i) - } else { - errorMessage += "\n" - errorMessage += indentedReason(reason, i) - } - - if !last { - errorMessage += ":" - } - - return errorMessage -} - -func indentedReason(reason string, level int) string { - var lines []string - split := strings.Split(reason, "\n") - for _, line := range split { - line = strings.TrimLeft(line, " ") - line = strings.TrimRight(line, "\n") - line = strings.TrimRight(line, " ") - if line == "" { - continue - } - lines = append(lines, line) - } - - var indented string - for i, line := range lines { - indented += strings.Repeat(" ", level) - indented += line - if i != len(lines)-1 { - indented += "\n" - } - } - return indented -} diff --git a/vendor/github.com/bitrise-io/go-utils/v2/log/colorstring/colorstring.go b/vendor/github.com/bitrise-io/go-utils/v2/log/colorstring/colorstring.go deleted file mode 100644 index 5401b91..0000000 --- a/vendor/github.com/bitrise-io/go-utils/v2/log/colorstring/colorstring.go +++ /dev/null @@ -1,111 +0,0 @@ -package colorstring - -// ANSI color escape sequences - -import ( - "fmt" -) - -// Color ... -type Color string - -const ( - blackColor Color = "\x1b[30;1m" - redColor Color = "\x1b[31;1m" - greenColor Color = "\x1b[32;1m" - yellowColor Color = "\x1b[33;1m" - blueColor Color = "\x1b[34;1m" - magentaColor Color = "\x1b[35;1m" - cyanColor Color = "\x1b[36;1m" - resetColor Color = "\x1b[0m" -) - -// ColorFunc ... -type ColorFunc func(a ...interface{}) string - -func addColor(color Color, msg string) string { - return string(color) + msg + string(resetColor) -} - -// NoColor ... -func NoColor(a ...interface{}) string { - return fmt.Sprint(a...) -} - -// Black ... -func Black(a ...interface{}) string { - return addColor(blackColor, fmt.Sprint(a...)) -} - -// Red ... -func Red(a ...interface{}) string { - return addColor(redColor, fmt.Sprint(a...)) -} - -// Green ... -func Green(a ...interface{}) string { - return addColor(greenColor, fmt.Sprint(a...)) -} - -// Yellow ... -func Yellow(a ...interface{}) string { - return addColor(yellowColor, fmt.Sprint(a...)) -} - -// Blue ... -func Blue(a ...interface{}) string { - return addColor(blueColor, fmt.Sprint(a...)) -} - -// Magenta ... -func Magenta(a ...interface{}) string { - return addColor(magentaColor, fmt.Sprint(a...)) -} - -// Cyan ... -func Cyan(a ...interface{}) string { - return addColor(cyanColor, fmt.Sprint(a...)) -} - -// ColorfFunc ... -type ColorfFunc func(format string, a ...interface{}) string - -// NoColorf ... -func NoColorf(format string, a ...interface{}) string { - return NoColor(fmt.Sprintf(format, a...)) -} - -// Blackf ... -func Blackf(format string, a ...interface{}) string { - return Black(fmt.Sprintf(format, a...)) -} - -// Redf ... -func Redf(format string, a ...interface{}) string { - return Red(fmt.Sprintf(format, a...)) -} - -// Greenf ... -func Greenf(format string, a ...interface{}) string { - return Green(fmt.Sprintf(format, a...)) -} - -// Yellowf ... -func Yellowf(format string, a ...interface{}) string { - return Yellow(fmt.Sprintf(format, a...)) -} - -// Bluef ... -func Bluef(format string, a ...interface{}) string { - return Blue(fmt.Sprintf(format, a...)) -} - -// Magentaf ... -func Magentaf(format string, a ...interface{}) string { - return Magenta(fmt.Sprintf(format, a...)) -} - -// Cyanf ... -func Cyanf(format string, a ...interface{}) string { - return Cyan(fmt.Sprintf(format, a...)) -} diff --git a/vendor/github.com/bitrise-io/go-utils/v2/log/log.go b/vendor/github.com/bitrise-io/go-utils/v2/log/log.go deleted file mode 100644 index 0c77db9..0000000 --- a/vendor/github.com/bitrise-io/go-utils/v2/log/log.go +++ /dev/null @@ -1,139 +0,0 @@ -package log - -import ( - "fmt" - "io" - "os" - "time" -) - -// Logger ... -type Logger interface { - Infof(format string, v ...interface{}) - Warnf(format string, v ...interface{}) - Printf(format string, v ...interface{}) - Donef(format string, v ...interface{}) - Debugf(format string, v ...interface{}) - Errorf(format string, v ...interface{}) - TInfof(format string, v ...interface{}) - TWarnf(format string, v ...interface{}) - TPrintf(format string, v ...interface{}) - TDonef(format string, v ...interface{}) - TDebugf(format string, v ...interface{}) - TErrorf(format string, v ...interface{}) - Println() - EnableDebugLog(enable bool) -} - -const defaultTimeStampLayout = "15:04:05" - -type logger struct { - enableDebugLog bool - timestampLayout string - stdout io.Writer -} - -// NewLogger ... -func NewLogger() Logger { - return &logger{enableDebugLog: false, timestampLayout: defaultTimeStampLayout, stdout: os.Stdout} -} - -// EnableDebugLog ... -func (l *logger) EnableDebugLog(enable bool) { - l.enableDebugLog = enable -} - -// Infof ... -func (l *logger) Infof(format string, v ...interface{}) { - l.printf(infoSeverity, false, format, v...) -} - -// Warnf ... -func (l *logger) Warnf(format string, v ...interface{}) { - l.printf(warnSeverity, false, format, v...) -} - -// Printf ... -func (l *logger) Printf(format string, v ...interface{}) { - l.printf(normalSeverity, false, format, v...) -} - -// Donef ... -func (l *logger) Donef(format string, v ...interface{}) { - l.printf(doneSeverity, false, format, v...) -} - -// Debugf ... -func (l *logger) Debugf(format string, v ...interface{}) { - if l.enableDebugLog { - l.printf(debugSeverity, false, format, v...) - } -} - -// Errorf ... -func (l *logger) Errorf(format string, v ...interface{}) { - l.printf(errorSeverity, false, format, v...) -} - -// TInfof ... -func (l *logger) TInfof(format string, v ...interface{}) { - l.printf(infoSeverity, true, format, v...) -} - -// TWarnf ... -func (l *logger) TWarnf(format string, v ...interface{}) { - l.printf(warnSeverity, true, format, v...) -} - -// TPrintf ... -func (l *logger) TPrintf(format string, v ...interface{}) { - l.printf(normalSeverity, true, format, v...) -} - -// TDonef ... -func (l *logger) TDonef(format string, v ...interface{}) { - l.printf(doneSeverity, true, format, v...) -} - -// TDebugf ... -func (l *logger) TDebugf(format string, v ...interface{}) { - if l.enableDebugLog { - l.printf(debugSeverity, true, format, v...) - } -} - -// TErrorf ... -func (l *logger) TErrorf(format string, v ...interface{}) { - l.printf(errorSeverity, true, format, v...) -} - -// Println ... -func (l *logger) Println() { - fmt.Println() -} - -func (l *logger) timestampField() string { - currentTime := time.Now() - return fmt.Sprintf("[%s]", currentTime.Format(l.timestampLayout)) -} - -func (l *logger) prefixCurrentTime(message string) string { - return fmt.Sprintf("%s %s", l.timestampField(), message) -} - -func (l *logger) createLogMsg(severity Severity, withTime bool, format string, v ...interface{}) string { - colorFunc := severityColorFuncMap[severity] - message := colorFunc(format, v...) - if withTime { - message = l.prefixCurrentTime(message) - } - - return message -} - -func (l *logger) printf(severity Severity, withTime bool, format string, v ...interface{}) { - message := l.createLogMsg(severity, withTime, format, v...) - if _, err := fmt.Fprintln(l.stdout, message); err != nil { - fmt.Printf("failed to print message: %s, error: %s\n", message, err) - } -} diff --git a/vendor/github.com/bitrise-io/go-utils/v2/log/severity.go b/vendor/github.com/bitrise-io/go-utils/v2/log/severity.go deleted file mode 100644 index 02a1431..0000000 --- a/vendor/github.com/bitrise-io/go-utils/v2/log/severity.go +++ /dev/null @@ -1,35 +0,0 @@ -package log - -import "github.com/bitrise-io/go-utils/v2/log/colorstring" - -// Severity ... -type Severity uint8 - -const ( - errorSeverity Severity = iota - warnSeverity - normalSeverity - infoSeverity - doneSeverity - debugSeverity -) - -type severityColorFunc colorstring.ColorfFunc - -var ( - doneSeverityColorFunc severityColorFunc = colorstring.Greenf - infoSeverityColorFunc severityColorFunc = colorstring.Bluef - normalSeverityColorFunc severityColorFunc = colorstring.NoColorf - debugSeverityColorFunc severityColorFunc = colorstring.Magentaf - warnSeverityColorFunc severityColorFunc = colorstring.Yellowf - errorSeverityColorFunc severityColorFunc = colorstring.Redf -) - -var severityColorFuncMap = map[Severity]severityColorFunc{ - doneSeverity: doneSeverityColorFunc, - infoSeverity: infoSeverityColorFunc, - normalSeverity: normalSeverityColorFunc, - debugSeverity: debugSeverityColorFunc, - warnSeverity: warnSeverityColorFunc, - errorSeverity: errorSeverityColorFunc, -} diff --git a/vendor/github.com/bitrise-io/go-utils/v2/pathutil/pathutil.go b/vendor/github.com/bitrise-io/go-utils/v2/pathutil/pathutil.go deleted file mode 100644 index f173693..0000000 --- a/vendor/github.com/bitrise-io/go-utils/v2/pathutil/pathutil.go +++ /dev/null @@ -1,127 +0,0 @@ -package pathutil - -import ( - "errors" - "os" - "os/user" - "path/filepath" - "strings" -) - -// PathProvider ... -type PathProvider interface { - CreateTempDir(prefix string) (string, error) -} - -type pathProvider struct{} - -// NewPathProvider ... -func NewPathProvider() PathProvider { - return pathProvider{} -} - -// CreateTempDir creates a temp dir, and returns its path. -// If prefix is provided it'll be used as the tmp dir's name prefix. -// Normalized: it's guaranteed that the path won't end with '/'. -func (pathProvider) CreateTempDir(prefix string) (dir string, err error) { - dir, err = os.MkdirTemp("", prefix) - dir = strings.TrimSuffix(dir, "/") - - return -} - -// PathChecker ... -type PathChecker interface { - IsPathExists(pth string) (bool, error) - IsDirExists(pth string) (bool, error) -} - -type pathChecker struct{} - -// NewPathChecker ... -func NewPathChecker() PathChecker { - return pathChecker{} -} - -// IsPathExists ... -func (c pathChecker) IsPathExists(pth string) (bool, error) { - _, isExists, err := c.genericIsPathExists(pth) - return isExists, err -} - -// IsDirExists ... -func (c pathChecker) IsDirExists(pth string) (bool, error) { - info, isExists, err := c.genericIsPathExists(pth) - return isExists && info.IsDir(), err -} - -func (pathChecker) genericIsPathExists(pth string) (os.FileInfo, bool, error) { - if pth == "" { - return nil, false, errors.New("no path provided") - } - - fileInf, err := os.Lstat(pth) - if err == nil { - return fileInf, true, nil - } - - if os.IsNotExist(err) { - return nil, false, nil - } - - return fileInf, false, err -} - -// PathModifier ... -type PathModifier interface { - AbsPath(pth string) (string, error) -} - -type pathModifier struct{} - -// NewPathModifier ... -func NewPathModifier() PathModifier { - return pathModifier{} -} - -// AbsPath expands ENV vars and the ~ character then calls Go's Abs -func (p pathModifier) AbsPath(pth string) (string, error) { - if pth == "" { - return "", errors.New("No Path provided") - } - - pth, err := p.expandTilde(pth) - if err != nil { - return "", err - } - - return filepath.Abs(os.ExpandEnv(pth)) -} - -func (pathModifier) expandTilde(pth string) (string, error) { - if pth == "" { - return "", errors.New("No Path provided") - } - - if strings.HasPrefix(pth, "~") { - pth = strings.TrimPrefix(pth, "~") - - if len(pth) == 0 || strings.HasPrefix(pth, "/") { - return os.ExpandEnv("$HOME" + pth), nil - } - - splitPth := strings.Split(pth, "/") - username := splitPth[0] - - usr, err := user.Lookup(username) - if err != nil { - return "", err - } - - pathInUsrHome := strings.Join(splitPth[1:], "/") - - return filepath.Join(usr.HomeDir, pathInUsrHome), nil - } - - return pth, nil -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 1a75d5b..1fbfe4e 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -23,12 +23,6 @@ github.com/bitrise-io/go-utils/stringutil github.com/bitrise-io/go-utils/ziputil # github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.16 ## explicit; go 1.17 -github.com/bitrise-io/go-utils/v2/command -github.com/bitrise-io/go-utils/v2/env -github.com/bitrise-io/go-utils/v2/errorutil -github.com/bitrise-io/go-utils/v2/log -github.com/bitrise-io/go-utils/v2/log/colorstring -github.com/bitrise-io/go-utils/v2/pathutil # github.com/hashicorp/go-cleanhttp v0.5.2 ## explicit; go 1.13 github.com/hashicorp/go-cleanhttp