Skip to content

Commit 8fdc72e

Browse files
authored
Inclusive variant filter added + validation test (#9)
* release flow clean-up * added variant filtering method * added IMAT step * gradlew path set for IMAT step
1 parent 44d2bca commit 8fdc72e

File tree

4 files changed

+42
-102
lines changed

4 files changed

+42
-102
lines changed

CHANGELOG.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

bitrise.yml

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
33

44
app:
55
envs:
6-
- BITRISE_STEP_ID: android-lint
7-
- BITRISE_STEP_VERSION: "0.9.4"
86
- BITRISE_STEP_GIT_CLONE_URL: https://github.com/bitrise-steplib/bitrise-step-android-lint.git
97
- MY_STEPLIB_REPO_FORK_GIT_URL: $MY_STEPLIB_REPO_FORK_GIT_URL
108
- SIMPLE_REPO_GIT_CLONE_URL: https://github.com/bitrise-samples/android-multiple-test-results-sample.git
@@ -38,6 +36,9 @@ workflows:
3836
- content: |
3937
#!/bin/bash
4038
git clone $SIMPLE_REPO_GIT_CLONE_URL .
39+
- install-missing-android-tools:
40+
inputs:
41+
- gradlew_path: ./gradlew
4142
- path::./:
4243
title: Test simple android project
4344
- change-workdir:
@@ -59,6 +60,11 @@ workflows:
5960
- is_create_path: true
6061
- path::./:
6162
title: Test monorepo
63+
- path::./:
64+
title: Test monorepo with module and variant set
65+
inputs:
66+
- module: app
67+
- variant: Debug
6268

6369
simple-and-mono-repo-in-root-tmp-dir:
6470
title: Test simple android project & mono repo projects in /tmp dir
@@ -79,6 +85,9 @@ workflows:
7985
- content: |
8086
#!/bin/bash
8187
git clone $SIMPLE_REPO_GIT_CLONE_URL .
88+
- install-missing-android-tools:
89+
inputs:
90+
- gradlew_path: ./gradlew
8291
- path::./:
8392
title: Test simple repo
8493
- change-workdir:
@@ -129,56 +138,3 @@ workflows:
129138
#!/bin/bash
130139
set -ex
131140
stepman audit --step-yml ./step.yml
132-
133-
# ----------------------------------------------------------------
134-
# --- workflows to create Release
135-
create-release:
136-
steps:
137-
- script:
138-
title:
139-
inputs:
140-
- content: |
141-
#!/bin/bash
142-
set -e
143-
export CI=true
144-
releaseman create --version $BITRISE_STEP_VERSION
145-
146-
share-this-step:
147-
envs:
148-
# if you want to share this step into a StepLib
149-
- MY_STEPLIB_REPO_FORK_GIT_URL: $MY_STEPLIB_REPO_FORK_GIT_URL
150-
- BITRISE_STEP_ID: $BITRISE_STEP_ID
151-
- BITRISE_STEP_VERSION: $BITRISE_STEP_VERSION
152-
- BITRISE_STEP_GIT_CLONE_URL: $BITRISE_STEP_GIT_CLONE_URL
153-
description: |-
154-
If this is the first time you try to share a Step you should
155-
first call: $ bitrise share
156-
157-
This will print you a guide, and information about how Step sharing
158-
works. Please read it at least once!
159-
160-
As noted in the Step sharing guide you'll have to fork the
161-
StepLib you want to share this step into. Once you're done with forking
162-
the repository you should set your own fork's git clone URL
163-
in the `.bitrise.secrets.yml` file, or here in the `envs` section,
164-
as the value of the `MY_STEPLIB_REPO_FORK_GIT_URL` environment.
165-
166-
You're now ready to share this Step, just make sure that
167-
the `BITRISE_STEP_ID` and `BITRISE_STEP_VERSION`
168-
environments are set to the desired values!
169-
170-
To share this Step into a StepLib you can just run: $ bitrise run share-this-step
171-
172-
Once it finishes the only thing left is to actually create a Pull Request,
173-
the way described in the guide printed at the end of the process.
174-
before_run:
175-
- audit-this-step
176-
steps:
177-
- script:
178-
inputs:
179-
- content: |-
180-
#!/bin/bash
181-
set -ex
182-
bitrise share start -c "${MY_STEPLIB_REPO_FORK_GIT_URL}"
183-
bitrise share create --stepid "${BITRISE_STEP_ID}" --tag "${BITRISE_STEP_VERSION}" --git "${BITRISE_STEP_GIT_CLONE_URL}"
184-
bitrise share finish

main.go

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,33 @@ func getArtifacts(gradleProject gradle.Project, started time.Time, pattern strin
4545
return
4646
}
4747

48+
func filterVariants(module, variant string, variantsMap gradle.Variants) (gradle.Variants, error) {
49+
// if module set: drop all the other modules
50+
if module != "" {
51+
v, ok := variantsMap[module]
52+
if !ok {
53+
return nil, fmt.Errorf("module not found: %s", module)
54+
}
55+
variantsMap = gradle.Variants{module: v}
56+
}
57+
// if variant not set: use all variants
58+
if variant == "" {
59+
return variantsMap, nil
60+
}
61+
filteredVariants := gradle.Variants{}
62+
for m, variants := range variantsMap {
63+
for _, v := range variants {
64+
if strings.ToLower(v) == strings.ToLower(variant) {
65+
filteredVariants[m] = append(filteredVariants[m], v)
66+
}
67+
}
68+
}
69+
if len(filteredVariants) == 0 {
70+
return nil, fmt.Errorf("variant: %s not found in any module", variant)
71+
}
72+
return filteredVariants, nil
73+
}
74+
4875
func mainE(config Config) error {
4976
gradleProject, err := gradle.NewProject(config.ProjectLocation)
5077
if err != nil {
@@ -62,7 +89,10 @@ func mainE(config Config) error {
6289
return fmt.Errorf("Failed to fetch variants, error: %s", err)
6390
}
6491

65-
filteredVariants := variants.Filter(config.Module, config.Variant)
92+
filteredVariants, err := filterVariants(config.Module, config.Variant, variants)
93+
if err != nil {
94+
failf("Failed to find buildable variants, error: %s", err)
95+
}
6696

6797
for module, variants := range variants {
6898
log.Printf("%s:", module)
@@ -76,16 +106,6 @@ func mainE(config Config) error {
76106
}
77107
fmt.Println()
78108

79-
if len(filteredVariants) == 0 {
80-
if config.Variant != "" {
81-
if config.Module == "" {
82-
return fmt.Errorf("Variant (%s) not found in any module", config.Variant)
83-
}
84-
return fmt.Errorf("No variant matching for (%s) in module: [%s]", config.Variant, config.Module)
85-
}
86-
return fmt.Errorf("Module not found: %s", config.Module)
87-
}
88-
89109
started := time.Now()
90110

91111
args, err := shellquote.Split(config.Arguments)

release_config.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)