-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.go
More file actions
119 lines (81 loc) · 3 KB
/
main.go
File metadata and controls
119 lines (81 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strconv"
"time"
)
func main() {
// Exit after 2hours 30 mins
time.AfterFunc(150*time.Minute, func() { failf("Session Timed Out") })
log.Print("Starting the build on BrowserStack App Automate")
username := os.Getenv("browserstack_username")
access_key := os.Getenv("browserstack_accesskey")
ios_app := os.Getenv("app_ipa_path")
test_suite_path := os.Getenv("xcui_test_suite")
if username == "" || access_key == "" {
failf(UPLOAD_APP_ERROR, "invalid credentials")
}
if ios_app == "" {
failf(IPA_NOT_FOUND)
}
if test_suite_path == "" {
failf(RUNNER_APP_NOT_FOUND)
}
find_and_zip_file_err := locateTestRunnerFileAndZip(test_suite_path)
if find_and_zip_file_err != nil {
failf(find_and_zip_file_err.Error())
}
test_runner_app := TEST_RUNNER_ZIP_FILE_NAME
log.Print("Uploading app on BrowserStack App Automate")
upload_app, err := upload(ios_app, APP_UPLOAD_ENDPOINT, username, access_key)
if err != nil {
failf(err.Error())
}
upload_app_parsed_response := jsonParse(upload_app)
if upload_app_parsed_response["app_url"] == "" {
failf(err.Error())
}
log.Print("Successfully uploaded the app")
app_url := upload_app_parsed_response["app_url"].(string)
log.Print("Uploading test suite on BrowserStack App Automate")
upload_test_suite, err := upload(test_runner_app, TEST_SUITE_UPLOAD_ENDPOINT, username, access_key)
if err != nil {
failf(err.Error())
}
test_suite_upload_parsed_response := jsonParse(upload_test_suite)
if test_suite_upload_parsed_response["test_suite_url"] == "" {
failf(err.Error())
}
log.Print("Successfully uploaded the test suite")
test_suite_url := test_suite_upload_parsed_response["test_suite_url"].(string)
build_response, err := build(app_url, test_suite_url, username, access_key)
if err != nil {
failf(err.Error())
}
build_parsed_response := jsonParse(build_response)
if build_parsed_response["message"] != "Success" {
failf(BUILD_FAILED_ERROR, build_parsed_response["message"])
}
log.Print("Successfully started the build")
check_build_status, _ := strconv.ParseBool(os.Getenv("check_build_status"))
build_status := ""
build_id := build_parsed_response["build_id"].(string)
build_status, err = checkBuildStatus(build_id, username, access_key, check_build_status)
if err != nil {
failf(err.Error())
}
cmd_log_build_id, err_build_id := exec.Command("bitrise", "envman", "add", "--key", "BROWSERSTACK_BUILD_URL", "--value", APP_AUTOMATE_BUILD_DASHBOARD_URL+build_parsed_response["build_id"].(string)).CombinedOutput()
cmd_log_build_status, err_build_status := exec.Command("bitrise", "envman", "add", "--key", "BROWSERSTACK_BUILD_STATUS", "--value", build_status).CombinedOutput()
if err_build_id != nil {
fmt.Printf("Failed to expose output with envman, error: %#v | output: %s", err, cmd_log_build_id)
os.Exit(1)
}
if err_build_status != nil {
fmt.Printf("Failed to expose output with envman, error: %#v | output: %s", err, cmd_log_build_status)
os.Exit(1)
}
os.Exit(0)
}