Skip to content

Commit

Permalink
Respect additional Gradle flags in every Gradle call (#33)
Browse files Browse the repository at this point in the history
* Respect additional Gradle flags in every Gradle call

* Fix import

* Commit missing vendor file
  • Loading branch information
ofalvai authored Nov 9, 2021
1 parent 2a6ccc4 commit ca14557
Show file tree
Hide file tree
Showing 31 changed files with 716 additions and 718 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.bitrise*
_tmp
_tmp
.idea/
1 change: 1 addition & 0 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ workflows:
title: Android Unit Test (monorepo projects in source dir)
inputs:
- is_debug: "true"
- arguments: --warn
after-run:
- check-artifacts

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/bitrise-steplib/bitrise-step-android-unit-test
go 1.16

require (
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1
github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5
github.com/bitrise-io/go-android v0.0.0-20211022134605-85247bb2c5c6
github.com/bitrise-io/go-steputils v0.0.0-20210819160244-b3962254d553
github.com/bitrise-io/go-utils v0.0.0-20211008161027-fa11986847a0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e h1:lkJnz+yXbIqFGpDTdRBBshqxeX0UCndJmEOp0yy2GRQ=
github.com/bitrise-io/go-android v0.0.0-20210527143215-3ad22ad02e2e/go.mod h1:gGXmY8hJ1x44AC98TIvZZvxP7o+hs4VI6wgmO4JMfEg=
github.com/bitrise-io/go-android v0.0.0-20211022134605-85247bb2c5c6 h1:WJQ7dvHP7/ZtS9qw/Ng+/eh+5MPOVVKDrjjrDNiWlwA=
github.com/bitrise-io/go-android v0.0.0-20211022134605-85247bb2c5c6/go.mod h1:yTe4i6RfahvAmOChFrS9uCPmJiH0eBEV4jya30v2tTc=
github.com/bitrise-io/go-steputils v0.0.0-20210514150206-5b6261447e77/go.mod h1:H0iZjgsAR5NA6pnlD/zKB6AbxEsskq55pwJ9klVmP8w=
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1 h1:gi29hTdxGXAGQvZckPZ9V8BAEfP3eK/tiZgTC5s6h1c=
github.com/bitrise-io/go-steputils v0.0.0-20210527075147-910ce7a105a1/go.mod h1:H0iZjgsAR5NA6pnlD/zKB6AbxEsskq55pwJ9klVmP8w=
github.com/bitrise-io/go-steputils v0.0.0-20210819160244-b3962254d553 h1:W8LE5et6SN8pHIKJ3+oy6IHWzLVwL55nCAN05vDkwQo=
github.com/bitrise-io/go-steputils v0.0.0-20210819160244-b3962254d553/go.mod h1:gPr5wQVOi3wZCY1RkMzk/Ij0rmdgEIP0Og84YgHmVSU=
github.com/bitrise-io/go-utils v0.0.0-20210507100250-37de47dfa6ce/go.mod h1:15EZZf02noI5nWFqXMZEoyb1CyqYRXTMz5Fyu4CWFzI=
github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5 h1:kclxBfygfNK6kWUB+9xcsfPLBen8Us9gubhitfL/Z6c=
github.com/bitrise-io/go-utils v0.0.0-20210520073355-367fa34178f5/go.mod h1:DRx7oFuAqk0dbKpAKCqWl0TgrowfJUb/MqYPRscxJOQ=
github.com/bitrise-io/go-utils v0.0.0-20210819105546-07a5bda18d68/go.mod h1:UprBoSn6HxcN9G7yGRSOoe9bSZLh7gLl4yA0/iqwYsI=
github.com/bitrise-io/go-utils v0.0.0-20210819143908-bbd923881fab h1:G9dwybvZJ8k2F55ntjQq/nZsZ6+nqvTzwIDjVLzpueA=
github.com/bitrise-io/go-utils v0.0.0-20210819143908-bbd923881fab/go.mod h1:UprBoSn6HxcN9G7yGRSOoe9bSZLh7gLl4yA0/iqwYsI=
github.com/bitrise-io/go-utils v0.0.0-20211008161027-fa11986847a0 h1:fT81H9m8GHazqZ0WsVq7GE5DfK4xSyXnHGJKyita2BM=
github.com/bitrise-io/go-utils v0.0.0-20211008161027-fa11986847a0/go.mod h1:Vi4MHnaZVL3PVoPPA/Yp6g2pzntkDH8LGiRSY7qw6KQ=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw=
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
Expand All @@ -30,15 +40,19 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210819072135-bce67f096156/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
71 changes: 38 additions & 33 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import (
"github.com/bitrise-io/go-android/gradle"
utilscache "github.com/bitrise-io/go-steputils/cache"
"github.com/bitrise-io/go-steputils/stepconf"
"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/env"
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-io/go-utils/pathutil"
"github.com/bitrise-io/go-utils/sliceutil"
"github.com/bitrise-steplib/bitrise-step-android-unit-test/testaddon"
shellquote "github.com/kballard/go-shellquote"
"github.com/kballard/go-shellquote"
)

// Configs ...
Expand All @@ -34,8 +36,11 @@ type Configs struct {
TestResultDir string `env:"BITRISE_TEST_RESULT_DIR"`
}

var cmdFactory = command.NewFactory(env.NewRepository())
var logger = log.NewLogger()

func failf(f string, args ...interface{}) {
log.Errorf(f, args...)
logger.Errorf(f, args...)
os.Exit(1)
}

Expand All @@ -51,13 +56,13 @@ func getArtifacts(gradleProject gradle.Project, started time.Time, pattern strin
}
if len(artifacts) == 0 {
if t == started {
log.Warnf("No artifacts found with pattern: %s that has modification time after: %s", pattern, t)
log.Warnf("Retrying without modtime check....")
logger.Warnf("No artifacts found with pattern: %s that has modification time after: %s", pattern, t)
logger.Warnf("Retrying without modtime check....")
fmt.Println()
continue
}
log.Warnf("No artifacts found with pattern: %s without modtime check", pattern)
log.Warnf("If you have changed default report export path in your gradle files then you might need to change ReportPathPattern accordingly.")
logger.Warnf("No artifacts found with pattern: %s without modtime check", pattern)
logger.Warnf("If you have changed default report export path in your gradle files then you might need to change ReportPathPattern accordingly.")
}
}
return
Expand Down Expand Up @@ -89,10 +94,10 @@ func exportArtifacts(deployDir string, artifacts []gradle.Artifact) error {
src = "./" + rel
}

log.Printf(" Export [ %s => $BITRISE_DEPLOY_DIR/%s ]", src, artifact.Name)
logger.Printf(" Export [ %s => $BITRISE_DEPLOY_DIR/%s ]", src, artifact.Name)

if err := artifact.ExportZIP(deployDir); err != nil {
log.Warnf("failed to export artifact (%s), error: %v", artifact.Path, err)
logger.Warnf("failed to export artifact (%s), error: %v", artifact.Path, err)
continue
}
}
Expand Down Expand Up @@ -139,13 +144,13 @@ func tryExportTestAddonArtifact(artifactPth, outputDir string, lastOtherDirIdx i
}

