-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive.go
55 lines (46 loc) · 1.69 KB
/
archive.go
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
package main
import (
"bytes"
"fmt"
"os"
"strings"
"time"
"github.com/bitrise-io/go-utils/colorstring"
"github.com/bitrise-io/go-utils/log"
"github.com/bitrise-io/go-utils/progress"
"github.com/bitrise-io/go-xcode/xcodebuild"
cache "github.com/bitrise-io/go-xcode/xcodecache"
"github.com/bitrise-io/go-xcode/xcpretty"
)
func runArchiveCommandWithRetry(archiveCmd *xcodebuild.CommandBuilder, useXcpretty bool, swiftPackagesPath string) (string, error) {
output, err := runArchiveCommand(archiveCmd, useXcpretty)
if err != nil && swiftPackagesPath != "" && strings.Contains(output, cache.SwiftPackagesStateInvalid) {
log.Warnf("Archive failed, swift packages cache is in an invalid state, error: %s", err)
log.RWarnf("xcode-archive", "swift-packages-cache-invalid", nil, "swift packages cache is in an invalid state")
if err := os.RemoveAll(swiftPackagesPath); err != nil {
return output, fmt.Errorf("failed to remove invalid Swift package caches, error: %s", err)
}
return runArchiveCommand(archiveCmd, useXcpretty)
}
return output, err
}
func runArchiveCommand(archiveCmd *xcodebuild.CommandBuilder, useXcpretty bool) (string, error) {
if useXcpretty {
xcprettyCmd := xcpretty.New(archiveCmd)
logWithTimestamp(colorstring.Green, "$ %s", xcprettyCmd.PrintableCmd())
fmt.Println()
return xcprettyCmd.Run()
}
// Using xcodebuild
logWithTimestamp(colorstring.Green, "$ %s", archiveCmd.PrintableCmd())
fmt.Println()
archiveRootCmd := archiveCmd.Command()
var output bytes.Buffer
archiveRootCmd.SetStdout(&output)
archiveRootCmd.SetStderr(&output)
var err error
progress.SimpleProgress(".", time.Minute, func() {
err = archiveRootCmd.Run()
})
return output.String(), err
}