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

Supported dynamic file name #8

Merged
merged 8 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ title: |-
summary: |
Run your XCUITest tests on BrowserStack App Automate
description: |
Run your XCUITest tests on BrowserStack App Automate. This step collects the built IPA from $BITRISE_IPA_PATH and test suite from `$BITRISE_BUNDLE_PATH` Environment Variables
Run your XCUITest tests on BrowserStack App Automate. This step collects the built IPA from `$BITRISE_IPA_PATH` and test suite from `$BITRISE_BUNDLE_PATH` Environment Variables
website: https://github.com/browserstack/browserstack-bitrise-xcui-step
source_code_url: https://github.com/browserstack/browserstack-bitrise-xcui-step
support_url: https://github.com/browserstack/browserstack-bitrise-xcui-step/issues
Expand Down Expand Up @@ -191,10 +191,10 @@ inputs:
Enable test sharding to split tests cases into different groups instead of running them sequentially.
Add the sharding value json here. Examples:
Input for only-testing strategy:
{"numberOfShards": 2, "mapping": [{"name": "Shard 1", "strategy": "only-testing", "values": ["SampleXCUITestsClass/testAlert", "SampleXCUITestsClass/testText"]}, {"name": "Shard 2", "strategy": "only-testing", "values": ["SampleXCUITestsClass/testLogin"]}]}
`{"numberOfShards": 2, "mapping": [{"name": "Shard 1", "strategy": "only-testing", "values": ["SampleXCUITestsClass/testAlert", "SampleXCUITestsClass/testText"]}, {"name": "Shard 2", "strategy": "only-testing", "values": ["SampleXCUITestsClass/testLogin"]}]}`

Input for skip-testing strategy:
{"numberOfShards": 2, "mapping": [{"name": "Shard 1", "strategy": "skip-testing", "values": ["SampleXCUITestsClass/testAlert"]}, {"name": "Shard 2", "strategy": "skip-testing", "values": ["SampleXCUITestsClass/testText"]}]}
`{"numberOfShards": 2, "mapping": [{"name": "Shard 1", "strategy": "skip-testing", "values": ["SampleXCUITestsClass/testAlert"]}, {"name": "Shard 2", "strategy": "skip-testing", "values": ["SampleXCUITestsClass/testText"]}]}`
category: 'Test Configuration'
- filter_test:
opts:
Expand Down Expand Up @@ -245,11 +245,11 @@ outputs:
- BROWSERSTACK_BUILD_URL:
opts:
title: 'BrowserStack Dashboard url'
summary: ''
summary: 'BrowserStack Dashboard url for the executed build'
description: 'BrowserStack Dashboard url for the executed build'
- BROWSERSTACK_BUILD_STATUS:
opts:
title: 'BrowserStack Build Status'
summary: Bs build status
summary: BrowserStack build status
description: |
Status of the executed build. Check values [here:] (https://www.browserstack.com/docs/app-automate/xcui/view-test-results)
Status of the executed build. Check values [here:] (https://www.browserstack.com/docs/app-automate/xcui/view-test-results)
33 changes: 28 additions & 5 deletions util_fns.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"encoding/json"
"errors"
"fmt"
"io/fs"
"log"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -251,6 +253,23 @@ func printBuildStatus(build_details map[string]interface{}) {
table.Render()
}

// find all the files from the directory which matches the pattern eg: *.md
func WalkMatch(root, ext string) []string {
var files_found []string
filepath.WalkDir(root, func(path string, d fs.DirEntry, e error) error {
if e != nil {
return e
}
if matched, err := filepath.Match(ext, filepath.Base(path)); err != nil {
return err
} else if matched {
files_found = append(files_found, path)
}
return nil
})
return files_found
}

func locateTestRunnerFileAndZip(test_suite_location string) error {
split_test_suite_path := strings.Split(test_suite_location, "/")
get_file_name := split_test_suite_path[len(split_test_suite_path)-1]
Expand All @@ -261,26 +280,30 @@ func locateTestRunnerFileAndZip(test_suite_location string) error {

// Checking 2 conditions here
// 1. test_suite_location - is this runner app
// 2. test_suite_location - if this is a directory, does runner app exists in this directory.
// 2. test_suite_location - if this is a directory, does any runner app exists in this directory.
if len(check_file_extension) > 0 && check_file_extension[len(check_file_extension)-1] == "app" {
test_runner_app_path = test_suite_location
} else if strings.Contains(get_file_name, "test_bundle") {
// if test_suite_location is a directory instead of the file, then check if runner app exits
if _, err := os.Stat(test_suite_location + TEST_RUNNER_RELATIVE_PATH_BITRISE); errors.Is(err, os.ErrNotExist) {
files := WalkMatch(test_suite_location+"/Debug-iphoneos/", "*-Runner.app")

if len(files) < 1 {
return errors.New(RUNNER_APP_NOT_FOUND)
} else {
test_runner_app_path = test_suite_location + TEST_RUNNER_RELATIVE_PATH_BITRISE
}
test_runner_app_path = files[len(files)-1]
} else {
return errors.New(RUNNER_APP_NOT_FOUND)
}

file_path := strings.Split(test_runner_app_path, "/")
test_runner_file_name := file_path[len(file_path)-1]

_, err := exec.Command("cp", "-r", test_runner_app_path, ".").Output()
if err != nil {
return errors.New(fmt.Sprintf(FILE_ZIP_ERROR, err))
}

_, zipping_err := exec.Command("zip", "-r", "-D", TEST_RUNNER_ZIP_FILE_NAME, "Tests iOS-Runner.app").Output()
_, zipping_err := exec.Command("zip", "-r", "-D", TEST_RUNNER_ZIP_FILE_NAME, test_runner_file_name).Output()
if zipping_err != nil {
return errors.New(fmt.Sprintf(FILE_ZIP_ERROR, zipping_err))
}
Expand Down