-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathmain.go
118 lines (99 loc) · 3.87 KB
/
main.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
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
package main
import (
"errors"
"fmt"
"os"
"github.com/bitrise-io/go-steputils/v2/stepconf"
"github.com/bitrise-io/go-utils/v2/command"
"github.com/bitrise-io/go-utils/v2/env"
"github.com/bitrise-io/go-utils/v2/fileutil"
"github.com/bitrise-io/go-utils/v2/log"
"github.com/bitrise-io/go-utils/v2/pathutil"
"github.com/bitrise-steplib/steps-xcode-archive/step"
)
func main() {
os.Exit(run())
}
func run() int {
logger := log.NewLogger()
archiver := createXcodebuildArchiver(logger)
config, err := archiver.ProcessInputs()
if err != nil {
logger.Errorf(formattedError(fmt.Errorf("Failed to process Step inputs: %w", err)))
return 1
}
dependenciesOpts := step.EnsureDependenciesOpts{
XCPretty: config.LogFormatter == "xcpretty",
}
if err := archiver.EnsureDependencies(dependenciesOpts); err != nil {
var xcprettyInstallErr step.XCPrettyInstallError
if errors.As(err, &xcprettyInstallErr) {
logger.Warnf("Installing xcpretty failed: %s", err)
logger.Warnf("Switching to xcodebuild for log formatter")
config.LogFormatter = "xcodebuild"
} else {
logger.Errorf(formattedError(fmt.Errorf("Failed to install Step dependencies: %w", err)))
return 1
}
}
exitCode := 0
runOpts := createRunOptions(config)
result, err := archiver.Run(runOpts)
if err != nil {
logger.Errorf(formattedError(fmt.Errorf("Failed to execute Step main logic: %w", err)))
exitCode = 1
// don't return as step outputs needs to be exported even in case of failure (for example the xcodebuild logs)
}
exportOpts := createExportOptions(config, result)
if err := archiver.ExportOutput(exportOpts); err != nil {
logger.Errorf(formattedError(fmt.Errorf("Failed to export Step outputs: %w", err)))
return 1
}
return exitCode
}
func createXcodebuildArchiver(logger log.Logger) step.XcodebuildArchiver {
xcodeVersionProvider := step.NewXcodebuildXcodeVersionProvider()
envRepository := env.NewRepository()
inputParser := stepconf.NewInputParser(envRepository)
pathProvider := pathutil.NewPathProvider()
pathChecker := pathutil.NewPathChecker()
pathModifier := pathutil.NewPathModifier()
fileManager := fileutil.NewFileManager()
cmdFactory := command.NewFactory(envRepository)
return step.NewXcodebuildArchiver(xcodeVersionProvider, inputParser, pathProvider, pathChecker, pathModifier, fileManager, logger, cmdFactory)
}
func createRunOptions(config step.Config) step.RunOpts {
return step.RunOpts{
ProjectPath: config.ProjectPath,
Scheme: config.Scheme,
Configuration: config.Configuration,
LogFormatter: config.LogFormatter,
XcodeMajorVersion: config.XcodeMajorVersion,
ArtifactName: config.ArtifactName,
CodesignManager: config.CodesignManager,
PerformCleanAction: config.PerformCleanAction,
XcconfigContent: config.XcconfigContent,
XcodebuildAdditionalOptions: config.XcodebuildAdditionalOptions,
CacheLevel: config.CacheLevel,
CustomExportOptionsPlistContent: config.ExportOptionsPlistContent,
ExportMethod: config.ExportMethod,
TestFlightInternalTestingOnly: config.TestFlightInternalTestingOnly,
ICloudContainerEnvironment: config.ICloudContainerEnvironment,
ExportDevelopmentTeam: config.ExportDevelopmentTeam,
UploadBitcode: config.UploadBitcode,
CompileBitcode: config.CompileBitcode,
}
}
func createExportOptions(config step.Config, result step.RunResult) step.ExportOpts {
return step.ExportOpts{
OutputDir: config.OutputDir,
ArtifactName: result.ArtifactName,
ExportAllDsyms: config.ExportAllDsyms,
Archive: result.Archive,
ExportOptionsPath: result.ExportOptionsPath,
IPAExportDir: result.IPAExportDir,
XcodebuildArchiveLog: result.XcodebuildArchiveLog,
XcodebuildExportArchiveLog: result.XcodebuildExportArchiveLog,
IDEDistrubutionLogsDir: result.IDEDistrubutionLogsDir,
}
}