Skip to content

Commit

Permalink
Always deploy xcodebuild archive and exportArchive command logs. (#238)
Browse files Browse the repository at this point in the history
* Always deploy xcodebuild archive and exportArchive command logs.

* Improve BITRISE_IDEDISTRIBUTION_LOGS_PATH step output description.

* Fix output check step reference.

* Fix output-check step validation.

* Add description to BITRISE_XCODEBUILD_ARCHIVE_LOG_PATH and BITRISE_XCODEBUILD_EXPORT_ARCHIVE_LOG_PATH.

* check-outputs Step moved to a separate repository.
  • Loading branch information
godrei authored Jun 25, 2021
1 parent 18743b1 commit 08d24ce
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 58 deletions.
27 changes: 15 additions & 12 deletions e2e/bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,23 @@ workflows:

_check_outputs:
steps:
- script:
title: Output (generated by the Step) tests
- git::https://github.com/bitrise-steplib/bitrise-step-check-step-outputs.git@main:
is_always_run: true
inputs:
- content: |-
echo "-> BITRISE_IPA_PATH: $BITRISE_IPA_PATH"
echo "-> BITRISE_DSYM_PATH: $BITRISE_DSYM_PATH"
echo "-> BITRISE_XCARCHIVE_ZIP_PATH: $BITRISE_XCARCHIVE_ZIP_PATH"
echo "-> BITRISE_APP_DIR_PATH: $BITRISE_APP_DIR_PATH"
echo "-> BITRISE_DSYM_DIR_PATH: $BITRISE_DSYM_DIR_PATH"
echo "-> BITRISE_XCARCHIVE_PATH: $BITRISE_XCARCHIVE_PATH"
echo "-> BITRISE_IDEDISTRIBUTION_LOGS_PATH: $BITRISE_IDEDISTRIBUTION_LOGS_PATH"
echo "-> BITRISE_XCODE_RAW_RESULT_TEXT_PATH: $BITRISE_XCODE_RAW_RESULT_TEXT_PATH"
- envs:
- files:
- dirs: |-
BITRISE_APP_DIR_PATH
BITRISE_DSYM_DIR_PATH
BITRISE_XCARCHIVE_PATH
- deploy_dir: $BITRISE_DEPLOY_DIR
- deployed_files: |-
BITRISE_IPA_PATH
BITRISE_DSYM_PATH
BITRISE_XCARCHIVE_ZIP_PATH
BITRISE_XCODEBUILD_ARCHIVE_LOG_PATH
BITRISE_XCODEBUILD_EXPORT_ARCHIVE_LOG_PATH
- deployed_dirs:

_check_exported_artifacts:
steps:
Expand Down
101 changes: 60 additions & 41 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@ const (
)

const (
bitriseXcodeRawResultTextEnvKey = "BITRISE_XCODE_RAW_RESULT_TEXT_PATH"
bitriseIDEDistributionLogsPthEnvKey = "BITRISE_IDEDISTRIBUTION_LOGS_PATH"
bitriseXCArchivePthEnvKey = "BITRISE_XCARCHIVE_PATH"
bitriseXCArchiveZipPthEnvKey = "BITRISE_XCARCHIVE_ZIP_PATH"
bitriseAppDirPthEnvKey = "BITRISE_APP_DIR_PATH"
bitriseIPAPthEnvKey = "BITRISE_IPA_PATH"
bitriseDSYMDirPthEnvKey = "BITRISE_DSYM_DIR_PATH"
bitriseDSYMPthEnvKey = "BITRISE_DSYM_PATH"
// Deployed Outputs (moved to the OutputDir)
bitriseXCArchiveZipPthEnvKey = "BITRISE_XCARCHIVE_ZIP_PATH"
bitriseDSYMPthEnvKey = "BITRISE_DSYM_PATH"
bitriseIPAPthEnvKey = "BITRISE_IPA_PATH"
// Deployed logs
xcodebuildArchiveLogPathEnvKey = "BITRISE_XCODEBUILD_ARCHIVE_LOG_PATH"
xcodebuildExportArchiveLogPathEnvKey = "BITRISE_XCODEBUILD_EXPORT_ARCHIVE_LOG_PATH"
bitriseIDEDistributionLogsPthEnvKey = "BITRISE_IDEDISTRIBUTION_LOGS_PATH"

// Env Outputs
bitriseAppDirPthEnvKey = "BITRISE_APP_DIR_PATH"
bitriseDSYMDirPthEnvKey = "BITRISE_DSYM_DIR_PATH"
bitriseXCArchivePthEnvKey = "BITRISE_XCARCHIVE_PATH"
)

// Inputs ...
Expand Down Expand Up @@ -378,11 +383,11 @@ type xcodeArchiveOpts struct {
}

type xcodeArchiveOutput struct {
ArchivePath string
AppPath string
AppDSYMPaths []string
FrameworkDSYMPaths []string
XcodebuildLog string
ArchivePath string
AppPath string
AppDSYMPaths []string
FrameworkDSYMPaths []string
XcodebuildArchiveLog string
}

func (s XcodeArchiveStep) xcodeArchive(opts xcodeArchiveOpts) (xcodeArchiveOutput, error) {
Expand Down Expand Up @@ -484,6 +489,7 @@ func (s XcodeArchiveStep) xcodeArchive(opts xcodeArchiveOpts) (xcodeArchiveOutpu
}

xcodebuildLog, err := runArchiveCommandWithRetry(archiveCmd, opts.OutputTool == "xcpretty", swiftPackagesPath)
out.XcodebuildArchiveLog = xcodebuildLog
if err != nil || opts.OutputTool == "xcodebuild" {
const lastLinesMsg = "\nLast lines of the Xcode's build log:"
if err != nil {
Expand All @@ -497,7 +503,6 @@ func (s XcodeArchiveStep) xcodeArchive(opts xcodeArchiveOpts) (xcodeArchiveOutpu
The log file will be stored in $BITRISE_DEPLOY_DIR, and its full path will be available in the $BITRISE_XCODE_RAW_RESULT_TEXT_PATH environment variable.`)
}
if err != nil {
out.XcodebuildLog = xcodebuildLog
return out, fmt.Errorf("archive failed, error: %s", err)
}

Expand Down Expand Up @@ -558,10 +563,10 @@ type xcodeIPAExportOpts struct {
}

type xcodeIPAExportOutput struct {
ExportOptionsPath string
IPAExportDir string
XcodebuildLog string
IDEDistrubutionLogsDir string
ExportOptionsPath string
IPAExportDir string
XcodebuildExportArchiveLog string
IDEDistrubutionLogsDir string
}

func (s XcodeArchiveStep) xcodeIPAExport(opts xcodeIPAExportOpts) (xcodeIPAExportOutput, error) {
Expand Down Expand Up @@ -654,9 +659,8 @@ func (s XcodeArchiveStep) xcodeIPAExport(opts xcodeIPAExportOpts) (xcodeIPAExpor
logWithTimestamp(colorstring.Green, xcprettyCmd.PrintableCmd())

xcodebuildLog, exportErr := xcprettyCmd.Run()
out.XcodebuildExportArchiveLog = xcodebuildLog
if exportErr != nil {
out.XcodebuildLog = xcodebuildLog

log.Warnf(`If you can't find the reason of the error in the log, please check the raw-xcodebuild-output.log
The log file is stored in $BITRISE_DEPLOY_DIR, and its full path
is available in the $BITRISE_XCODE_RAW_RESULT_TEXT_PATH environment variable`)
Expand Down Expand Up @@ -686,9 +690,8 @@ is available in the $BITRISE_IDEDISTRIBUTION_LOGS_PATH environment variable`)
logWithTimestamp(colorstring.Green, exportCmd.PrintableCmd())

xcodebuildLog, exportErr := exportCmd.RunAndReturnOutput()
out.XcodebuildExportArchiveLog = xcodebuildLog
if exportErr != nil {
out.XcodebuildLog = xcodebuildLog

// xcdistributionlogs
ideDistrubutionLogsDir, err := findIDEDistrubutionLogsPath(xcodebuildLog)
if err != nil {
Expand Down Expand Up @@ -756,8 +759,9 @@ type RunOut struct {
ExportOptionsPath string
IPAExportDir string

XcodebuildLog string
IDEDistrubutionLogsDir string
XcodebuildArchiveLog string
XcodebuildExportArchiveLog string
IDEDistrubutionLogsDir string
}

// Run ...
Expand All @@ -782,11 +786,11 @@ func (s XcodeArchiveStep) Run(opts RunOpts) (RunOut, error) {
CacheLevel: opts.CacheLevel,
}
archiveOut, err := s.xcodeArchive(archiveOpts)
out.XcodebuildArchiveLog = archiveOut.XcodebuildArchiveLog
if err != nil {
return RunOut{
XcodebuildLog: archiveOut.XcodebuildLog,
}, err
return out, err
}

out.ArchivePath = archiveOut.ArchivePath
out.AppPath = archiveOut.AppPath
out.AppDSYMPaths = archiveOut.AppDSYMPaths
Expand All @@ -808,12 +812,12 @@ func (s XcodeArchiveStep) Run(opts RunOpts) (RunOut, error) {
CompileBitcode: opts.CompileBitcode,
}
exportOut, err := s.xcodeIPAExport(IPAExportOpts)
out.XcodebuildExportArchiveLog = exportOut.XcodebuildExportArchiveLog
if err != nil {
return RunOut{
XcodebuildLog: exportOut.XcodebuildLog,
IDEDistrubutionLogsDir: exportOut.IDEDistrubutionLogsDir,
}, err
out.IDEDistrubutionLogsDir = exportOut.IDEDistrubutionLogsDir
return out, err
}

out.ExportOptionsPath = exportOut.ExportOptionsPath
out.IPAExportDir = exportOut.IPAExportDir

Expand All @@ -834,8 +838,9 @@ type ExportOpts struct {
ExportOptionsPath string
IPAExportDir string

XcodebuildLog string
IDEDistrubutionLogsDir string
XcodebuildArchiveLog string
XcodebuildExportArchiveLog string
IDEDistrubutionLogsDir string
}

// ExportOutput ...
Expand Down Expand Up @@ -1006,16 +1011,29 @@ func (s XcodeArchiveStep) ExportOutput(opts ExportOpts) error {
}
}

if opts.XcodebuildLog != "" {
xcodebuildLogPath := filepath.Join(opts.OutputDir, "raw-xcodebuild-output.log")
if err := cleanup(xcodebuildLogPath); err != nil {
if opts.XcodebuildArchiveLog != "" {
xcodebuildArchiveLogPath := filepath.Join(opts.OutputDir, "xcodebuild-archive.log")
if err := cleanup(xcodebuildArchiveLogPath); err != nil {
return err
}

if err := utils.ExportOutputFileContent(opts.XcodebuildArchiveLog, xcodebuildArchiveLogPath, xcodebuildArchiveLogPathEnvKey); err != nil {
log.Warnf("Failed to export %s, error: %s", xcodebuildArchiveLogPathEnvKey, err)
} else {
log.Donef("The xcodebuild archive log path is now available in the Environment Variable: %s (value: %s)", xcodebuildArchiveLogPathEnvKey, xcodebuildArchiveLogPath)
}
}

if opts.XcodebuildExportArchiveLog != "" {
xcodebuildExportArchiveLogPath := filepath.Join(opts.OutputDir, "xcodebuild-export-archive.log")
if err := cleanup(xcodebuildExportArchiveLogPath); err != nil {
return err
}

if err := utils.ExportOutputFileContent(opts.XcodebuildLog, xcodebuildLogPath, bitriseXcodeRawResultTextEnvKey); err != nil {
log.Warnf("Failed to export %s, error: %s", bitriseXcodeRawResultTextEnvKey, err)
if err := utils.ExportOutputFileContent(opts.XcodebuildExportArchiveLog, xcodebuildExportArchiveLogPath, xcodebuildExportArchiveLogPathEnvKey); err != nil {
log.Warnf("Failed to export %s, error: %s", xcodebuildArchiveLogPathEnvKey, err)
} else {
log.Donef("The raw xcodebuild log path is now available in the Environment Variable: %s (value: %s)", bitriseXcodeRawResultTextEnvKey, xcodebuildLogPath)
log.Donef("The xcodebuild -exportArchive log path is now available in the Environment Variable: %s (value: %s)", xcodebuildExportArchiveLogPathEnvKey, xcodebuildExportArchiveLogPath)
}
}

Expand Down Expand Up @@ -1079,8 +1097,9 @@ func RunStep() error {
ExportOptionsPath: out.ExportOptionsPath,
IPAExportDir: out.IPAExportDir,

XcodebuildLog: out.XcodebuildLog,
IDEDistrubutionLogsDir: out.IDEDistrubutionLogsDir,
XcodebuildArchiveLog: out.XcodebuildArchiveLog,
XcodebuildExportArchiveLog: out.XcodebuildExportArchiveLog,
IDEDistrubutionLogsDir: out.IDEDistrubutionLogsDir,
}
exportErr := step.ExportOutput(exportOpts)

Expand Down
16 changes: 11 additions & 5 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,19 @@ outputs:
title: The created .xcarchive.zip file's path
description: |-
The created .xcarchive.zip file's path.
- BITRISE_XCODE_ARCHIVE_RAW_RESULT_TEXT_PATH:
- BITRISE_XCODEBUILD_ARCHIVE_LOG_PATH:
opts:
title: The full, raw archive output file path
title: "`xcodebuild archive` command log file path"
description: |-
This is the path of the raw archive results log file.
If `output_tool=xcpretty` and the archive fails this log will contain the archive output.
The file path of the raw `xcodebuild archive` command log. The log is placed into the `Output directory path`.
- BITRISE_XCODEBUILD_EXPORT_ARCHIVE_LOG_PATH:
opts:
title: "`xcodebuild -exportArchive` command log file path"
description: |-
The file path of the raw `xcodebuild -exportArchive` command log. The log is placed into the `Output directory path`.
- BITRISE_IDEDISTRIBUTION_LOGS_PATH:
opts:
title: Path to the xcdistributionlogs
description: |-
Exported when `xcodebuild -exportArchive` command fails.

0 comments on commit 08d24ce

Please sign in to comment.