Skip to content

Commit

Permalink
fix: Ensure app is a path before archiving (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
FriggaHel authored May 29, 2023
1 parent 24c4ef8 commit 85c8eca
Showing 1 changed file with 34 additions and 25 deletions.
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

0 comments on commit 85c8eca

Please sign in to comment.