forked from bitrise-steplib/bitrise-step-flutter-analyze
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
executable file
·68 lines (56 loc) · 1.52 KB
/
main.go
File metadata and controls
executable file
·68 lines (56 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"bytes"
"fmt"
"io"
"os"
"regexp"
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-tools/go-steputils/stepconf"
shellquote "github.com/kballard/go-shellquote"
)
type config struct {
AdditionalParams string `env:"additional_params"`
ProjectLocation string `env:"project_location,dir"`
}
func failf(msg string, args ...interface{}) {
log.Errorf(msg, args...)
os.Exit(1)
}
func hasAnalyzeError(cmdOutput string) bool {
// example: error • Undefined class 'function' • lib/package.dart:3:1 • undefined_class
analyzeErrorPattern := regexp.MustCompile(`error.+\.dart:\d+:\d+`)
if analyzeErrorPattern.MatchString(cmdOutput) {
return true
}
return false
}
func main() {
var cfg config
if err := stepconf.Parse(&cfg); err != nil {
failf("Issue with input: %s", err)
}
stepconf.Print(cfg)
additionalParams, err := shellquote.Split(cfg.AdditionalParams)
if err != nil {
failf("Failed to parse additional parameters, error: %s", err)
}
fmt.Println()
log.Infof("Running analyze")
var b bytes.Buffer
multiwr := io.MultiWriter(os.Stdout, &b)
analyzeCmd := command.New("flutter", append([]string{"analyze"}, additionalParams...)...).
SetDir(cfg.ProjectLocation).
SetStdout(multiwr).
SetStderr(os.Stderr)
fmt.Println()
log.Donef("$ %s", analyzeCmd.PrintableCommandArgs())
fmt.Println()
if err := analyzeCmd.Run(); err != nil {
if hasAnalyzeError(b.String()) {
log.Errorf("flutter analyze found errors: %s", err)
os.Exit(1)
}
}
}