diff --git a/Gopkg.lock b/Gopkg.lock index bc8ec7b..15809fb 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -3,7 +3,7 @@ [[projects]] branch = "master" - digest = "1:ca950e4f3bdf3150aa39117da56c34747027d6f8709ccae2473efc29ba152a0a" + digest = "1:e11d2bac877b9284baf9cc87c312f3d46baca7718b26f016e8afe8e56757098b" name = "github.com/bitrise-io/go-utils" packages = [ "colorstring", @@ -18,6 +18,7 @@ "pkcs12/internal/rc2", "pointers", "stringutil", + "ziputil", ] pruneopts = "UT" revision = "d1de0dbcb811588e61362aff67bb700b93c13c17" @@ -32,9 +33,10 @@ [[projects]] branch = "master" - digest = "1:02f962575f79cb7ab4f9352af38120e44fdb5d43708b8e7440927d3b2e408471" + digest = "1:ef821f1a314d0164da39e6b0a4ce1223259a45c3611ede95d5759d5d2270af5f" name = "github.com/bitrise-tools/go-steputils" packages = [ + "output", "stepconf", "tools", ] @@ -128,6 +130,7 @@ "github.com/bitrise-io/go-utils/pathutil", "github.com/bitrise-io/go-utils/stringutil", "github.com/bitrise-io/steps-xcode-archive/utils", + "github.com/bitrise-tools/go-steputils/output", "github.com/bitrise-tools/go-steputils/stepconf", "github.com/bitrise-tools/go-steputils/tools", "github.com/bitrise-tools/go-xcode/xcodebuild", diff --git a/bitrise.yml b/bitrise.yml index ed7d264..48f4c1a 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -47,9 +47,19 @@ workflows: if [[ "$BITRISE_DEPLOY_DIR/testbundle.zip" != "$BITRISE_TEST_BUNDLE_ZIP_PATH" ]] ; then echo "BITRISE_TEST_BUNDLE_ZIP_PATH (\"$BITRISE_TEST_BUNDLE_ZIP_PATH\") should be: \"$BITRISE_DEPLOY_DIR/testbundle.zip\"" exit 1 - else - echo "BITRISE_APP_DIR_PATH: $BITRISE_APP_DIR_PATH" fi + if [[ "$BITRISE_DEPLOY_DIR/Debug-iphoneos" != "$BITRISE_TEST_DIR_PATH" ]] ; then + echo "BITRISE_TEST_DIR_PATH (\"$BITRISE_TEST_DIR_PATH\") should be: \"$BITRISE_DEPLOY_DIR/Debug-iphoneos\"" + exit 1 + fi + if [[ "$BITRISE_DEPLOY_DIR/ios-simple-objc_iphoneos12.0-arm64e.xctestrun" != "$BITRISE_XCTESTRUN_FILE_PATH" ]] ; then + echo "BITRISE_XCTESTRUN_FILE_PATH (\"$BITRISE_XCTESTRUN_FILE_PATH\") should be: \"$BITRISE_DEPLOY_DIR/ios-simple-objc_iphoneos12.0-arm64e.xctestrun\"" + exit 1 + fi + + echo "BITRISE_TEST_BUNDLE_ZIP_PATH: $BITRISE_TEST_BUNDLE_ZIP_PATH" + echo "BITRISE_TEST_DIR_PATH: $BITRISE_TEST_DIR_PATH" + echo "BITRISE_XCTESTRUN_FILE_PATH: $BITRISE_XCTESTRUN_FILE_PATH" go-tests: steps: diff --git a/main.go b/main.go index 9556c96..176e437 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "github.com/bitrise-io/go-utils/pathutil" "github.com/bitrise-io/go-utils/stringutil" "github.com/bitrise-io/steps-xcode-archive/utils" + "github.com/bitrise-tools/go-steputils/output" "github.com/bitrise-tools/go-steputils/stepconf" "github.com/bitrise-tools/go-steputils/tools" "github.com/bitrise-tools/go-xcode/xcodebuild" @@ -264,8 +265,8 @@ The log file is stored in $BITRISE_DEPLOY_DIR, and its full path is available in } log.Printf("Built test directory: %s", builtTestDir) - testBundleZipPath := filepath.Join(absOutputDir, "testbundle.zip") - zipCmd := command.New("zip", "-r", testBundleZipPath, filepath.Base(builtTestDir), filepath.Base(xctestrunPth)).SetDir(symRoot) + outputTestBundleZipPath := filepath.Join(absOutputDir, "testbundle.zip") + zipCmd := command.New("zip", "-r", outputTestBundleZipPath, filepath.Base(builtTestDir), filepath.Base(xctestrunPth)).SetDir(symRoot) if out, err := zipCmd.RunAndReturnTrimmedCombinedOutput(); err != nil { if errorutil.IsExitStatusError(err) { failf("%s failed: %s", zipCmd.PrintableCommandArgs(), out) @@ -273,12 +274,24 @@ The log file is stored in $BITRISE_DEPLOY_DIR, and its full path is available in failf("%s failed: %s", zipCmd.PrintableCommandArgs(), err) } } - log.Printf("Zipped test bundle: %s", testBundleZipPath) + log.Printf("Zipped test bundle: %s", outputTestBundleZipPath) - if err := tools.ExportEnvironmentWithEnvman("BITRISE_TEST_BUNDLE_ZIP_PATH", testBundleZipPath); err != nil { + outputXCTestrunPth := filepath.Join(absOutputDir, filepath.Base(xctestrunPth)) + if err := output.ExportOutputFile(xctestrunPth, outputXCTestrunPth, "BITRISE_XCTESTRUN_FILE_PATH"); err != nil { + failf("Failed to export BITRISE_XCTESTRUN_FILE_PATH: %s", err) + } + log.Donef("The built xctestrun file is available in BITRISE_XCTESTRUN_FILE_PATH env: %s", outputXCTestrunPth) + + outputTestDirPath := filepath.Join(absOutputDir, filepath.Base(builtTestDir)) + if err := output.ExportOutputDir(builtTestDir, outputTestDirPath, "BITRISE_TEST_DIR_PATH"); err != nil { + failf("Failed to export BITRISE_TEST_DIR_PATH: %s", err) + } + log.Donef("The built test directory is available in BITRISE_TEST_DIR_PATH env: %s", outputTestDirPath) + + if err := tools.ExportEnvironmentWithEnvman("BITRISE_TEST_BUNDLE_ZIP_PATH", outputTestBundleZipPath); err != nil { failf("Failed to export BITRISE_TEST_BUNDLE_ZIP_PATH: %s", err) } - log.Donef("The zipped test bundle is available in BITRISE_TEST_BUNDLE_ZIP_PATH env") + log.Donef("The zipped test bundle is available in BITRISE_TEST_BUNDLE_ZIP_PATH env: %s", outputTestBundleZipPath) } func failf(format string, v ...interface{}) { diff --git a/step.yml b/step.yml index 55d1594..b37e2c2 100644 --- a/step.yml +++ b/step.yml @@ -97,9 +97,15 @@ inputs: - "no" outputs: + - BITRISE_TEST_DIR_PATH: + opts: + title: "Path to the built test directory (example: PROJECT_DERIVED_DATA/Build/Products/Debug-iphoneos)" + - BITRISE_XCTESTRUN_FILE_PATH: + opts: + title: "Path to the built xctestrun file (example: PROJECT_DERIVED_DATA/Build/Products/ios-simple-objc_iphoneos12.0-arm64e.xctestrun)" - BITRISE_TEST_BUNDLE_ZIP_PATH: opts: - title: The generated *.xctestrun and app bundle zip ready for testing + title: "The built test directory and the built xctestrun file compressed as a single zip" - BITRISE_XCODE_BUILD_RAW_RESULT_TEXT_PATH: opts: title: The full, raw build output file path diff --git a/vendor/github.com/bitrise-io/go-utils/ziputil/ziputil.go b/vendor/github.com/bitrise-io/go-utils/ziputil/ziputil.go new file mode 100644 index 0000000..29a6252 --- /dev/null +++ b/vendor/github.com/bitrise-io/go-utils/ziputil/ziputil.go @@ -0,0 +1,71 @@ +package ziputil + +import ( + "fmt" + "path/filepath" + + "github.com/bitrise-io/go-utils/command" + "github.com/bitrise-io/go-utils/pathutil" +) + +// ZipDir ... +func ZipDir(sourceDirPth, destinationZipPth string, isContentOnly bool) error { + if exist, err := pathutil.IsDirExists(sourceDirPth); err != nil { + return err + } else if !exist { + return fmt.Errorf("dir (%s) not exist", sourceDirPth) + } + + workDir := filepath.Dir(sourceDirPth) + if isContentOnly { + workDir = sourceDirPth + } + + zipTarget := filepath.Base(sourceDirPth) + if isContentOnly { + zipTarget = "." + } + + // -r - Travel the directory structure recursively + // -T - Test the integrity of the new zip file + // -y - Store symbolic links as such in the zip archive, instead of compressing and storing the file referred to by the link + cmd := command.New("/usr/bin/zip", "-rTy", destinationZipPth, zipTarget) + cmd.SetDir(workDir) + if out, err := cmd.RunAndReturnTrimmedCombinedOutput(); err != nil { + return fmt.Errorf("command: (%s) failed, output: %s, error: %s", cmd.PrintableCommandArgs(), out, err) + } + + return nil +} + +// ZipFile ... +func ZipFile(sourceFilePth, destinationZipPth string) error { + if exist, err := pathutil.IsPathExists(sourceFilePth); err != nil { + return err + } else if !exist { + return fmt.Errorf("file (%s) not exist", sourceFilePth) + } + + workDir := filepath.Dir(sourceFilePth) + zipTarget := filepath.Base(sourceFilePth) + + // -T - Test the integrity of the new zip file + // -y - Store symbolic links as such in the zip archive, instead of compressing and storing the file referred to by the link + cmd := command.New("/usr/bin/zip", "-Ty", destinationZipPth, zipTarget) + cmd.SetDir(workDir) + if out, err := cmd.RunAndReturnTrimmedCombinedOutput(); err != nil { + return fmt.Errorf("command: (%s) failed, output: %s, error: %s", cmd.PrintableCommandArgs(), out, err) + } + + return nil +} + +// UnZip ... +func UnZip(zip, intoDir string) error { + cmd := command.New("/usr/bin/unzip", zip, "-d", intoDir) + if out, err := cmd.RunAndReturnTrimmedCombinedOutput(); err != nil { + return fmt.Errorf("command: (%s) failed, output: %s, error: %s", cmd.PrintableCommandArgs(), out, err) + } + + return nil +} diff --git a/vendor/github.com/bitrise-tools/go-steputils/output/output.go b/vendor/github.com/bitrise-tools/go-steputils/output/output.go new file mode 100644 index 0000000..273096c --- /dev/null +++ b/vendor/github.com/bitrise-tools/go-steputils/output/output.go @@ -0,0 +1,90 @@ +package output + +import ( + "fmt" + "path/filepath" + + "github.com/bitrise-io/go-utils/command" + "github.com/bitrise-io/go-utils/fileutil" + "github.com/bitrise-io/go-utils/pathutil" + "github.com/bitrise-io/go-utils/ziputil" + "github.com/bitrise-tools/go-steputils/tools" +) + +// ExportOutputDir ... +func ExportOutputDir(sourceDir, destinationDir, envKey string) error { + absSourceDir, err := pathutil.AbsPath(sourceDir) + if err != nil { + return err + } + + absDestinationDir, err := pathutil.AbsPath(destinationDir) + if err != nil { + return err + } + + if absSourceDir != absDestinationDir { + if err := command.CopyDir(absSourceDir, absDestinationDir, true); err != nil { + return err + } + } + return tools.ExportEnvironmentWithEnvman(envKey, absDestinationDir) +} + +// ExportOutputFile ... +func ExportOutputFile(sourcePth, destinationPth, envKey string) error { + absSourcePth, err := pathutil.AbsPath(sourcePth) + if err != nil { + return err + } + + absDestinationPth, err := pathutil.AbsPath(destinationPth) + if err != nil { + return err + } + + if absSourcePth != absDestinationPth { + if err := command.CopyFile(absSourcePth, absDestinationPth); err != nil { + return err + } + } + return tools.ExportEnvironmentWithEnvman(envKey, absDestinationPth) +} + +// ExportOutputFileContent ... +func ExportOutputFileContent(content, destinationPth, envKey string) error { + if err := fileutil.WriteStringToFile(destinationPth, content); err != nil { + return err + } + + return ExportOutputFile(destinationPth, destinationPth, envKey) +} + +// ZipAndExportOutput ... +func ZipAndExportOutput(sourcePth, destinationZipPth, envKey string) error { + tmpDir, err := pathutil.NormalizedOSTempDirPath("__export_tmp_dir__") + if err != nil { + return err + } + + base := filepath.Base(sourcePth) + tmpZipFilePth := filepath.Join(tmpDir, base+".zip") + + if exist, err := pathutil.IsDirExists(sourcePth); err != nil { + return err + } else if exist { + if err := ziputil.ZipDir(sourcePth, tmpZipFilePth, false); err != nil { + return err + } + } else if exist, err := pathutil.IsPathExists(sourcePth); err != nil { + return err + } else if exist { + if err := ziputil.ZipFile(sourcePth, tmpZipFilePth); err != nil { + return err + } + } else { + return fmt.Errorf("source path (%s) not exists", sourcePth) + } + + return ExportOutputFile(tmpZipFilePth, destinationZipPth, envKey) +}