Skip to content

Commit

Permalink
high-level logs for the step
Browse files Browse the repository at this point in the history
  • Loading branch information
shams-ahmed committed May 12, 2022
1 parent 16729ba commit c052ef0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
38 changes: 34 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,23 @@ func findIDEDistrubutionLogsPath(output string) (string, error) {
pattern := `IDEDistribution: -\[IDEDistributionLogging _createLoggingBundleAtPath:\]: Created bundle at path '(?P<log_path>.*)'`
re := regexp.MustCompile(pattern)

logger.Printf("Locating IDE distrubution logs path")

scanner := bufio.NewScanner(strings.NewReader(output))
for scanner.Scan() {
line := scanner.Text()
if match := re.FindStringSubmatch(line); len(match) == 2 {
logger.Printf("Located IDE distrubution logs path")

return match[1], nil
}
}
if err := scanner.Err(); err != nil {
return "", err
}

logger.Printf("IDE distrubution logs path not found")

return "", nil
}

Expand Down Expand Up @@ -452,16 +458,22 @@ func (s XcodeArchiveStep) xcodeArchive(opts xcodeArchiveOpts) (xcodeArchiveOutpu
out := xcodeArchiveOutput{}

// Open Xcode project
logger.TInfof("Opening xcode project at path: %s for scheme: %s", opts.ProjectPath, opts.Scheme)

xcodeProj, scheme, configuration, err := utils.OpenArchivableProject(opts.ProjectPath, opts.Scheme, opts.Configuration)
if err != nil {
return out, fmt.Errorf("failed to open project: %s: %s", opts.ProjectPath, err)
}

logger.TInfof("Reading xcode project")

platform, err := utils.BuildableTargetPlatform(xcodeProj, scheme, configuration, utils.XcodeBuild{})
if err != nil {
return out, fmt.Errorf("failed to read project platform: %s: %s", opts.ProjectPath, err)
}

logger.TInfof("Reading main target")

mainTarget, err := exportoptionsgenerator.ArchivableApplicationTarget(xcodeProj, scheme)
if err != nil {
return out, fmt.Errorf("failed to read main application target: %s", err)
Expand All @@ -476,7 +488,7 @@ func (s XcodeArchiveStep) xcodeArchive(opts xcodeArchiveOpts) (xcodeArchiveOutpu

// Create the Archive with Xcode Command Line tools
logger.Println()
logger.Infof("Creating the Archive ...")
logger.TInfof("Creating the Archive ...")

isWorkspace := false
ext := filepath.Ext(opts.ProjectPath)
Expand Down Expand Up @@ -538,6 +550,8 @@ func (s XcodeArchiveStep) xcodeArchive(opts xcodeArchiveOpts) (xcodeArchiveOutpu
}
}

logger.Infof("Starting the Archive ...")

xcodebuildLog, err := runArchiveCommandWithRetry(archiveCmd, opts.LogFormatter == "xcpretty", swiftPackagesPath)
out.XcodebuildArchiveLog = xcodebuildLog
if err != nil || opts.LogFormatter == "xcodebuild" {
Expand Down Expand Up @@ -660,6 +674,8 @@ func (s XcodeArchiveStep) xcodeIPAExport(opts xcodeIPAExportOpts) (xcodeIPAExpor
return out, err
}

logger.TPrintf("Opening Xcode project at path: %s.", opts.ProjectPath)

xcodeProj, scheme, configuration, err := utils.OpenArchivableProject(opts.ProjectPath, opts.Scheme, opts.Configuration)
if err != nil {
return out, fmt.Errorf("failed to open project: %s: %s", opts.ProjectPath, err)
Expand Down Expand Up @@ -700,6 +716,8 @@ func (s XcodeArchiveStep) xcodeIPAExport(opts xcodeIPAExportOpts) (xcodeIPAExpor
fmt.Println()
logWithTimestamp(colorstring.Green, xcprettyCmd.PrintableCmd())

logger.Infof("Running export ipa from the archive command.")

xcodebuildLog, exportErr := xcprettyCmd.Run()
out.XcodebuildExportArchiveLog = xcodebuildLog
if exportErr != nil {
Expand Down Expand Up @@ -731,6 +749,8 @@ is available in the $BITRISE_IDEDISTRIBUTION_LOGS_PATH environment variable`)
fmt.Println()
logWithTimestamp(colorstring.Green, exportCmd.PrintableCmd())

logger.Infof("Running export ipa from the archive command.")

xcodebuildLog, exportErr := exportCmd.RunAndReturnOutput()
out.XcodebuildExportArchiveLog = xcodebuildLog
if exportErr != nil {
Expand Down Expand Up @@ -817,6 +837,7 @@ func (s XcodeArchiveStep) Run(opts RunOpts) (RunOut, error) {

logger.Println()
if opts.XcodeMajorVersion >= 11 {
logger.Infof("Running resolve Swift package dependencies")
// Resolve Swift package dependencies, so running -showBuildSettings later is faster later
// Specifying a scheme is required for workspaces
resolveDepsCmd := xcodebuild.NewResolvePackagesCommandModel(opts.ProjectPath, opts.Scheme, opts.Configuration)
Expand All @@ -827,6 +848,8 @@ func (s XcodeArchiveStep) Run(opts RunOpts) (RunOut, error) {
}

if opts.ArtifactName == "" {
logger.Infof("Looking for artifact name as field is empty")

cmdModel := xcodebuild.NewShowBuildSettingsCommand(opts.ProjectPath)
cmdModel.SetScheme(opts.Scheme)
cmdModel.SetConfiguration(opts.Configuration)
Expand Down Expand Up @@ -987,27 +1010,34 @@ func (s XcodeArchiveStep) ExportOutput(opts ExportOpts) error {
}
logger.Donef("The app directory is now available in the Environment Variable: %s (value: %s)", bitriseAppDirPthEnvKey, appPath)

logger.Printf("Looking for app and framework dSYMs.")

appDSYMPaths, frameworkDSYMPaths, err := opts.Archive.FindDSYMs()
if err != nil {
return fmt.Errorf("failed to export dSYMs, error: %s", err)
}

if len(appDSYMPaths) > 0 || len(frameworkDSYMPaths) > 0 {
appDSYMPathsCount := len(appDSYMPaths)
frameworkDSYMPathsCount := len(frameworkDSYMPaths)

logger.Printf("Found %s app dSYMs and framework dSYMs %s.", appDSYMPathsCount, frameworkDSYMPathsCount)

if appDSYMPathsCount > 0 || frameworkDSYMPathsCount > 0 {
fmt.Println()
dsymDir, err := v1pathutil.NormalizedOSTempDirPath("__dsyms__")
if err != nil {
return fmt.Errorf("failed to create tmp dir, error: %s", err)
}

if len(appDSYMPaths) > 0 {
if appDSYMPathsCount > 0 {
if err := exportDSYMs(dsymDir, appDSYMPaths); err != nil {
return fmt.Errorf("failed to export dSYMs: %v", err)
}
} else {
logger.Warnf("No app dSYMs found to export")
}

if opts.ExportAllDsyms && len(frameworkDSYMPaths) > 0 {
if opts.ExportAllDsyms && frameworkDSYMPathsCount > 0 {
if err := exportDSYMs(dsymDir, frameworkDSYMPaths); err != nil {
return fmt.Errorf("failed to export dSYMs: %v", err)
}
Expand Down
17 changes: 17 additions & 0 deletions utils/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"path/filepath"
"strings"
"time"

v1command "github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/fileutil"
Expand All @@ -12,6 +13,10 @@ import (
)

func zip(cmdFactory command.Factory, sourceDir, destinationZipPth string) error {
var start = time.Now()

fmt.Printf("Will zip directory path: %s", sourceDir)

parentDir := filepath.Dir(sourceDir)
dirName := filepath.Base(sourceDir)
cmd := cmdFactory.Create("/usr/bin/zip", []string{"-rTy", destinationZipPth, dirName}, &command.Opts{Dir: parentDir})
Expand All @@ -20,6 +25,8 @@ func zip(cmdFactory command.Factory, sourceDir, destinationZipPth string) error
return fmt.Errorf("failed to zip dir: %s, output: %s, error: %s", sourceDir, out, err)
}

fmt.Printf("Directory zipped in %s.", time.Since(start).Round(time.Second))

return nil
}

Expand All @@ -31,11 +38,15 @@ func exportEnvironmentWithEnvman(cmdFactory command.Factory, keyStr, valueStr st
// ExportOutputDir ...
func ExportOutputDir(cmdFactory command.Factory, sourceDirPth, destinationDirPth, envKey string) error {
if sourceDirPth != destinationDirPth {
fmt.Printf("Coping export output")

if err := v1command.CopyDir(sourceDirPth, destinationDirPth, true); err != nil {
return err
}
}

fmt.Printf("Copied export output to %s", destinationDirPth)

return exportEnvironmentWithEnvman(cmdFactory, envKey, destinationDirPth)
}

Expand All @@ -61,6 +72,10 @@ func ExportOutputFileContent(cmdFactory command.Factory, content, destinationPth

// ExportOutputDirAsZip ...
func ExportOutputDirAsZip(cmdFactory command.Factory, sourceDirPth, destinationPth, envKey string) error {
var start = time.Now()

fmt.Printf("Will zip directory path: %s", sourceDirPth)

tmpDir, err := pathutil.NormalizedOSTempDirPath("__export_tmp_dir__")
if err != nil {
return err
Expand All @@ -73,5 +88,7 @@ func ExportOutputDirAsZip(cmdFactory command.Factory, sourceDirPth, destinationP
return err
}

fmt.Printf("Directory zipped in %s.", time.Since(start).Round(time.Second))

return ExportOutputFile(cmdFactory, tmpZipFilePth, destinationPth, envKey)
}
8 changes: 7 additions & 1 deletion utils/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func BuildableTargetPlatform(
configurationName string,
provider TargetBuildSettingsProvider,
) (Platform, error) {
fmt.Printf("Finding platform type")

archiveEntry, ok := scheme.AppBuildActionEntry()
if !ok {
return "", fmt.Errorf("archivable entry not found in project: %s, scheme: %s", xcodeProj.Path, scheme.Name)
Expand All @@ -88,7 +90,11 @@ func BuildableTargetPlatform(
return "", fmt.Errorf("failed to get target (%s) build settings: %s", mainTarget.Name, err)
}

return getPlatform(settings)
platform, err := getPlatform(settings)

fmt.Printf("Platform type: %s", platform)

return platform, err
}

func getPlatform(buildSettings serialized.Object) (Platform, error) {
Expand Down

0 comments on commit c052ef0

Please sign in to comment.