Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Name string Envs []models.EnvironmentItemModel Want []Command }{ { Name: "empty env list", Envs: []models.EnvironmentItemModel{}, Want: []Command{}, }, { Name: "unset env", Envs: []models.EnvironmentItemModel{ {"A": "B", "opts": map[string]interface{}{"unset": true}}, }, Want: []Command{ {Action: UnsetAction, Variable: Variable{Key: "A"}}, }, }, { Name: "set env", Envs: []models.EnvironmentItemModel{ {"A": "B", "opts": map[string]interface{}{}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "A", Value: "B"}}, }, }, { Name: "set multiple envs", Envs: []models.EnvironmentItemModel{ {"A": "B", "opts": map[string]interface{}{}}, {"B": "C", "opts": map[string]interface{}{}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "A", Value: "B"}}, {Action: SetAction, Variable: Variable{Key: "B", Value: "C"}}, }, }, { Name: "set int env", Envs: []models.EnvironmentItemModel{ {"A": 12, "opts": map[string]interface{}{}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "A", Value: "12"}}, }, }, { Name: "skip env", Envs: []models.EnvironmentItemModel{ {"A": "B", "opts": map[string]interface{}{}}, {"S": "", "opts": map[string]interface{}{"skip_if_empty": true}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "A", Value: "B"}}, {Action: SkipAction, Variable: Variable{Key: "S"}}, }, }, { Name: "skip env, do not skip if not empty", Envs: []models.EnvironmentItemModel{ {"A": "B", "opts": map[string]interface{}{}}, {"S": "T", "opts": map[string]interface{}{"skip_if_empty": true}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "A", Value: "B"}}, {Action: SetAction, Variable: Variable{Key: "S", Value: "T"}}, }, }, { Name: "Env does only depend on envs declared before them", Envs: []models.EnvironmentItemModel{ {"simulator_device": "$simulator_major", "opts": map[string]interface{}{"is_expand": true}}, {"simulator_major": "12", "opts": map[string]interface{}{"is_expand": false}}, {"simulator_os_version": "$simulator_device", "opts": map[string]interface{}{"is_expand": true}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "simulator_device", Value: ""}}, {Action: SetAction, Variable: Variable{Key: "simulator_major", Value: "12"}}, {Action: SetAction, Variable: Variable{Key: "simulator_os_version", Value: ""}}, }, }, { Name: "Env does only depend on envs declared before them (input order switched)", Envs: []models.EnvironmentItemModel{ {"simulator_device": "$simulator_major", "opts": map[string]interface{}{"is_expand": true}}, {"simulator_os_version": "$simulator_device", "opts": map[string]interface{}{"is_sensitive": false}}, {"simulator_major": "12", "opts": map[string]interface{}{"is_expand": true}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "simulator_device", Value: ""}}, {Action: SetAction, Variable: Variable{Key: "simulator_os_version", Value: ""}}, {Action: SetAction, Variable: Variable{Key: "simulator_major", Value: "12"}}, }, }, { Name: "Env does only depend on envs declared before them, envs in a loop", Envs: []models.EnvironmentItemModel{ {"A": "$C", "opts": map[string]interface{}{"is_expand": true}}, {"B": "$A", "opts": map[string]interface{}{"is_expand": true}}, {"C": "$B", "opts": map[string]interface{}{"is_expand": true}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "A", Value: ""}}, {Action: SetAction, Variable: Variable{Key: "B", Value: ""}}, {Action: SetAction, Variable: Variable{Key: "C", Value: ""}}, }, }, { Name: "Do not expand env if is_expand is false", Envs: []models.EnvironmentItemModel{ {"SIMULATOR_OS_VERSION": "13.3", "opts": map[string]interface{}{"is_expand": true}}, {"simulator_os_version": "$SIMULATOR_OS_VERSION", "opts": map[string]interface{}{"is_expand": false}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "SIMULATOR_OS_VERSION", Value: "13.3"}}, {Action: SetAction, Variable: Variable{Key: "simulator_os_version", Value: "$SIMULATOR_OS_VERSION"}}, }, }, { Name: "Expand env, self reference", Envs: []models.EnvironmentItemModel{ {"SIMULATOR_OS_VERSION": "$SIMULATOR_OS_VERSION", "opts": map[string]interface{}{"is_expand": true}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "SIMULATOR_OS_VERSION", Value: ""}}, }, }, { Name: "Expand env, input contains env var", Envs: []models.EnvironmentItemModel{ {"SIMULATOR_OS_VERSION": "13.3", "opts": map[string]interface{}{"is_expand": false}}, {"simulator_os_version": "$SIMULATOR_OS_VERSION", "opts": map[string]interface{}{"is_expand": true}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "SIMULATOR_OS_VERSION", Value: "13.3"}}, {Action: SetAction, Variable: Variable{Key: "simulator_os_version", Value: "13.3"}}, }, }, { Name: "Multi level env var expansion", Envs: []models.EnvironmentItemModel{ {"A": "1", "opts": map[string]interface{}{"is_expand": true}}, {"B": "$A", "opts": map[string]interface{}{"is_expand": true}}, {"C": "prefix $B", "opts": map[string]interface{}{"is_expand": true}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "A", Value: "1"}}, {Action: SetAction, Variable: Variable{Key: "B", Value: "1"}}, {Action: SetAction, Variable: Variable{Key: "C", Value: "prefix 1"}}, }, }, { Name: "Multi level env var expansion 2", Envs: []models.EnvironmentItemModel{ {"SIMULATOR_OS_MAJOR_VERSION": "13", "opts": map[string]interface{}{"is_expand": true}}, {"SIMULATOR_OS_MINOR_VERSION": "3", "opts": map[string]interface{}{"is_expand": true}}, {"SIMULATOR_OS_VERSION": "$SIMULATOR_OS_MAJOR_VERSION.$SIMULATOR_OS_MINOR_VERSION", "opts": map[string]interface{}{"is_expand": true}}, {"simulator_os_version": "$SIMULATOR_OS_VERSION", "opts": map[string]interface{}{"is_expand": true}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "SIMULATOR_OS_MAJOR_VERSION", Value: "13"}}, {Action: SetAction, Variable: Variable{Key: "SIMULATOR_OS_MINOR_VERSION", Value: "3"}}, {Action: SetAction, Variable: Variable{Key: "SIMULATOR_OS_VERSION", Value: "13.3"}}, {Action: SetAction, Variable: Variable{Key: "simulator_os_version", Value: "13.3"}}, }, }, { Name: "Env expand, duplicate env declarations", Envs: []models.EnvironmentItemModel{ {"simulator_os_version": "12.1", "opts": map[string]interface{}{}}, {"simulator_device": "iPhone 8 ($simulator_os_version)", "opts": map[string]interface{}{"is_expand": "true"}}, {"simulator_os_version": "13.3", "opts": map[string]interface{}{}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "simulator_os_version", Value: "12.1"}}, {Action: SetAction, Variable: Variable{Key: "simulator_device", Value: "iPhone 8 (12.1)"}}, {Action: SetAction, Variable: Variable{Key: "simulator_os_version", Value: "13.3"}}, }, }, { Name: "is_sensitive property is not affecting input expansion", Envs: []models.EnvironmentItemModel{ {"SECRET_ENV": "top secret", "opts": map[string]interface{}{"is_sensitive": true}}, {"simulator_device": "iPhone $SECRET_ENV", "opts": map[string]interface{}{"is_expand": true, "is_sensitive": false}}, }, Want: []Command{ {Action: SetAction, Variable: Variable{Key: "SECRET_ENV", Value: "top secret"}}, {Action: SetAction, Variable: Variable{Key: "simulator_device", Value: "iPhone top secret"}}, }, }, }
EnvmanSharedTestCases are test cases used as unit and integration tests.
Functions ¶
Types ¶
type Action ¶
type Action int
Action is a possible action changing an environment variable
const ( // InvalidAction represents an unexpected state InvalidAction Action = iota + 1 // SetAction is an environment variable assignement, like os.Setenv SetAction // UnsetAction is an action to clear (if existing) an environment variable, like os.Unsetenv UnsetAction // SkipAction means that no action is performed (usually for an env with an empty value) SkipAction )
type DeclarationSideEffects ¶
type DeclarationSideEffects struct {
// CommandHistory is an ordered list of commands: when performed in sequence,
// will result in a environment that contains the declared env vars
CommandHistory []Command
// ResultEnvironment is returned for reference,
// it will equal the environment after performing the commands
ResultEnvironment map[string]string
// EvaluatedNewEnvs is the set of envs resulted after evaluating newEnvs with envSource
EvaluatedNewEnvs map[string]string
}
DeclarationSideEffects is returned by GetDeclarationsSideEffects()
func GetDeclarationsSideEffects ¶
func GetDeclarationsSideEffects(newEnvs []models.EnvironmentItemModel, envSource EnvironmentSource) (DeclarationSideEffects, error)
GetDeclarationsSideEffects iterates over the list of ordered new declared variables sequentially and returns the needed commands (like os.Setenv) to add the variables to the current environment. The current process environment is not changed. Variable expansion is done also, every new variable can reference the previous and initial environments (via EnvironmentSource) The new variables (models.EnvironmentItemModel) can be defined in the envman definition file, or filled in directly. If the source of the variables (models.EnvironmentItemModel) is the bitrise.yml workflow, they will be in this order:
- Bitrise CLI configuration parameters (IS_CI, IS_DEBUG)
- App secrets
- App level envs
- Workflow level envs
- Additional Step inputs envs (BITRISE_STEP_SOURCE_DIR; BitriseTestDeployDirEnvKey ("BITRISE_TEST_DEPLOY_DIR"), PWD)
- Input envs
type DefaultEnvironmentSource ¶
type DefaultEnvironmentSource struct{}
DefaultEnvironmentSource is a default implementation of EnvironmentSource, returns the current environment
func (*DefaultEnvironmentSource) GetEnvironment ¶
func (*DefaultEnvironmentSource) GetEnvironment() map[string]string
GetEnvironment returns the current process' environment
type EnvironmentSource ¶
EnvironmentSource implementations can return an initial environment