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

fix: Ensure app is a path before archiving #787

Merged
merged 3 commits into from
May 29, 2023
Merged
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
59 changes: 34 additions & 25 deletions internal/saucecloud/xcuitest.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/rs/zerolog/log"

"github.com/saucelabs/saucectl/internal/apps"
"github.com/saucelabs/saucectl/internal/archive/zip"
"github.com/saucelabs/saucectl/internal/config"
"github.com/saucelabs/saucectl/internal/job"
Expand Down Expand Up @@ -176,37 +177,45 @@ func (r *XcuitestRunner) calculateJobsCount(suites []xcuitest.Suite) int {
}

// archiveAppsToIpaIfRequired checks if apps are a .ipa package. Otherwise, it generates one.
func archiveAppsToIpaIfRequired(project *xcuitest.Project) (err error) {
appPath := project.Xcuitest.App
if !strings.HasSuffix(appPath, ".ipa") {
project.Xcuitest.App, err = archiveAppToIpa(appPath)
if err != nil {
log.Error().Msgf("Unable to archive %s to ipa: %v", appPath, err)
err = fmt.Errorf("unable to archive %s", appPath)
return
}
}
func archiveAppsToIpaIfRequired(project *xcuitest.Project) error {
var err error
cache := map[string]string{}
project.Xcuitest.App, err = archiveAppToIpaIfRequired(project.Xcuitest.App, cache)
if err != nil {
return err
}

for i, s := range project.Suites {
if strings.HasSuffix(s.TestApp, ".ipa") {
continue
project.Suites[i].TestApp, err = archiveAppToIpaIfRequired(s.TestApp, cache)
if err != nil {
return err
}
}
return nil
}

if val, ok := cache[s.TestApp]; ok {
project.Suites[i].TestApp = val
continue
}
func archiveAppToIpaIfRequired(appPath string, cache map[string]string) (string, error) {
if apps.IsStorageReference(appPath) {
return appPath, nil
}

var testAppPath string
testAppPath, err = archiveAppToIpa(s.TestApp)
if err != nil {
log.Error().Msgf("Unable to archive %s to ipa: %v", s.TestApp, err)
return fmt.Errorf("unable to archive %s: %w", s.TestApp, err)
}
project.Suites[i].TestApp = testAppPath
cache[s.TestApp] = testAppPath
if strings.HasSuffix(appPath, ".ipa") {
return appPath, nil
}

if cachedApp, ok := cache[appPath]; ok {
return cachedApp, nil
}
return

archivedApp, err := archiveAppToIpa(appPath)
if err != nil {
log.Error().Msgf("Unable to archive %s to ipa: %v", appPath, err)
err = fmt.Errorf("unable to archive %s", appPath)
return "", err
}

cache[appPath] = archivedApp
return archivedApp, nil
}

// archiveAppToIpa generates a valid IPA file from a .app folder.
Expand Down