Esempio n. 1
0
func TestLastWorkflowIDInConfig(t *testing.T) {
	configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  before:

  target:
    title: target
    before_run:
    - before
    after_run:
    - after1

  after1:
    after_run:
    - after2

  after2:
  `
	config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.NoError(t, err)
	require.Equal(t, 0, len(warnings))

	last, err := lastWorkflowIDInConfig("target", config)
	require.NoError(t, err)
	require.Equal(t, "after2", last)
}
Esempio n. 2
0
func TestLastWorkflowIDInConfig(t *testing.T) {
	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  before:

  target:
    title: target
    before_run:
    - before
    after_run:
    - after1

  after1:
    after_run:
    - after2

  after2:
  `
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	if err != nil {
		t.Fatal(err)
	}

	last, err := lastWorkflowIDInConfig("target", config)
	if err != nil {
		t.Fatal(err)
	}

	if last != "after2" {
		t.Fatalf("Last workflow id is incorrect: (%s) should be (after2)", last)
	}
}
Esempio n. 3
0
func TestStepOutputsInTemplate(t *testing.T) {
	inventoryStr := `
envs:
- TEMPLATE_TEST0: "true"
`
	inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
	require.Equal(t, nil, err)

	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - TEMPLATE_TEST1: "true"

workflows:
  test:
    envs:
    - TEMPLATE_TEST2: "true"
    steps:
    - script:
        title: "Envman add"
        inputs:
        - content: |
            #!/bin/bash
            set -v
            envman add --key TEMPLATE_TEST3 --value "true"
    - script:
        title: "TEMPLATE_TEST0"
        run_if: |-
          {{enveq "TEMPLATE_TEST0" "true"}}
    - script:
        title: "TEMPLATE_TEST1"
        run_if: |-
          {{enveq "TEMPLATE_TEST1" "true"}}
    - script:
        title: "TEMPLATE_TEST2"
        run_if: |-
          {{enveq "TEMPLATE_TEST2" "true"}}
    - script:
        title: "TEMPLATE_TEST3"
        run_if: |-
          {{enveq "TEMPLATE_TEST3" "true"}}
    - script:
        title: "TEMPLATE_TEST_NO_VALUE"
        run_if: |-
          {{enveq "TEMPLATE_TEST_NO_VALUE" "true"}}

`
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
	require.Equal(t, nil, err)
	require.Equal(t, 5, len(buildRunResults.SuccessSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSkippableSteps))
	require.Equal(t, 1, len(buildRunResults.SkippedSteps))
}
Esempio n. 4
0
// Test - Bitrise activateAndRunWorkflow
// Trivial success test
func TestSuccess(t *testing.T) {
	configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  target:
    steps:
    - script:
        title: Should success
    `

	require.NoError(t, configs.InitPaths())

	config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.NoError(t, err)
	require.Equal(t, 0, len(warnings))

	_, found := config.Workflows["target"]
	require.Equal(t, true, found)

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "target", config, []envmanModels.EnvironmentItemModel{})
	require.NoError(t, err)
	require.Equal(t, 1, len(buildRunResults.SuccessSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSkippableSteps))
	require.Equal(t, 0, len(buildRunResults.SkippedSteps))

	require.Equal(t, "0", os.Getenv("BITRISE_BUILD_STATUS"))
	require.Equal(t, "0", os.Getenv("STEPLIB_BUILD_STATUS"))
}
Esempio n. 5
0
// Test - Bitrise Environments
// Test for same env in before and target workflow, actual workflow should overwrite environemnt and use own value
func TestWorkflowEnvironmentOverWrite(t *testing.T) {
	configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  before:
    envs:
    - ENV: env1
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo ${ENV}
            if [[ "$ENV" != "env1" ]] ; then
              exit 1
            fi

  target:
    title: target
    envs:
    - ENV: env2
    before_run:
    - before
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo ${ENV}
            if [[ "$ENV" != "env2" ]] ; then
              exit 1
            fi
`

	require.NoError(t, configs.InitPaths())

	config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.NoError(t, err)
	require.Equal(t, 0, len(warnings))

	_, found := config.Workflows["target"]
	require.Equal(t, true, found)

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "target", config, []envmanModels.EnvironmentItemModel{})
	require.NoError(t, err)
	require.Equal(t, 2, len(buildRunResults.SuccessSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSkippableSteps))
	require.Equal(t, 0, len(buildRunResults.SkippedSteps))

	require.Equal(t, "0", os.Getenv("BITRISE_BUILD_STATUS"))
	require.Equal(t, "0", os.Getenv("STEPLIB_BUILD_STATUS"))
}
Esempio n. 6
0
// Outputs exported with `envman add` should be accessible for subsequent Steps.
func TestStepOutputEnvironment(t *testing.T) {
	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  out-test:
    title: Output Test
    steps:
    - script:
        inputs:
        - content: envman -l=debug add --key MY_TEST_1 --value 'Test value 1'
    - script:
        inputs:
        - content: |-
            if [[ "${MY_TEST_1}" != "Test value 1" ]] ; then
              echo " [!] MY_TEST_1 invalid: ${MY_TEST_1}"
              exit 1
            fi
    - script:
        title: Should fail
        inputs:
        - content: |-
            envman add --key MY_TEST_2 --value 'Test value 2'
            # exported output, but test fails
            exit 22
    - script:
        is_always_run: true
        inputs:
        - content: |-
            if [[ "${MY_TEST_2}" != "Test value 2" ]] ; then
              exit 1
            fi
`
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)
	_, found := config.Workflows["out-test"]
	require.Equal(t, true, found)

	err = config.Validate()
	require.Equal(t, nil, err)

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "out-test", config, []envmanModels.EnvironmentItemModel{})
	require.Equal(t, "[BITRISE_CLI] - Workflow FINISHED but a couple of steps failed - Ouch", err.Error())
	require.Equal(t, 0, len(buildRunResults.SkippedSteps))
	require.Equal(t, 3, len(buildRunResults.SuccessSteps))
	require.Equal(t, 1, len(buildRunResults.FailedSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSkippableSteps))

	// the exported output envs should NOT be exposed here, should NOT be available!
	require.Equal(t, "", os.Getenv("MY_TEST_1"))
	require.Equal(t, "", os.Getenv("MY_TEST_2"))

	// standard, Build Status ENV test
	require.Equal(t, "1", os.Getenv("BITRISE_BUILD_STATUS"))
	require.Equal(t, "1", os.Getenv("STEPLIB_BUILD_STATUS"))
}
Esempio n. 7
0
// Test - Bitrise activateAndRunWorkflow
// Trivial test with 1 workflow
func Test1Workflows(t *testing.T) {
	configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  trivial_fail:
    steps:
    - script:
        title: Should success
    - script:
        title: Should fail, but skippable
        is_skippable: true
        inputs:
        - content: |
            #!/bin/bash
            set -v
            exit 2
    - script:
        title: Should success
    - script:
        title: Should fail
        inputs:
        - content: |
            #!/bin/bash
            set -v
            exit 2
    - script:
        title: Should success
        is_always_run: true
    - script:
        title: Should skipped
  `
	config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.NoError(t, err)
	require.Equal(t, 0, len(warnings))

	workflow, found := config.Workflows["trivial_fail"]
	require.Equal(t, true, found)

	buildRunResults := models.BuildRunResultsModel{
		StartTime:      time.Now(),
		StepmanUpdates: map[string]int{},
	}

	buildRunResults, err = activateAndRunWorkflow("trivial_fail", workflow, config, buildRunResults, &[]envmanModels.EnvironmentItemModel{}, "")
	require.NoError(t, err)
	require.Equal(t, 3, len(buildRunResults.SuccessSteps))
	require.Equal(t, 1, len(buildRunResults.FailedSteps))
	require.Equal(t, 1, len(buildRunResults.FailedSkippableSteps))
	require.Equal(t, 1, len(buildRunResults.SkippedSteps))

	require.Equal(t, "1", os.Getenv("BITRISE_BUILD_STATUS"))
	require.Equal(t, "1", os.Getenv("STEPLIB_BUILD_STATUS"))
}
Esempio n. 8
0
func TestDeleteEnvironment(t *testing.T) {
	configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  test:
    steps:
    - script:
        is_skippable: true
        title: "Envman add DELETE_TEST"
        inputs:
        - content: |
            #!/bin/bash
            envman add --key DELETE_TEST --value "delete test"
    - script:
        title: "Test env DELETE_TEST"
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "DELETE_TEST: $DELETE_TEST"
            if [ -z "$DELETE_TEST" ] ; then
              exit 1
            fi
    - script:
        title: "Delete env DELETE_TEST"
        inputs:
        - content: |
            #!/bin/bash
            envman add --key DELETE_TEST --value ""
    - script:
        title: "Test env DELETE_TEST"
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "DELETE_TEST: $DELETE_TEST"
            if [ ! -z "$DELETE_TEST" ] ; then
              exit 1
            fi
`
	require.NoError(t, configs.InitPaths())

	config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.NoError(t, err)
	require.Equal(t, 0, len(warnings))

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "test", config, []envmanModels.EnvironmentItemModel{})
	require.NoError(t, err)
	require.Equal(t, 4, len(buildRunResults.SuccessSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSkippableSteps))
	require.Equal(t, 0, len(buildRunResults.SkippedSteps))
}
Esempio n. 9
0
func generateBitriseYMLContent(userInputProjectTitle, userInputDevBranch string) (string, []string, error) {
	bitriseConfContent := fmt.Sprintf(defaultBitriseYMLContentFormat,
		models.Version, userInputProjectTitle, userInputDevBranch)

	_, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(bitriseConfContent))
	if err != nil {
		return "", warnings, err
	}

	return bitriseConfContent, warnings, nil
}
Esempio n. 10
0
// Test - Bitrise Environments
// Step input should visible only for actual step and invisible for other steps
func TestStepInputEnvironment(t *testing.T) {
	configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  before:
    steps:
    - script:
        inputs:
        - working_dir: $HOME

  target:
    title: target
    before_run:
    - before
    steps:
    - script:
        title: "${working_dir} should not exist"
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo ${ENV}
            if [ ! -z "$working_dir" ] ; then
              echo ${working_dir}
              exit 3
            fi
`

	require.NoError(t, configs.InitPaths())

	config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.NoError(t, err)
	require.Equal(t, 0, len(warnings))

	_, found := config.Workflows["target"]
	require.Equal(t, true, found)

	if os.Getenv("working_dir") != "" {
		require.Equal(t, nil, os.Unsetenv("working_dir"))
	}

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "target", config, []envmanModels.EnvironmentItemModel{})
	require.NoError(t, err)
	require.Equal(t, 2, len(buildRunResults.SuccessSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSkippableSteps))
	require.Equal(t, 0, len(buildRunResults.SkippedSteps))

	require.Equal(t, "0", os.Getenv("BITRISE_BUILD_STATUS"))
	require.Equal(t, "0", os.Getenv("STEPLIB_BUILD_STATUS"))
}
Esempio n. 11
0
// GetBitriseConfigFromBase64Data ...
func GetBitriseConfigFromBase64Data(configBase64Str string) (models.BitriseDataModel, []string, error) {
	configBase64Bytes, err := base64.StdEncoding.DecodeString(configBase64Str)
	if err != nil {
		return models.BitriseDataModel{}, []string{}, fmt.Errorf("Failed to decode base 64 string, error: %s", err)
	}

	config, warnings, err := bitrise.ConfigModelFromYAMLBytes(configBase64Bytes)
	if err != nil {
		return models.BitriseDataModel{}, warnings, fmt.Errorf("Failed to parse bitrise config, error: %s", err)
	}

	return config, warnings, nil
}
Esempio n. 12
0
func TestEvaluateInputs(t *testing.T) {
	configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  test:
    envs:
    - TEST_KEY: "test value"
    steps:
    - script:
        title: "Template test"
        inputs:
        - content: |
            #!/bin/bash
            set -v
            {{if .IsCI}}
            exit 1
            {{else}}
            exit 0
            {{end}}
          opts:
            is_template: true
    - script:
        title: "Template test"
        inputs:
        - content: |
            #!/bin/bash
            set -v
            {{if enveq "TEST_KEY" "test value"}}
            exit 0
            {{else}}
            exit 1
            {{end}}
          opts:
            is_template: true
`

	require.NoError(t, configs.InitPaths())

	config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.NoError(t, err)
	require.Equal(t, 0, len(warnings))

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "test", config, []envmanModels.EnvironmentItemModel{})
	require.Equal(t, nil, err)
	require.Equal(t, 0, len(buildRunResults.SkippedSteps))
	require.Equal(t, 2, len(buildRunResults.SuccessSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSkippableSteps))
}
Esempio n. 13
0
func Test(t *testing.T) {
	// should be valid
	bitriseConfContent, warnings, err := generateBitriseYMLContent("App Title", "master")
	require.NoError(t, err)
	require.Equal(t, 0, len(warnings))
	require.NotEqual(t, "", bitriseConfContent)
	require.Contains(t, bitriseConfContent, fmt.Sprintf("format_version: %s", models.Version))
	require.Contains(t, bitriseConfContent, `- BITRISE_APP_TITLE: "App Title"`)
	require.Contains(t, bitriseConfContent, `- BITRISE_DEV_BRANCH: "master"`)

	_, warnings, err = bitrise.ConfigModelFromYAMLBytes([]byte(bitriseConfContent))
	require.NoError(t, err)
	require.Equal(t, 0, len(warnings))
}
Esempio n. 14
0
// Test - Bitrise activateAndRunWorkflow
// Trivial success test
func TestSuccess(t *testing.T) {
	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  target:
    steps:
    - script:
        title: Should success
    `
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	if err != nil {
		t.Fatal(err)
	}
	_, found := config.Workflows["target"]
	if !found {
		t.Fatal("No workflow found with ID (target)")
	}
	if err := config.Validate(); err != nil {
		t.Fatal(err)
	}

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "target", config, []envmanModels.EnvironmentItemModel{})
	t.Log("Err: ", err)
	if len(buildRunResults.SuccessSteps) != 1 {
		t.Fatalf("Success step count (%d), should be (1)", len(buildRunResults.SuccessSteps))
	}
	if len(buildRunResults.FailedSteps) != 0 {
		t.Fatalf("Failed step count (%d), should be (0)", len(buildRunResults.FailedSteps))
	}
	if len(buildRunResults.FailedSkippableSteps) != 0 {
		t.Fatalf("FailedSkippable step count (%d), should be (0)", len(buildRunResults.FailedSkippableSteps))
	}
	if len(buildRunResults.SkippedSteps) != 0 {
		t.Fatalf("Skipped step count (%d), should be (0)", len(buildRunResults.SkippedSteps))
	}

	if status := os.Getenv("BITRISE_BUILD_STATUS"); status != "0" {
		t.Log("BITRISE_BUILD_STATUS:", status)
		t.Fatal("BUILD_STATUS envs are incorrect")
	}
	if status := os.Getenv("STEPLIB_BUILD_STATUS"); status != "0" {
		t.Log("STEPLIB_BUILD_STATUS:", status)
		t.Fatal("STEPLIB_BUILD_STATUS envs are incorrect")
	}
}
Esempio n. 15
0
func TestFailedStepOutputs(t *testing.T) {
	configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  test:
    steps:
    - script:
        is_skippable: true
        title: "Envman add"
        inputs:
        - content: |
            #!/bin/bash
            set -v
            envman add --key FAILED_OUTPUT_TEST --value "failed step output"
            exit 1
    - script:
        title: "Test failed output"
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "FAILED_OUTPUT_TEST: $FAILED_OUTPUT_TEST"
            if [[ "$FAILED_OUTPUT_TEST" != "failed step output" ]] ; then
              exit 1
            fi
`
	require.NoError(t, configs.InitPaths())

	config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.NoError(t, err)
	require.Equal(t, 0, len(warnings))

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "test", config, []envmanModels.EnvironmentItemModel{})
	require.NoError(t, err)
	require.Equal(t, 1, len(buildRunResults.SuccessSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSteps))
	require.Equal(t, 1, len(buildRunResults.FailedSkippableSteps))
	require.Equal(t, 0, len(buildRunResults.SkippedSteps))
}
Esempio n. 16
0
func TestExpandEnvs(t *testing.T) {
	configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  test:
    envs:
    - ENV0: "Hello"
    - ENV1: "$ENV0 world"
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            envman add --key ENV2 --value "$ENV1 !"
    - script:
        inputs:
        - content: |
            #!/bin/bash
            echo "ENV2: $ENV2"
            if [ "$ENV2" != "Hello world !" ] ; then
              echo "Actual ($ENV2), excpected (Hello world !)"
              exit 1
            fi
`

	require.NoError(t, configs.InitPaths())

	config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.NoError(t, err)
	require.Equal(t, 0, len(warnings))

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "test", config, []envmanModels.EnvironmentItemModel{})
	require.NoError(t, err)
	require.Equal(t, 2, len(buildRunResults.SuccessSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSkippableSteps))
	require.Equal(t, 0, len(buildRunResults.SkippedSteps))
}
Esempio n. 17
0
func TestInvalidStepID(t *testing.T) {
	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  target:
    title: Invalid step id
    steps:
    - invalid-step:
    - invalid-step:
    - invalid-step:
`

	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	if err != nil {
		t.Fatal(err)
	}

	results, err := runWorkflowWithConfiguration(time.Now(), "target", config, []envmanModels.EnvironmentItemModel{})
	require.Equal(t, 1, len(results.StepmanUpdates))
}
Esempio n. 18
0
// Test - Bitrise ConfigModelFromYAMLBytes
// Workflow contains before and after workflow, and no one contains steps, but circular wofklow dependecy exist, which should fail
func TestRefeneceCycle(t *testing.T) {
	configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  before1:
    before_run:
    - before2

  before2:
    before_run:
    - before1

  target:
    before_run:
    - before1
    - before2
  `
	_, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Error(t, err)
	require.Equal(t, 0, len(warnings))
}
Esempio n. 19
0
// Test - Bitrise ConfigModelFromYAMLBytes
// Workflow contains before and after workflow, and no one contains steps, but circular wofklow dependecy exist, which should fail
func TestRefeneceCycle(t *testing.T) {
	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  before1:
    before_run:
    - before2

  before2:
    before_run:
    - before1

  target:
    before_run:
    - before1
    - before2
  `
	_, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	if err == nil {
		t.Fatal("Should find workflow reference cycle")
	}
}
Esempio n. 20
0
// Outputs exported with `envman add` should be accessible for subsequent Steps,
//  except if the step failed.
func TestStepOutputEnvironment(t *testing.T) {
	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  out-test:
    title: Output Test
    steps:
    - script:
        inputs:
        - content: envman -l=debug add --key MY_TEST_1 --value 'Test value 1'
    - script:
        inputs:
        - content: |-
            if [[ "${MY_TEST_1}" != "Test value 1" ]] ; then
              echo " [!] MY_TEST_1 invalid: ${MY_TEST_1}"
              exit 1
            fi
    - script:
        inputs:
        - content: |-
            envman add --key MY_TEST_2 --value 'Test value 2'
            # exported output, but test fails
            exit 22
    - script:
        is_always_run: true
        inputs:
        - content: |-
            if [[ "${MY_TEST_2}" != "" ]] ; then
              echo " [!] MY_TEST_2 invalid - expected empty, got: ${MY_TEST_2}"
              exit 1
            fi
`
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	if err != nil {
		t.Fatal(err)
	}
	_, found := config.Workflows["out-test"]
	if !found {
		t.Fatal("No workflow found with ID (out-test)")
	}
	if err := config.Validate(); err != nil {
		t.Fatal(err)
	}

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "out-test", config, []envmanModels.EnvironmentItemModel{})
	t.Log("Err: ", err)
	t.Logf("Build run result: %#v", buildRunResults)
	if len(buildRunResults.SkippedSteps) != 0 {
		t.Fatalf("Skipped step count (%d), should be (0)", len(buildRunResults.SkippedSteps))
	}
	if len(buildRunResults.SuccessSteps) != 3 {
		t.Fatalf("Success step count (%d), should be (3)", len(buildRunResults.SuccessSteps))
	}
	if len(buildRunResults.FailedSteps) != 1 {
		t.Fatalf("Failed step count (%d), should be (1)", len(buildRunResults.FailedSteps))
	}
	if len(buildRunResults.FailedSkippableSteps) != 0 {
		t.Fatalf("FailedSkippable step count (%d), should be (0)", len(buildRunResults.FailedSkippableSteps))
	}

	// the exported output envs should NOT be exposed here, should NOT be available!
	if envVal := os.Getenv("MY_TEST_1"); envVal != "" {
		t.Fatal("MY_TEST_1 env is exposed, should NOT be! Value: ", envVal)
	}
	if envVal := os.Getenv("MY_TEST_2"); envVal != "" {
		t.Fatal("MY_TEST_2 env is exposed, should NOT be! Value: ", envVal)
	}

	// standard, Build Status ENV test
	if status := os.Getenv("BITRISE_BUILD_STATUS"); status != "1" {
		t.Log("BITRISE_BUILD_STATUS:", status)
		t.Fatal("BUILD_STATUS envs are incorrect")
	}
	if status := os.Getenv("STEPLIB_BUILD_STATUS"); status != "1" {
		t.Log("STEPLIB_BUILD_STATUS:", status)
		t.Fatal("STEPLIB_BUILD_STATUS envs are incorrect")
	}
}
Esempio n. 21
0
// Test - Bitrise BuildStatusEnv
// Checks if BuildStatusEnv is set correctly
func TestBuildStatusEnv(t *testing.T) {
	configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  before1:
    steps:
    - script:
        title: Should success
    - script:
        title: Should fail, but skippable
        is_skippable: true
        inputs:
        - content: |
            #!/bin/bash
            set -v
            exit 2
    - script:
        title: Should success

  before2:
    steps:
    - script:
        title: Should success

  target:
    steps:
    - script:
        title: Should success
        inputs:
        - content: |
            #!/bin/bash
            set -v
            if [[ "$BITRISE_BUILD_STATUS" != "0" ]] ; then
              exit 1
            fi
            if [[ "$STEPLIB_BUILD_STATUS" != "0" ]] ; then
              exit 1
            fi
    - script:
        title: Should fail, but skippable
        is_skippable: true
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo 'This is a before workflow'
            exit 2
    - script:
        title: Should success
        inputs:
        - content: |
            #!/bin/bash
            set -v
            if [[ "$BITRISE_BUILD_STATUS" != "0" ]] ; then
              exit 1
            fi
            if [[ "$STEPLIB_BUILD_STATUS" != "0" ]] ; then
              exit 1
            fi
    - script:
        title: Should fail
        inputs:
        - content: |
            #!/bin/bash
            set -v
            exit 1
    - script:
        title: Should success
        is_always_run: true
        inputs:
        - content: |
            #!/bin/bash
            set -v
            if [[ "$BITRISE_BUILD_STATUS" != "1" ]] ; then
              echo "should fail"
            fi
            if [[ "$STEPLIB_BUILD_STATUS" != "1" ]] ; then
              echo "should fail"
            fi
    - script:
        title: Should skipped
  `

	require.NoError(t, configs.InitPaths())

	config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.NoError(t, err)
	require.Equal(t, 0, len(warnings))

	_, found := config.Workflows["target"]
	require.Equal(t, true, found)

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "target", config, []envmanModels.EnvironmentItemModel{})
	require.NoError(t, err)
	require.Equal(t, 3, len(buildRunResults.SuccessSteps))
	require.Equal(t, 1, len(buildRunResults.FailedSteps))
	require.Equal(t, 1, len(buildRunResults.FailedSkippableSteps))
	require.Equal(t, 1, len(buildRunResults.SkippedSteps))

	require.Equal(t, "1", os.Getenv("BITRISE_BUILD_STATUS"))
	require.Equal(t, "1", os.Getenv("STEPLIB_BUILD_STATUS"))
}
Esempio n. 22
0
func TestEnvOrders(t *testing.T) {
	t.Log("Only secret env - secret env should be use")
	{
		inventoryStr := `
envs:
- ENV_ORDER_TEST: "should be the 1."
`

		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  test:
    steps:
    - 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
`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}

	t.Log("Secret env & app env also defined - app env should be use")
	{
		inventoryStr := `
envs:
- ENV_ORDER_TEST: "should be the 1."
`

		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

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

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

`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}

	t.Log("Secret env & app env && workflow env also defined - workflow env should be use")
	{
		inventoryStr := `
envs:
- ENV_ORDER_TEST: "should be the 1."
`

		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

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

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

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}

	t.Log("Secret env & app env && workflow env && step output env also defined - step output env should be use")
	{
		inventoryStr := `
envs:
- ENV_ORDER_TEST: "should be the 1."
`

		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

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

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."
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "ENV_ORDER_TEST: $ENV_ORDER_TEST"
            if [[ "$ENV_ORDER_TEST" != "should be the 4." ]] ; then
              exit 1
            fi
`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}
}
Esempio n. 23
0
func TestSkipIfEmpty(t *testing.T) {
	t.Log("skip_if_empty=true && value=empty => should not add")
	{
		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  skip_if_empty:
    envs:
    - TEST: test
    - TEST:
      opts:
        skip_if_empty: true
    steps:
    - script:
        is_skippable: true
        title: "Envman add DELETE_TEST"
        inputs:
        - content: |
            #!/bin/bash
            if [ -z $TEST ] ; then
              echo "TEST shuld exist"
              exit 1
            fi
`
		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "skip_if_empty", config, []envmanModels.EnvironmentItemModel{})
		require.NoError(t, err)
		require.Equal(t, 1, len(buildRunResults.SuccessSteps))
		require.Equal(t, 0, len(buildRunResults.FailedSteps))
		require.Equal(t, 0, len(buildRunResults.FailedSkippableSteps))
		require.Equal(t, 0, len(buildRunResults.SkippedSteps))
	}

	t.Log("skip_if_empty=false && value=empty => should add")
	{
		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  skip_if_empty:
    envs:
    - TEST: test
    - TEST:
      opts:
        skip_if_empty: false
    steps:
    - script:
        is_skippable: true
        title: "Envman add DELETE_TEST"
        inputs:
        - content: |
            #!/bin/bash
            if [ ! -z $TEST ] ; then
              echo "TEST env shuld not exist"
              exit 1
            fi
`
		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "skip_if_empty", config, []envmanModels.EnvironmentItemModel{})
		require.NoError(t, err)
		require.Equal(t, 1, len(buildRunResults.SuccessSteps))
		require.Equal(t, 0, len(buildRunResults.FailedSteps))
		require.Equal(t, 0, len(buildRunResults.FailedSkippableSteps))
		require.Equal(t, 0, len(buildRunResults.SkippedSteps))
	}
}
Esempio n. 24
0
func TestBitriseSourceDir(t *testing.T) {
	currPth, err := pathutil.NormalizedOSTempDirPath("bitrise_source_dir_test")
	if err != nil {
		t.Fatal("Failed to get curr abs path: ", err)
	}

	testPths := []string{}
	for i := 0; i < 4; i++ {
		testPth := path.Join(currPth, fmt.Sprintf("_test%d", i))
		if err := os.RemoveAll(testPth); err != nil {
			t.Fatalf("Failed to remove %s, err: %s: ", testPth, err)
		}

		err := os.Mkdir(testPth, 0777)
		if err != nil {
			t.Fatalf("Failed to create %s, err: %s: ", testPth, err)
		}
		// eval symlinks: the Go generated temp folder on OS X is a symlink
		//  from /var/ to /private/var/
		testPth, err = filepath.EvalSymlinks(testPth)
		if err != nil {
			t.Fatalf("Failed to EvalSymlinks for (path:%s), err: %s", testPth, err)
		}

		defer func() {
			err := os.RemoveAll(testPth)
			if err != nil {
				t.Fatalf("Failed to remove %s, err: %s: ", testPth, err)
			}
		}()

		testPths = append(testPths, testPth)
	}

	//
	// BITRISE_SOURCE_DIR defined in Secret
	inventoryStr := `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
	inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
	require.Equal(t, nil, err)

	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  test:
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[0] + `" ]] ; then
              exit 1
            fi
`
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
	require.Equal(t, nil, err)

	//
	// BITRISE_SOURCE_DIR defined in Secret, and in App
	inventoryStr = `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
	inventory, err = bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
	require.Equal(t, nil, err)

	configStr = `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR: "` + testPths[1] + `"

workflows:
  test:
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[1] + `" ]] ; then
              exit 1
            fi
`
	config, err = bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
	require.Equal(t, nil, err)

	//
	// BITRISE_SOURCE_DIR defined in Secret, App and Workflow
	inventoryStr = `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
	inventory, err = bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
	require.Equal(t, nil, err)

	configStr = `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR: "` + testPths[1] + `"

workflows:
  test:
    envs:
    - BITRISE_SOURCE_DIR: "` + testPths[2] + `"
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[2] + `" ]] ; then
              exit 1
            fi
`
	config, err = bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
	require.Equal(t, nil, err)

	//
	// BITRISE_SOURCE_DIR defined in Secret, App and Workflow
	//  BUT the value is empty in Workflow and App Envs - Secrets should be used!
	inventoryStr = `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
	inventory, err = bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
	require.Equal(t, nil, err)

	configStr = `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR:

workflows:
  test:
    envs:
    - BITRISE_SOURCE_DIR: ""
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[0] + `" ]] ; then
              echo "-> BITRISE_SOURCE_DIR missmatch!"
              exit 1
            fi
            curr_pwd="$(pwd)"
            if [[ "${curr_pwd}" != "` + testPths[0] + `" ]] ; then
              echo "-> pwd missmatch! : curr_pwd : ${curr_pwd}"
              exit 1
            fi
`
	config, err = bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
	require.Equal(t, nil, err)

	//
	// BITRISE_SOURCE_DIR defined in secret, App, Workflow and Step
	inventoryStr = `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
	inventory, err = bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
	require.Equal(t, nil, err)

	configStr = `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR: "` + testPths[1] + `"

workflows:
  test:
    envs:
    - BITRISE_SOURCE_DIR: "` + testPths[2] + `"
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            envman add --key BITRISE_SOURCE_DIR --value ` + testPths[3] + `
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[3] + `" ]] ; then
              exit 1
            fi
`
	config, err = bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
	require.Equal(t, nil, err)
}
Esempio n. 25
0
// Test - Bitrise Environments
// Trivial test for workflow environment handling
// Before workflows env should be visible in target and after workflow
func TestWorkflowEnvironments(t *testing.T) {
	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  before:
    envs:
    - BEFORE_ENV: beforeenv

  target:
    title: target
    before_run:
    - before
    after_run:
    - after
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            if [[ "$BEFORE_ENV" != "beforeenv" ]] ; then
              exit 1
            fi

  after:
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            if [[ "$BEFORE_ENV" != "beforeenv" ]] ; then
              exit 1
            fi
    `
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	if err != nil {
		t.Fatal(err)
	}
	_, found := config.Workflows["target"]
	if !found {
		t.Fatal("No workflow found with ID (target)")
	}
	if err := config.Validate(); err != nil {
		t.Fatal(err)
	}

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "target", config, []envmanModels.EnvironmentItemModel{})
	t.Log("Err: ", err)
	t.Logf("Build run result: %#v", buildRunResults)
	if len(buildRunResults.SkippedSteps) != 0 {
		t.Fatalf("Skipped step count (%d), should be (0)", len(buildRunResults.SkippedSteps))
	}
	if len(buildRunResults.SuccessSteps) != 2 {
		t.Fatalf("Success step count (%d), should be (2)", len(buildRunResults.SuccessSteps))
	}
	if len(buildRunResults.FailedSteps) != 0 {
		t.Fatalf("Failed step count (%d), should be (0)", len(buildRunResults.FailedSteps))
	}
	if len(buildRunResults.FailedSkippableSteps) != 0 {
		t.Fatalf("FailedSkippable step count (%d), should be (0)", len(buildRunResults.FailedSkippableSteps))
	}

	if status := os.Getenv("BITRISE_BUILD_STATUS"); status != "0" {
		t.Log("BITRISE_BUILD_STATUS:", status)
		t.Fatal("BUILD_STATUS envs are incorrect")
	}
	if status := os.Getenv("STEPLIB_BUILD_STATUS"); status != "0" {
		t.Log("STEPLIB_BUILD_STATUS:", status)
		t.Fatal("STEPLIB_BUILD_STATUS envs are incorrect")
	}
}
Esempio n. 26
0
// Test - Bitrise Environments
// Step input should visible only for actual step and invisible for other steps
func TestStepInputEnvironment(t *testing.T) {
	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  before:
    steps:
    - script:
        inputs:
        - working_dir: $HOME

  target:
    title: target
    before_run:
    - before
    steps:
    - script:
        title: "${working_dir} should not exist"
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo ${ENV}
            if [ ! -z "$working_dir" ] ; then
              echo ${working_dir}
              exit 3
            fi
`
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	if err != nil {
		t.Fatal(err)
	}
	_, found := config.Workflows["target"]
	if !found {
		t.Fatal("No workflow found with ID (target)")
	}
	if err := config.Validate(); err != nil {
		t.Fatal(err)
	}

	if os.Getenv("working_dir") != "" {
		require.Equal(t, nil, os.Unsetenv("working_dir"))
	}

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "target", config, []envmanModels.EnvironmentItemModel{})
	t.Log("Err: ", err)
	t.Logf("Build run result: %#v", buildRunResults)
	if len(buildRunResults.SkippedSteps) != 0 {
		t.Fatalf("Skipped step count (%d), should be (0)", len(buildRunResults.SkippedSteps))
	}
	if len(buildRunResults.SuccessSteps) != 2 {
		t.Fatalf("Success step count (%d), should be (2)", len(buildRunResults.SuccessSteps))
	}
	if len(buildRunResults.FailedSteps) != 0 {
		t.Fatalf("Failed step count (%d), should be (0)", len(buildRunResults.FailedSteps))
	}
	if len(buildRunResults.FailedSkippableSteps) != 0 {
		t.Fatalf("FailedSkippable step count (%d), should be (0)", len(buildRunResults.FailedSkippableSteps))
	}

	if status := os.Getenv("BITRISE_BUILD_STATUS"); status != "0" {
		t.Log("BITRISE_BUILD_STATUS:", status)
		t.Fatal("BUILD_STATUS envs are incorrect")
	}
	if status := os.Getenv("STEPLIB_BUILD_STATUS"); status != "0" {
		t.Log("STEPLIB_BUILD_STATUS:", status)
		t.Fatal("STEPLIB_BUILD_STATUS envs are incorrect")
	}
}
Esempio n. 27
0
func TestGetWorkflowIDByPattern(t *testing.T) {
	configStr := `
trigger_map:
- pattern: master
  is_pull_request_allowed: false
  workflow: master
- pattern: feature/*
  is_pull_request_allowed: true
  workflow: feature
- pattern: "*"
  is_pull_request_allowed: true
  workflow: primary

workflows:
  test:
  master:
  feature:
  primary:
`

	//
	// Default pattern defined
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	// Non pull request mode
	configs.IsPullRequestMode = false

	workflowID, err := GetWorkflowIDByPattern(config, "master")
	require.Equal(t, nil, err)
	require.Equal(t, "master", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "feature/a")
	require.Equal(t, nil, err)
	require.Equal(t, "feature", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "feature/")
	require.Equal(t, nil, err)
	require.Equal(t, "feature", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "feature")
	require.Equal(t, nil, err)
	require.Equal(t, "primary", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "test")
	require.Equal(t, nil, err)
	require.Equal(t, "primary", workflowID)

	// Pull request mode
	configs.IsPullRequestMode = true

	workflowID, err = GetWorkflowIDByPattern(config, "master")
	require.Equal(t, nil, err)
	require.Equal(t, "primary", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "feature/a")
	require.Equal(t, nil, err)
	require.Equal(t, "feature", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "feature/")
	require.Equal(t, nil, err)
	require.Equal(t, "feature", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "feature")
	require.Equal(t, nil, err)
	require.Equal(t, "primary", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "test")
	require.Equal(t, nil, err)
	require.Equal(t, "primary", workflowID)

	configStr = `
  trigger_map:
  - pattern: master
    is_pull_request_allowed: false
    workflow: master
  - pattern: feature/*
    is_pull_request_allowed: true
    workflow: feature

  workflows:
    test:
    master:
    feature:
    primary:
  `

	//
	// No default pattern defined
	config, err = bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	// Non pull request mode
	configs.IsPullRequestMode = false

	workflowID, err = GetWorkflowIDByPattern(config, "master")
	require.Equal(t, nil, err)
	require.Equal(t, "master", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "feature/a")
	require.Equal(t, nil, err)
	require.Equal(t, "feature", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "feature/")
	require.Equal(t, nil, err)
	require.Equal(t, "feature", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "feature")
	require.NotEqual(t, nil, err)
	require.Equal(t, "", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "test")
	require.NotEqual(t, nil, err)
	require.Equal(t, "", workflowID)

	// Pull request mode
	configs.IsPullRequestMode = true

	workflowID, err = GetWorkflowIDByPattern(config, "master")
	require.NotEqual(t, nil, err)
	require.Equal(t, "", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "feature/a")
	require.Equal(t, nil, err)
	require.Equal(t, "feature", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "feature/")
	require.Equal(t, nil, err)
	require.Equal(t, "feature", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "feature")
	require.NotEqual(t, nil, err)
	require.Equal(t, "", workflowID)

	workflowID, err = GetWorkflowIDByPattern(config, "test")
	require.NotEqual(t, nil, err)
	require.Equal(t, "", workflowID)
}
Esempio n. 28
0
// Test - Bitrise BuildStatusEnv
// Checks if BuildStatusEnv is set correctly
func TestBuildStatusEnv(t *testing.T) {
	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  before1:
    steps:
    - script:
        title: Should success
    - script:
        title: Should fail, but skippable
        is_skippable: true
        inputs:
        - content: |
            #!/bin/bash
            set -v
            exit 2
    - script:
        title: Should success

  before2:
    steps:
    - script:
        title: Should success

  target:
    steps:
    - script:
        title: Should success
        inputs:
        - content: |
            #!/bin/bash
            set -v
            if [[ "$BITRISE_BUILD_STATUS" != "0" ]] ; then
              exit 1
            fi
            if [[ "$STEPLIB_BUILD_STATUS" != "0" ]] ; then
              exit 1
            fi
    - script:
        title: Should fail, but skippable
        is_skippable: true
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo 'This is a before workflow'
            exit 2
    - script:
        title: Should success
        inputs:
        - content: |
            #!/bin/bash
            set -v
            if [[ "$BITRISE_BUILD_STATUS" != "0" ]] ; then
              exit 1
            fi
            if [[ "$STEPLIB_BUILD_STATUS" != "0" ]] ; then
              exit 1
            fi
    - script:
        title: Should fail
        inputs:
        - content: |
            #!/bin/bash
            set -v
            exit 1
    - script:
        title: Should success
        is_always_run: true
        inputs:
        - content: |
            #!/bin/bash
            set -v
            if [[ "$BITRISE_BUILD_STATUS" != "1" ]] ; then
              echo "should fail"
            fi
            if [[ "$STEPLIB_BUILD_STATUS" != "1" ]] ; then
              echo "should fail"
            fi
    - script:
        title: Should skipped
  `
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	if err != nil {
		t.Fatal(err)
	}
	_, found := config.Workflows["target"]
	if !found {
		t.Fatal("No workflow found with ID (target)")
	}
	if err := config.Validate(); err != nil {
		t.Fatal(err)
	}

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "target", config, []envmanModels.EnvironmentItemModel{})
	t.Log("Err: ", err)
	t.Logf("Build run results: %#v\n", buildRunResults)
	if len(buildRunResults.SuccessSteps) != 3 {
		t.Fatalf("Success step count (%d), should be (3)", len(buildRunResults.SuccessSteps))
	}
	if len(buildRunResults.FailedSteps) != 1 {
		t.Fatalf("Failed step count (%d), should be (1)", len(buildRunResults.FailedSteps))
	}
	if len(buildRunResults.FailedSkippableSteps) != 1 {
		t.Fatalf("FailedSkippable step count (%d), should be (1)", len(buildRunResults.FailedSkippableSteps))
	}
	if len(buildRunResults.SkippedSteps) != 1 {
		t.Fatalf("Skipped step count (%d), should be (1)", len(buildRunResults.SkippedSteps))
	}

	if status := os.Getenv("BITRISE_BUILD_STATUS"); status != "1" {
		t.Log("BITRISE_BUILD_STATUS:", status)
		t.Fatal("BUILD_STATUS envs are incorrect")
	}
	if status := os.Getenv("STEPLIB_BUILD_STATUS"); status != "1" {
		t.Log("STEPLIB_BUILD_STATUS:", status)
		t.Fatal("STEPLIB_BUILD_STATUS envs are incorrect")
	}
}
Esempio n. 29
0
func TestBitriseSourceDir(t *testing.T) {
	currPth, err := pathutil.NormalizedOSTempDirPath("bitrise_source_dir_test")
	require.NoError(t, err)

	testPths := []string{}
	for i := 0; i < 4; i++ {
		testPth := filepath.Join(currPth, fmt.Sprintf("_test%d", i))
		require.NoError(t, os.RemoveAll(testPth))
		require.NoError(t, os.Mkdir(testPth, 0777))

		// eval symlinks: the Go generated temp folder on OS X is a symlink
		//  from /var/ to /private/var/
		testPth, err = filepath.EvalSymlinks(testPth)
		require.NoError(t, err)

		defer func() { require.NoError(t, os.RemoveAll(testPth)) }()

		testPths = append(testPths, testPth)
	}

	t.Log("BITRISE_SOURCE_DIR defined in Secret")
	{
		inventoryStr := `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  test:
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[0] + `" ]] ; then
              exit 1
            fi
`
		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}

	t.Log("BITRISE_SOURCE_DIR defined in Secret, and in App")
	{
		inventoryStr := `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR: "` + testPths[1] + `"

workflows:
  test:
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[1] + `" ]] ; then
              exit 1
            fi
`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}

	t.Log("BITRISE_SOURCE_DIR defined in Secret, App and Workflow")
	{
		inventoryStr := `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR: "` + testPths[1] + `"

workflows:
  test:
    envs:
    - BITRISE_SOURCE_DIR: "` + testPths[2] + `"
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[2] + `" ]] ; then
              exit 1
            fi
`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}

	t.Log("BITRISE_SOURCE_DIR defined in secret, App, Workflow and Step")
	{
		inventoryStr := `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR: "` + testPths[1] + `"

workflows:
  test:
    envs:
    - BITRISE_SOURCE_DIR: "` + testPths[2] + `"
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            envman add --key BITRISE_SOURCE_DIR --value ` + testPths[3] + `
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[3] + `" ]] ; then
              exit 1
            fi
`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}
}
Esempio n. 30
0
// Test - Bitrise activateAndRunWorkflow
// Trivial test with 1 workflow
func Test1Workflows(t *testing.T) {
	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  trivial_fail:
    steps:
    - script:
        title: Should success
    - script:
        title: Should fail, but skippable
        is_skippable: true
        inputs:
        - content: |
            #!/bin/bash
            set -v
            exit 2
    - script:
        title: Should success
    - script:
        title: Should fail
        inputs:
        - content: |
            #!/bin/bash
            set -v
            exit 2
    - script:
        title: Should success
        is_always_run: true
    - script:
        title: Should skipped
  `
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	if err != nil {
		t.Fatal(err)
	}
	workflow, found := config.Workflows["trivial_fail"]
	if !found {
		t.Fatal("No workflow found with ID (trivial_fail)")
	}
	if err := config.Validate(); err != nil {
		t.Fatal(err)
	}

	buildRunResults := models.BuildRunResultsModel{
		StartTime:      time.Now(),
		StepmanUpdates: map[string]int{},
	}
	buildRunResults, err = activateAndRunWorkflow("trivial_fail", workflow, config, buildRunResults, &[]envmanModels.EnvironmentItemModel{}, "")
	if err != nil {
		t.Fatal("Failed to activate and run worfklow:", err)
	}
	if len(buildRunResults.SuccessSteps) != 3 {
		t.Fatalf("Success step count (%d), should be (3)", len(buildRunResults.SuccessSteps))
	}
	if len(buildRunResults.FailedSteps) != 1 {
		t.Fatalf("Failed step count (%d), should be (1)", len(buildRunResults.FailedSteps))
	}
	if len(buildRunResults.FailedSkippableSteps) != 1 {
		t.Fatalf("FailedSkippable step count (%d), should be (1)", len(buildRunResults.FailedSkippableSteps))
	}
	if len(buildRunResults.SkippedSteps) != 1 {
		t.Fatalf("Skipped step count (%d), should be (1)", len(buildRunResults.SkippedSteps))
	}

	if status := os.Getenv("BITRISE_BUILD_STATUS"); status != "1" {
		t.Log("BITRISE_BUILD_STATUS:", status)
		t.Fatal("BUILD_STATUS envs are incorrect")
	}
	if status := os.Getenv("STEPLIB_BUILD_STATUS"); status != "1" {
		t.Log("STEPLIB_BUILD_STATUS:", status)
		t.Fatal("STEPLIB_BUILD_STATUS envs are incorrect")
	}
}