if err := testaddon.ExportArtifact(artifactPth, outputDir, dir); err != nil {
log.Warnf("Failed to export test results for test addon: %s", err)
logger.Warnf("Failed to export test results for test addon: %s", err)
} else {
src := artifactPth
if rel, err := workDirRel(artifactPth); err == nil {
src = "./" + rel
}
log.Printf(" Export [%s => %s]", src, filepath.Join("$BITRISE_TEST_RESULT_DIR", dir, filepath.Base(artifactPth)))
logger.Printf(" Export [%s => %s]", src, filepath.Join("$BITRISE_TEST_RESULT_DIR", dir, filepath.Base(artifactPth)))
}
return lastOtherDirIdx
}
Expand All @@ -160,19 +165,24 @@ func main() {
stepconf.Print(config)
fmt.Println()

log.SetEnableDebugLog(config.IsDebug)
logger.EnableDebugLog(config.IsDebug)

gradleProject, err := gradle.NewProject(config.ProjectLocation)
gradleProject, err := gradle.NewProject(config.ProjectLocation, cmdFactory)
if err != nil {
failf("Failed to open project, error: %s", err)
}

testTask := gradleProject.GetTask("test")

log.Infof("Variants:")
args, err := shellquote.Split(config.Arguments)
if err != nil {
failf("Failed to parse arguments, error: %s", err)
}

logger.Infof("Variants:")
fmt.Println()

variants, err := testTask.GetVariants()
variants, err := testTask.GetVariants(args...)
if err != nil {
failf("Failed to fetch variants, error: %s", err)
}
Expand All @@ -183,39 +193,34 @@ func main() {
}

for module, variants := range variants {
log.Printf("%s:", module)
logger.Printf("%s:", module)
for _, variant := range variants {
if sliceutil.IsStringInSlice(variant, filteredVariants[module]) {
log.Donef("✓ %s", strings.TrimSuffix(variant, "UnitTest"))
logger.Donef("✓ %s", strings.TrimSuffix(variant, "UnitTest"))
} else {
log.Printf("- %s", strings.TrimSuffix(variant, "UnitTest"))
logger.Printf("- %s", strings.TrimSuffix(variant, "UnitTest"))
}
}
}
fmt.Println()

started := time.Now()

args, err := shellquote.Split(config.Arguments)
if err != nil {
failf("Failed to parse arguments, error: %s", err)
}

var testErr error

log.Infof("Run test:")
logger.Infof("Run test:")
testCommand := testTask.GetCommand(filteredVariants, args...)

fmt.Println()
log.Donef("$ " + testCommand.PrintableCommandArgs())
logger.Donef("$ " + testCommand.PrintableCommandArgs())
fmt.Println()

testErr = testCommand.Run()
if testErr != nil {
log.Errorf("Test task failed, error: %v", testErr)
logger.Errorf("Test task failed, error: %v", testErr)
}
fmt.Println()
log.Infof("Export HTML results:")
logger.Infof("Export HTML results:")
fmt.Println()

reports, err := getArtifacts(gradleProject, started, config.HTMLResultDirPattern, true, true)
Expand All @@ -228,7 +233,7 @@ func main() {
}

fmt.Println()
log.Infof("Export XML results:")
logger.Infof("Export XML results:")
fmt.Println()

results, err := getArtifacts(gradleProject, started, config.XMLResultDirPattern, true, true)
Expand All @@ -243,7 +248,7 @@ func main() {
if config.TestResultDir != "" {
// Test Addon is turned on
fmt.Println()
log.Infof("Export XML results for test addon:")
logger.Infof("Export XML results for test addon:")
fmt.Println()

xmlResultFilePattern := config.XMLResultDirPattern
Expand All @@ -253,7 +258,7 @@ func main() {

resultXMLs, err := getArtifacts(gradleProject, started, xmlResultFilePattern, false, false)
if err != nil {
log.Warnf("Failed to find test XML test results, error: %s", err)
logger.Warnf("Failed to find test XML test results, error: %s", err)
} else {
lastOtherDirIdx := -1
for _, artifact := range resultXMLs {
Expand All @@ -267,9 +272,9 @@ func main() {
}

fmt.Println()
log.Infof("Collecting cache:")
if warning := cache.Collect(config.ProjectLocation, utilscache.Level(config.CacheLevel)); warning != nil {
log.Warnf("%s", warning)
logger.Infof("Collecting cache:")
if warning := cache.Collect(config.ProjectLocation, utilscache.Level(config.CacheLevel), cmdFactory); warning != nil {
logger.Warnf("%s", warning)
}
log.Donef(" Done")
logger.Donef(" Done")
}
Loading

0 comments on commit ca14557

Please sign in to comment.