-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share envs between the triggered workflows and the parent build (#6)
* feat: add an option to share the provided envs with the triggered workflows - step.yml: add the environment_key_list input. With that you can specify which envs do you want to share with the triggered worklflows. - bitrise/bitrise.go: add the Environment struct. - test added to test the environment_key_list input parsing * test: test fix * sourceBuildNumber param converted to the new Environment struct * test: add test_shared_envs workfows to the bitrise.yml * fix: chage the break command to continue in the loop which creates the shared envs for the request * docs: remove the note from the `environment_key_list` input in the step.yml * fix: typo fix
- Loading branch information
1 parent
55c0415
commit 4b4f74b
Showing
5 changed files
with
148 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,11 @@ app: | |
|
||
workflows: | ||
test: | ||
envs: | ||
- ENV_1: "1" | ||
- ENV_2: "2" | ||
- ENV_3: "3" | ||
- ENV_4: "4" | ||
before_run: | ||
- audit-this-step | ||
steps: | ||
|
@@ -24,6 +29,23 @@ workflows: | |
- workflows: $TEST_WORKFLOWS | ||
- access_token: $ACCESS_TOKEN | ||
- wait_for_builds: "true" | ||
- environment_key_list: "ENV_1\nENV_2\n$ENV_3\n$ENV_4\n" | ||
|
||
test_shared_envs: | ||
steps: | ||
- [email protected]: | ||
inputs: | ||
- content: |- | ||
#!/usr/bin/env bash | ||
# fail if any commands fails | ||
set -e | ||
echo "ENV_1 = $ENV_1 ENV_2 = $ENV_2 ENV_3 = $ENV_3 ENV_4 = $ENV_4" | ||
if [[ "$ENV_1" != "1" ]] || [[ "$ENV_2" != "2" ]] || [[ "$ENV_3" != "3" ]] || [[ "$ENV_4" != "4" ]] ; then | ||
exit 1; | ||
else | ||
echo "got all of the exported environments" | ||
fi | ||
# ---------------------------------------------------------------- | ||
# --- workflows to Share this step into a Step Library | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/bitrise-steplib/bitrise-step-build-router-start/bitrise" | ||
) | ||
|
||
func Test_createEnvs(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
environmentKeys string | ||
want []bitrise.Environment | ||
}{ | ||
{ | ||
name: "empty", | ||
environmentKeys: "", | ||
want: nil, | ||
}, | ||
{ | ||
name: "one env", | ||
environmentKeys: "ENV_1", | ||
want: []bitrise.Environment{bitrise.Environment{MappedTo: "ENV_1", Value: "1"}}, | ||
}, | ||
{ | ||
name: "multiple env", | ||
environmentKeys: "ENV_1\nENV_2\nENV_3\nENV_4", | ||
want: []bitrise.Environment{ | ||
bitrise.Environment{ | ||
MappedTo: "ENV_1", | ||
Value: "1", | ||
}, | ||
bitrise.Environment{ | ||
MappedTo: "ENV_2", | ||
Value: "2", | ||
}, | ||
bitrise.Environment{ | ||
MappedTo: "ENV_3", | ||
Value: "3", | ||
}, | ||
bitrise.Environment{ | ||
MappedTo: "ENV_4", | ||
Value: "4", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "multiple env with $", | ||
environmentKeys: "ENV_1\n$ENV_2\nENV_3\n$ENV_4", | ||
want: []bitrise.Environment{ | ||
bitrise.Environment{ | ||
MappedTo: "ENV_1", | ||
Value: "1", | ||
}, | ||
bitrise.Environment{ | ||
MappedTo: "ENV_2", | ||
Value: "2", | ||
}, | ||
bitrise.Environment{ | ||
MappedTo: "ENV_3", | ||
Value: "3", | ||
}, | ||
bitrise.Environment{ | ||
MappedTo: "ENV_4", | ||
Value: "4", | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := createEnvs(tt.environmentKeys); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("createEnvs() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters