diff --git a/bitrise.yml b/bitrise.yml index 38744a3c..447aed6e 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -30,8 +30,8 @@ workflows: inputs: - is_force_code_sign: "no" - is_clean_build: "no" - - build_tool: xctool - workdir: $PROJECT_WORKDIR + - output_tool: xcpretty # - configuration: Debug - script: title: Output (generated by the Step) tests diff --git a/step.sh b/step.sh index 98240ced..62cb5219 100644 --- a/step.sh +++ b/step.sh @@ -4,7 +4,6 @@ THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" set -e - # # Detect Xcode major version xcode_major_version="" @@ -45,14 +44,28 @@ if [ ! -z "${export_options_path}" ] && [[ "${xcode_major_version}" == "6" ]] ; export_options_path="" fi -if [ -z "${build_tool}" ] ; then - echo "[!] Missing required input: build_tool" - exit 1 -elif [[ "${build_tool}" != "xctool" && "${build_tool}" != "xcodebuild" ]] ; then - echo "[!] Invalid build_tool: ${build_tool}" +if [[ "${output_tool}" != "xcpretty" && "${output_tool}" != "xcodebuild" ]] ; then + echo "[!] Invalid output_tool: ${output_tool}" exit 1 fi +set +e + +if [[ "${output_tool}" == "xcpretty" ]] ; then + xcpretty_version=$(xcpretty --version) + exit_code=$? + if [[ $exit_code != 0 || -z $xcpretty_version ]] ; then + echo + echo " (!) xcpretty is not installed" + echo " For xcpretty installation see: 'https://github.com/supermarin/xcpretty'," + echo " or use 'xcodebuild' as 'output_tool'." + echo + exit 1 + fi +fi + +set -e + # # Project-or-Workspace flag if [[ "${project_path}" == *".xcodeproj" ]]; then @@ -84,7 +97,7 @@ fi echo echo "========== Configs ==========" echo " * CONFIG_xcode_project_action: ${CONFIG_xcode_project_action}" -echo " * build_tool: ${build_tool}" +echo " * output_tool: ${output_tool}" echo " * project_path: ${project_path}" echo " * scheme: ${scheme}" echo " * workdir: ${workdir}" @@ -142,38 +155,40 @@ if [ -f "${ipa_path}" ] ; then rm "${ipa_path}" fi +echo +echo +echo "=> Create the Archive ..." + # # Create the Archive with Xcode Command Line tools +archive_cmd="xcodebuild ${CONFIG_xcode_project_action} \"${project_path}\"" +archive_cmd="$archive_cmd -scheme \"${scheme}\" ${xcode_configuration}" +archive_cmd="$archive_cmd ${clean_build_param} archive -archivePath \"${archive_path}\"" + if [[ "${is_force_code_sign}" == "yes" ]] ; then echo " (!) Using Force Code Signing mode!" - echo - echo - - set -x - ${build_tool} ${CONFIG_xcode_project_action} "${project_path}" \ - -scheme "${scheme}" ${xcode_configuration} \ - ${clean_build_param} archive -archivePath "${archive_path}" \ - PROVISIONING_PROFILE="${BITRISE_PROVISIONING_PROFILE_ID}" \ - CODE_SIGN_IDENTITY="${BITRISE_CODE_SIGN_IDENTITY}" -else - echo - echo + archive_cmd="$archive_cmd PROVISIONING_PROFILE=\"${BITRISE_PROVISIONING_PROFILE_ID}\"" + archive_cmd="$archive_cmd CODE_SIGN_IDENTITY=\"${BITRISE_CODE_SIGN_IDENTITY}\"" +fi - set -x - ${build_tool} ${CONFIG_xcode_project_action} "${project_path}" \ - -scheme "${scheme}" ${xcode_configuration} \ - ${clean_build_param} archive -archivePath "${archive_path}" +if [[ "${output_tool}" == "xcpretty" ]] ; then + archive_cmd="set -o pipefail && $archive_cmd | xcpretty" fi -set +x -set +v +echo +echo "archive command:" +echo "$archive_cmd" +echo + +eval $archive_cmd echo echo echo "=> Exporting IPA from generated Archive ..." echo -echo + +export_command="xcodebuild -exportArchive" if [[ "${xcode_major_version}" == "6" ]] ; then # @@ -210,20 +225,27 @@ if [[ "${xcode_major_version}" == "6" ]] ; then echo " (i) Found Profile Name for signing: ${profile_name}" - set -v - # # Use the Provisioning Profile name to export the IPA - xcodebuild -exportArchive \ - -exportFormat ipa \ - -archivePath "${archive_path}" \ - -exportPath "${ipa_path}" \ - -exportProvisioningProfile "${profile_name}" + export_command="$export_command -exportFormat ipa" + export_command="$export_command -archivePath \"${archive_path}\"" + export_command="$export_command -exportPath \"${ipa_path}\"" + export_command="$export_command -exportProvisioningProfile \"${profile_name}\"" + + if [[ "${output_tool}" == "xcpretty" ]] ; then + export_command="set -o pipefail && $export_command | xcpretty" + fi + + echo + echo "export command:" + echo "$export_command" + echo + + eval $export_command else echo " (i) Using Xcode 7 'exportOptionsPlist' option" if [ -z "${export_options_path}" ] ; then - set -x export_options_path="${output_dir}/export_options.plist" curr_pwd="$(pwd)" cd "${THIS_SCRIPT_DIR}" @@ -232,15 +254,8 @@ else -o "${export_options_path}" \ -a "${archive_path}" cd "${curr_pwd}" - set +x fi - - # - # Export the IPA - echo "Content of exportOptionsPlist file:" - cat "${export_options_path}" - # # Because of an RVM issue which conflicts with `xcodebuild`'s new # `-exportOptionsPlist` option @@ -255,16 +270,22 @@ else rvm use system fi - set -x - tmp_dir=$(mktemp -d -t bitrise-xcarchive) - xcodebuild -exportArchive \ - -archivePath "${archive_path}" \ - -exportPath "${tmp_dir}" \ - -exportOptionsPlist "${export_options_path}" + export_command="$export_command -archivePath \"${archive_path}\"" + export_command="$export_command -exportPath \"${tmp_dir}\"" + export_command="$export_command -exportOptionsPlist \"${export_options_path}\"" + + if [[ "${output_tool}" == "xcpretty" ]] ; then + export_command="set -o pipefail && $export_command | xcpretty" + fi - set +x + echo + echo "export command:" + echo "$export_command" + echo + + eval $export_command # Searching for ipa exported_ipa_path="" @@ -300,8 +321,6 @@ else ipa_path="${exported_ipa_path}" fi -set +v - # # Export *.ipa path diff --git a/step.yml b/step.yml index 28ed7c7b..fd6795f2 100644 --- a/step.yml +++ b/step.yml @@ -19,8 +19,6 @@ is_skippable: false deps: check_only: - name: xcode - brew: - - name: xctool run_if: "" inputs: - workdir: $BITRISE_SOURCE_DIR @@ -125,12 +123,15 @@ inputs: is_required: true is_expand: true is_dont_change_value: false - - build_tool: "xctool" + - output_tool: xcpretty opts: - title: "Build tool" + title: Output tool + description: |- + If output_tool is set to xcpretty, the xcodebuild output will be prettified by xcpretty. + If output_tool is set to xcodebuild, the raw xcodebuild output will be printed. value_options: - - "xctool" - - "xcodebuild" + - xcpretty + - xcodebuild is_required: true is_expand: false is_dont_change_value: false