Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step bundle inputs #1045

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,34 @@ func createWorkflowRunPlan(
return models.WorkflowRunPlan{}, fmt.Errorf("referenced step bundle not defined: %s", bundleID)
}

bundleEnvs := append(bundleDefinition.Environments, bundleOverride.Environments...)
var bundleEnvs []envmanModels.EnvironmentItemModel

bundleEnvs = append(bundleEnvs, bundleDefinition.Environments...)
bundleEnvs = append(bundleEnvs, bundleOverride.Environments...)

bundleEnvs = append(bundleEnvs, bundleDefinition.Inputs...)

// Filter undefined bundleOverride inputs
bundleDefinitionInputKeys := map[string]bool{}
for _, input := range bundleDefinition.Inputs {
key, _, err := input.GetKeyValuePair()
if err != nil {
return models.WorkflowRunPlan{}, err
}

bundleDefinitionInputKeys[key] = true
}
for _, input := range bundleOverride.Inputs {
key, _, err := input.GetKeyValuePair()
if err != nil {
return models.WorkflowRunPlan{}, err
}

if _, ok := bundleDefinitionInputKeys[key]; ok {
bundleEnvs = append(bundleEnvs, input)
}
}

bundleUUID := uuidProvider()

stepBundlePlans[bundleUUID] = models.StepBundlePlan{
Expand Down
206 changes: 202 additions & 4 deletions cli/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,45 @@ workflows:
fi`,
},
{
name: "Step Bundle definition's env var overrides secrets, app, workflow and step output env vars with the same env key",
name: "Step Bundle definition's inputs overrides secrets, app, workflow and step output env vars with the same env key",
secrets: `
envs:
- ENV_ORDER_TEST: "should be the 1."`,
config: `
format_version: "15"
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
envs:
- ENV_ORDER_TEST: "should be the 2."

step_bundles:
test-bundle:
inputs:
- ENV_ORDER_TEST: "should be the 5."
steps:
- script:
inputs:
- content: |
#!/bin/bash
set -v
echo "ENV_ORDER_TEST: $ENV_ORDER_TEST"
if [[ "$ENV_ORDER_TEST" != "should be the 5." ]] ; then
exit 1
fi

workflows:
test:
envs:
- ENV_ORDER_TEST: "should be the 3."
steps:
- script:
inputs:
- content: envman add --key ENV_ORDER_TEST --value "should be the 4."
- bundle::test-bundle: {}`,
},
{
name: "Step Bundle definition's envs overrides secrets, app, workflow and step output env vars with the same env key",
secrets: `
envs:
- ENV_ORDER_TEST: "should be the 1."`,
Expand Down Expand Up @@ -629,7 +667,87 @@ workflows:
- bundle::test-bundle: {}`,
},
{
name: "Step Bundle list item's env var overrides secrets, app, workflow, step output and step bundle definition env vars with the same env key",
name: "Step Bundle definition's inputs override Step Bundle definition envs with the same env key",
secrets: `
envs:
- ENV_ORDER_TEST: "should be the 1."`,
config: `
format_version: "15"
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
envs:
- ENV_ORDER_TEST: "should be the 2."

step_bundles:
test-bundle:
inputs:
- ENV_ORDER_TEST: "should be the 6."
envs:
- ENV_ORDER_TEST: "should be the 5."
steps:
- script:
inputs:
- content: |
#!/bin/bash
set -v
echo "ENV_ORDER_TEST: $ENV_ORDER_TEST"
if [[ "$ENV_ORDER_TEST" != "should be the 6." ]] ; then
exit 1
fi

workflows:
test:
envs:
- ENV_ORDER_TEST: "should be the 3."
steps:
- script:
inputs:
- content: envman add --key ENV_ORDER_TEST --value "should be the 4."
- bundle::test-bundle: {}`,
},
{
name: "Step Bundle list item's inputs overrides secrets, app, workflow, step output and step bundle definition env vars with the same env key",
secrets: `
envs:
- ENV_ORDER_TEST: "should be the 1."`,
config: `
format_version: "15"
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
envs:
- ENV_ORDER_TEST: "should be the 2."

step_bundles:
test-bundle:
inputs:
- ENV_ORDER_TEST: "should be the 5."
steps:
- script:
inputs:
- content: |
#!/bin/bash
set -v
echo "ENV_ORDER_TEST: $ENV_ORDER_TEST"
if [[ "$ENV_ORDER_TEST" != "should be the 6." ]] ; then
exit 1
fi

workflows:
test:
envs:
- ENV_ORDER_TEST: "should be the 3."
steps:
- script:
inputs:
- content: envman add --key ENV_ORDER_TEST --value "should be the 4."
- bundle::test-bundle:
inputs:
- ENV_ORDER_TEST: "should be the 6."`,
},
{
name: "Step Bundle list item's envs overrides secrets, app, workflow, step output and step bundle definition env vars with the same env key",
secrets: `
envs:
- ENV_ORDER_TEST: "should be the 1."`,
Expand Down Expand Up @@ -669,7 +787,87 @@ workflows:
- ENV_ORDER_TEST: "should be the 6."`,
},
{
name: "Step Bundle input envs are not shared with the workflow",
name: "Step Bundle list item's inputs overrides Step Bundle list item's envs with the same env key",
secrets: `
envs:
- ENV_ORDER_TEST: "should be the 1."`,
config: `
format_version: "15"
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
envs:
- ENV_ORDER_TEST: "should be the 2."

step_bundles:
test-bundle:
inputs:
- ENV_ORDER_TEST: "should be the 6."
envs:
- ENV_ORDER_TEST: "should be the 5."
steps:
- script:
inputs:
- content: |
#!/bin/bash
set -v
echo "ENV_ORDER_TEST: $ENV_ORDER_TEST"
if [[ "$ENV_ORDER_TEST" != "should be the 8." ]] ; then
exit 1
fi

workflows:
test:
envs:
- ENV_ORDER_TEST: "should be the 3."
steps:
- script:
inputs:
- content: envman add --key ENV_ORDER_TEST --value "should be the 4."
- bundle::test-bundle:
inputs:
- ENV_ORDER_TEST: "should be the 8."
envs:
- ENV_ORDER_TEST: "should be the 7."`,
},
{
name: "Step Bundle inputs are not shared with the workflow",
config: `
format_version: "15"
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

step_bundles:
test-bundle:
inputs:
- ENV_ORDER_TEST: "should be the 2."
steps:
- script:
inputs:
- content: |
#!/bin/bash
set -v
echo "ENV_ORDER_TEST: $ENV_ORDER_TEST"

workflows:
test:
envs:
- ENV_ORDER_TEST: "should be the 1."
steps:
- bundle::test-bundle:
inputs:
- ENV_ORDER_TEST: "should be the 3."
- script:
inputs:
- content: |
#!/bin/bash
set -v
echo "ENV_ORDER_TEST: $ENV_ORDER_TEST"
if [[ "$ENV_ORDER_TEST" != "should be the 1." ]] ; then
exit 1
fi`,
},
{
name: "Step Bundle envs are not shared with the workflow",
config: `
format_version: "15"
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"
Expand Down Expand Up @@ -705,7 +903,7 @@ workflows:
fi`,
},
{
name: "Step Bundle output envs are shared with the workflow",
name: "Step Bundle outputs are shared with the workflow",
config: `
format_version: "15"
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"
Expand Down
1 change: 0 additions & 1 deletion cli/run_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func (r WorkflowRunner) activateAndRunSteps(

// Global variables for restricting Step Bundle's environment variables for the given Step Bundle
currentStepBundleUUID := ""
// TODO: add the last step bundle's envs to environments
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seemed obsolete, we even have a test case to check if the last step bundle's output env vars are available: https://github.com/bitrise-io/bitrise/blob/master/cli/run_test.go#L708

var currentStepBundleEnvVars []envmanModels.EnvironmentItemModel

// ------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ const (
)

type StepBundleModel struct {
Inputs []envmanModels.EnvironmentItemModel `json:"inputs,omitempty" yaml:"inputs,omitempty"`
Environments []envmanModels.EnvironmentItemModel `json:"envs,omitempty" yaml:"envs,omitempty"`
Steps []StepListStepItemModel `json:"steps,omitempty" yaml:"steps,omitempty"`
}

type StepBundleListItemModel struct {
Inputs []envmanModels.EnvironmentItemModel `json:"inputs,omitempty" yaml:"inputs,omitempty"`
Environments []envmanModels.EnvironmentItemModel `json:"envs,omitempty" yaml:"envs,omitempty"`
}

Expand Down
Loading