Skip to content

Commit

Permalink
Add step input for specifying additional gradle options (#96)
Browse files Browse the repository at this point in the history
* Add step input for specifying additional gradle options

* Update README.md

* Update step.yml

* Update step.yml

* Update README
  • Loading branch information
godrei authored Jul 25, 2022
1 parent f8c3343 commit b77cfa8
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ You can also run this step directly with [Bitrise CLI](https://github.com/bitris
| --- | --- | --- | --- |
| `gradlew_path` | Using a Gradle Wrapper (gradlew) is required, as the wrapper is what makes sure that the right Gradle version is installed and used for the build. __You can find more information about the Gradle Wrapper (gradlew), and about how you can generate one (if you would not have one already)__ in the official guide at: [https://docs.gradle.org/current/userguide/gradle_wrapper.html](https://docs.gradle.org/current/userguide/gradle_wrapper.html). **The path should be relative** to the repository root, for example: `./gradlew`, or if it's in a sub directory: `./sub/dir/gradlew`. | required | `$GRADLEW_PATH` |
| `ndk_version` | NDK version to install, for example `23.0.7599858`. Run `sdkmanager --list` on your machine to see all available versions. Leave this input empty if you are not using the Native Development Kit in your project. | | |
| `gradlew_dependencies_options` | Additional options to be added to the executed `gradlew dependencies` command. The step runs `gradlew dependencies --stacktrace` to list and install the missing project dependencies. Additional options will be appended to the end of this command. Example: `--configuration-cache-problems=warn`. | | |
</details>

<details>
Expand Down
25 changes: 15 additions & 10 deletions androidcomponents/androidcomponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
)

type installer struct {
androidSDK *sdk.Model
sdkManager *sdkmanager.Model
gradlewPath string
androidSDK *sdk.Model
sdkManager *sdkmanager.Model
gradlewPath string
gradlewDependenciesOptions []string
}

// InstallLicences ...
Expand Down Expand Up @@ -84,15 +85,16 @@ func InstallLicences(androidSdk *sdk.Model) error {
}

// Ensure ...
func Ensure(androidSdk *sdk.Model, gradlewPath string) error {
func Ensure(androidSdk *sdk.Model, gradlewPath string, gradlewDependenciesOptions []string) error {
sdkManager, err := sdkmanager.New(androidSdk)
if err != nil {
return err
}
i := installer{
androidSdk,
sdkManager,
gradlewPath,
androidSDK: androidSdk,
sdkManager: sdkManager,
gradlewPath: gradlewPath,
gradlewDependenciesOptions: gradlewDependenciesOptions,
}

return retry.Times(1).Wait(time.Second).Try(func(attempt uint) error {
Expand All @@ -112,15 +114,18 @@ func (i installer) getDependencyCases() map[string]func(match string) error {
}
}

func getDependenciesOutput(projectLocation string) (string, error) {
gradleCmd := command.New("./gradlew", "dependencies", "--stacktrace")
func getDependenciesOutput(projectLocation string, options []string) (string, error) {
args := []string{"dependencies", "--stacktrace"}
args = append(args, options...)

gradleCmd := command.New("./gradlew", args...)
gradleCmd.SetStdin(strings.NewReader("y"))
gradleCmd.SetDir(projectLocation)
return gradleCmd.RunAndReturnTrimmedCombinedOutput()
}

func (i installer) scanDependencies(foundMatches ...string) error {
out, err := getDependenciesOutput(filepath.Dir(i.gradlewPath))
out, err := getDependenciesOutput(filepath.Dir(i.gradlewPath), i.gradlewDependenciesOptions)
if err == nil {
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ workflows:
- branch: master
- path::./:
title: Execute step
inputs:
- gradlew_dependencies_options: --configuration-cache-problems=warn
- gradle-runner:
inputs:
- gradle_task: assembleDebug
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ require (
github.com/bitrise-io/go-steputils v1.0.1
github.com/bitrise-io/go-utils v1.0.1
github.com/hashicorp/go-version v1.3.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiw
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=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
Expand Down
16 changes: 11 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ import (
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-steplib/steps-install-missing-android-tools/androidcomponents"
"github.com/hashicorp/go-version"
"github.com/kballard/go-shellquote"
)

const androidNDKHome = "ANDROID_NDK_HOME"

// Config ...
type Config struct {
GradlewPath string `env:"gradlew_path,file"`
AndroidHome string `env:"ANDROID_HOME"`
AndroidSDKRoot string `env:"ANDROID_SDK_ROOT"`
NDKVersion string `env:"ndk_version"`
GradlewPath string `env:"gradlew_path,file"`
AndroidHome string `env:"ANDROID_HOME"`
AndroidSDKRoot string `env:"ANDROID_SDK_ROOT"`
NDKVersion string `env:"ndk_version"`
GradlewDependenciesOptions string `env:"gradlew_dependencies_options"`
}

func failf(format string, v ...interface{}) {
Expand Down Expand Up @@ -129,6 +131,10 @@ func main() {
if err := stepconf.Parse(&config); err != nil {
failf("Process config: %s", err)
}
gradlewDependenciesOptions, err := shellquote.Split(config.GradlewDependenciesOptions)
if err != nil {
failf("provided gradlew_dependencies_options (%s) are not valid CLI parameters: %s", config.GradlewDependenciesOptions, err)
}

fmt.Println()
stepconf.Print(config)
Expand Down Expand Up @@ -189,7 +195,7 @@ func main() {
fmt.Println()
log.Infof("Ensure required Android SDK components")

if err := androidcomponents.Ensure(androidSdk, config.GradlewPath); err != nil {
if err := androidcomponents.Ensure(androidSdk, config.GradlewPath, gradlewDependenciesOptions); err != nil {
failf("Run: failed to ensure android components, error: %s", err)
}

Expand Down
12 changes: 12 additions & 0 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,15 @@ inputs:
title: NDK version
summary: NDK version to install. Leave this input empty if you are not using the Native Development Kit in your project.
description: NDK version to install, for example `23.0.7599858`. Run `sdkmanager --list` on your machine to see all available versions. Leave this input empty if you are not using the Native Development Kit in your project.
- gradlew_dependencies_options:
opts:
title: Additional options for the `gradlew dependencies` command
summary: Additional options to be added to the executed `gradlew dependencies` command.
description: |-
Additional options to be added to the executed `gradlew dependencies` command.
The step runs `gradlew dependencies --stacktrace` to list and install the missing project dependencies.
Additional options will be appended to the end of this command.
Example: `--configuration-cache-problems=warn`.
19 changes: 19 additions & 0 deletions vendor/github.com/kballard/go-shellquote/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions vendor/github.com/kballard/go-shellquote/README

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/kballard/go-shellquote/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 102 additions & 0 deletions vendor/github.com/kballard/go-shellquote/quote.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b77cfa8

Please sign in to comment.