bin/nixenvironment in nixenvironment-0.0.8 vs bin/nixenvironment in nixenvironment-0.0.9

- old
+ new

@@ -36,11 +36,11 @@ end end command :deploy do |c| c.syntax = 'nixenvironment deploy' - c.description = 'Deploy build to mds' + c.description = 'Deploy built artifacts to given server' c.action do |args, options| read_config deploy end end @@ -51,10 +51,52 @@ c.action do |args, options| clean end end +command :test do |c| + c.syntax = 'nixenvironment test' + c.description = 'Build unit tests and run them in simulator' + c.action do |args, options| + read_config + test + end +end + +command :code_duplication_report do |c| + c.syntax = 'nixenvironment code_duplication_report' + c.description = 'Generate code duplication report' + c.action do |args, options| + read_config + code_duplication_report + end +end + +command :tag do |c| + c.syntax = 'nixenvironment tag' + c.description = 'Make SVN/git/mercurial tag, SCM_USERNAME and SCM_PASSWORD must be defined on calling this target' + c.action do |args, options| + tag + end +end + +command :svn_tag_from_jenkins do |c| + c.syntax = 'nixenvironment svn_tag_from_jenkins' + c.description = 'Make tag by finding the first credential in local credential storage' + c.action do |args, options| + svn_tag_from_jenkins + end +end + +command :clean_working_copy do |c| + c.syntax = 'nixenvironment clean_working_copy' + c.description = 'Make working copy clean' + c.action do |args, options| + clean_working_copy + end +end + def update(ninbas) root_working_directory = Dir.pwd target_directory = File.join(Dir.home, NIXENV_ROOT) begin @@ -62,22 +104,20 @@ Dir.chdir(target_directory) REPO_LIST.each do |repo_name, repo_url| unless Dir.exist?(repo_name) clone_success = system("git clone #{repo_url} --recursive") - unless clone_success p("Authentication failed for #{repo_name} project!") next end end Dir.chdir(repo_name) if repo_name == BUILD_SCRIPTS if ninbas - #TODO: rework me please! system("git checkout #{ninbas}") Dir.chdir('..') next end end @@ -87,12 +127,13 @@ tags.map! { |tag| tag = tag.strip } if tags.size > 0 p("Checkout newest #{repo_name} tag...") system("git checkout #{tags.last}") + else + abort("Error checkout #{repo_name}! There is no tags!") end - #TODO: hadle tags.size == 0 p("Checkout #{repo_name} #{tags.last} tag success!") Dir.chdir('..') end @@ -145,12 +186,10 @@ -configuration #{config}\ -sdk #{@config['SDK']}\ -showBuildSettings ] end - #TODO: handle if cmd_output still nil - env_vars_list = cmd_output.split(/\n/).reject(&:empty?) build_settings = Hash.new if env_vars_list and env_vars_list.length > 0 @@ -165,139 +204,158 @@ end return build_settings end -def prebuild(build_settings) - save_revision_script_path = File.join(BUILD_SCRIPTS_PATH, 'SaveRevision.sh') - save_build_env_vars_script_path = File.join(BUILD_SCRIPTS_PATH, 'SaveBuildEnvVars.sh') - tag_icons_script_path = File.join(BUILD_SCRIPTS_PATH, 'XcodeIconTagger/tagIcons.sh') - update_build_number_script_path = File.join(BUILD_SCRIPTS_PATH, 'UpdateBuildNumber.sh') - update_revision_number_script_path = File.join(BUILD_SCRIPTS_PATH, 'UpdateRevisionNumber.sh') +def save_build_env_vars(build_settings) + app_product = "#{build_settings['BUILT_PRODUCTS_DIR']}/#{build_settings['EXECUTABLE_NAME']}.app" - icon_path = @config['ICONS_PATH'] - - system("#{save_revision_script_path}") - - abort unless working_copy_is_clean? - - # TODO: rewrite SaveBuildEnvVars.sh - #system("#{save_build_env_vars_script_path}") - system(" echo \"#!/bin/sh\ -### AUTOGENERATED BY SaveBuildEnvVars.sh; DO NOT EDIT ### +### AUTOGENERATED BY Nixenvironment; DO NOT EDIT ### PROJECT=\"#{build_settings['PROJECT']}\" BUILT_PRODUCTS_DIR=\"#{build_settings['BUILT_PRODUCTS_DIR']}\" OBJECTS_NORMAL_DIR=\"#{build_settings['OBJECT_FILE_DIR_normal']}\" EXECUTABLE_NAME=\"#{build_settings['EXECUTABLE_NAME']}\" - APP_PRODUCT=\"#{build_settings['BUILT_PRODUCTS_DIR']}/#{build_settings['EXECUTABLE_NAME']}.app\" - APP_DSYM=\"#{build_settings['BUILT_PRODUCTS_DIR']}/#{build_settings['EXECUTABLE_NAME']}.app.dSYM\" + APP_PRODUCT=\"#{app_product}\" + APP_DSYM=\"#{app_product}.dSYM\" APP_INFOPLIST_FILE=\"#{@config['INFOPLIST_PATH']}\" - EMBEDDED_PROFILE=\"#{build_settings['BUILT_PRODUCTS_DIR']}/#{build_settings['EXECUTABLE_NAME']}.app/#{build_settings['EMBEDDED_PROFILE_NAME']}\" + EMBEDDED_PROFILE=\"##{app_product}/#{build_settings['EMBEDDED_PROFILE_NAME']}\" TARGET_NAME=\"#{build_settings['TARGET_NAME']}\" CONFIGURATION=\"#{build_settings['CONFIGURATION']}\" SDK_NAME=\"#{build_settings['SDK_NAME']}\" RESIGNED_BUNDLE_ID=\"#{build_settings['RESIGNED_BUNDLE_ID']}\" RESIGNED_BUNDLE_NAME=\"#{build_settings['RESIGNED_BUNDLE_NAME']}\" RESIGNED_ENTITLEMENTS_PATH=\"#{build_settings['RESIGNED_ENTITLEMENTS_PATH']}\"\" > _last_build_vars.sh ") +end +def prebuild(build_settings) + save_revision = File.join(BUILD_SCRIPTS_PATH, 'SaveRevision.sh') + tag_icons = File.join(BUILD_SCRIPTS_PATH, 'XcodeIconTagger/tagIcons.sh') + update_build_number = File.join(BUILD_SCRIPTS_PATH, 'UpdateBuildNumber.sh') + update_revision_number = File.join(BUILD_SCRIPTS_PATH, 'UpdateRevisionNumber.sh') + + system("#{save_revision}") + + abort unless working_copy_is_clean? + + save_build_env_vars(build_settings) + # TODO: rewrite tagIcons.sh - # system("#{tag_icons_script_path} #{icon_path}") + # system("#{tag_icons} @config['ICONS_PATH']") - # Implement all modify things in one script - system("#{update_build_number_script_path}") - system("#{update_revision_number_script_path}") + system("#{update_build_number}") + system("#{update_revision_number}") end def build(config, ipa) - build_script_path = File.join(BUILD_SCRIPTS_PATH, 'Build.py') + build = File.join(BUILD_SCRIPTS_PATH, 'Build.py') - system("#{build_script_path} --project \"#{@config['PROJECT_TO_BUILD']}\"\ - --target \"#{@config['PROJECT_TARGET_TO_BUILD']}\"\ - --workspace \"#{@config['WORKSPACE_TO_BUILD']}\"\ - --scheme \"#{@config['WORKSPACE_SCHEME_TO_BUILD']}\"\ - --configuration \"#{config}\"\ - --sdk \"#{@config['SDK']}\"\ - --env-var-prefix \"#{@config['ENV_VAR_PREFIX']}\"") + build_success = system("#{build} --project \"#{@config['PROJECT_TO_BUILD']}\"\ + --target \"#{@config['PROJECT_TARGET_TO_BUILD']}\"\ + --workspace \"#{@config['WORKSPACE_TO_BUILD']}\"\ + --scheme \"#{@config['WORKSPACE_SCHEME_TO_BUILD']}\"\ + --configuration \"#{config}\"\ + --sdk \"#{@config['SDK']}\"\ + --env-var-prefix \"#{@config['ENV_VAR_PREFIX']}\"") + abort('Build error!') unless build_success case ipa # create .ipa file from last built app product when 'ipa' - make_script_path = File.join(BUILD_SCRIPTS_PATH, 'MakeIPA.sh') + make = File.join(BUILD_SCRIPTS_PATH, 'MakeIPA.sh') # resign last built app product with iPhone Developer profile and package it into .ipa file when 'resigned_ipa_for_device' - make_script_path = File.join(BUILD_SCRIPTS_PATH, 'MakeResignedIPAForDevice.sh') + make = File.join(BUILD_SCRIPTS_PATH, 'MakeResignedIPAForDevice.sh') # resign last built app product with iPhone Distribution AdHoc profile and package it into .ipa file when 'resigned_ipa_for_adhoc_distribution' - make_script_path = File.join(BUILD_SCRIPTS_PATH, 'MakeResignedIPAForAdHocDistribution.sh') + make = File.join(BUILD_SCRIPTS_PATH, 'MakeResignedIPAForAdHocDistribution.sh') # resign last built app product with Appstore distribution profile and package it into .ipa file when 'resigned_ipa_for_appstore' - make_script_path = File.join(BUILD_SCRIPTS_PATH, 'MakeResignedIPAForAppstore.sh') + make = File.join(BUILD_SCRIPTS_PATH, 'MakeResignedIPAForAppstore.sh') else - p("Error: Unknown ipa '#{ipa}'!") + abort("Error: Unknown ipa '#{ipa}'!") end - system("#{make_script_path}") if defined? make_script_path + make_success = system("#{make}") if defined? make + abort("#{make} error!") unless make_success end def revert_info_plist p('Reverting Info.plist ...') - system("git checkout #{@config['INFOPLIST_PATH']}") - p('Done.') + + revert_success = system("git checkout #{@config['INFOPLIST_PATH']}") + abort('Reverting Info.plist error!') unless revert_success + + p('Info.plist was reverted.') end -# deploys built artifacts to given server def deploy - deploy_script_path = File.join(BUILD_SCRIPTS_PATH, 'Deploy.sh') + deploy = File.join(BUILD_SCRIPTS_PATH, 'Deploy.sh') deploy_host = @config['DEPLOY_HOST'].nil? || @config['DEPLOY_HOST'].empty? ? ENV['DEPLOY_HOST'] : @config['DEPLOY_HOST'] deploy_path = @config['DEPLOY_PATH'].nil? || @config['DEPLOY_PATH'].empty? ? ENV['DEPLOY_PATH'] : @config['DEPLOY_PATH'] deploy_username = @config['DEPLOY_USERNAME'].nil? || @config['DEPLOY_USERNAME'].empty? ? ENV['DEPLOY_USERNAME'] : @config['DEPLOY_USERNAME'] deploy_password = @config['DEPLOY_PASSWORD'].nil? || @config['DEPLOY_PASSWORD'].empty? ? ENV['DEPLOY_PASSWORD'] : @config['DEPLOY_PASSWORD'] - system("#{deploy_script_path} #{deploy_host}\ - #{deploy_path}\ - #{deploy_username}\ - #{deploy_password}") + deploy_success = system("#{deploy} #{deploy_host} #{deploy_path} #{deploy_username} #{deploy_password}") + abort('Deploy error!') unless deploy_success end def clean - remove_temporary_files_script_path = File.join(BUILD_SCRIPTS_PATH, 'RemoveTemporaryFiles.sh') + remove_temporary_files = File.join(BUILD_SCRIPTS_PATH, 'RemoveTemporaryFiles.sh') - system("#{remove_temporary_files_script_path}") + system("#{remove_temporary_files}") system('rm -rf test-results/') system("find . -name \"*.pyc\" -exec rm -rf {} \;") system('xcodebuild -alltargets clean') end -# # build unit tests and run them in simulator -# def test -# ${BUILD_SCRIPTS_PATH}Build.py --project "${PROJECT_TO_BUILD}" --target "${PROJECT_TARGET_TO_TEST}" --workspace "${WORKSPACE_TO_BUILD}" --scheme "${WORKSPACE_SCHEME_TO_TEST}" --configuration "Release" --sdk "${SDK_FOR_TESTS}" --env-var-prefix "${ENV_VAR_PREFIX}" -# ${BUILD_SCRIPTS_PATH}RunTests.sh -# ${BUILD_SCRIPTS_PATH}GenerateCodeCoverageReport.sh "${EXCLUDE_PATTERN_FOR_CODE_COVERAGE}" coverage.xml -# end -# -# # generates code duplication report -# def code_duplication_report -# ${BUILD_SCRIPTS_PATH}GenerateCodeDuplicationReport.sh "${EXCLUDE_PATTERN_FOR_CODE_DUPLICATION}" duplication.xml -# end -# -# # make SVN/git/mercurial tag, SCM_USERNAME and SCM_PASSWORD must be defined on calling this target -# def tag -# ${BUILD_SCRIPTS_PATH}MakeTag.sh "${SCM_USERNAME}" "${SCM_PASSWORD}" -# end -# -# # Jenkins stores SVN credentials locally in XML, so this target gets and uses them on making tag by finding the first credential in local credential storage -# # additional |echo| is needed in order to add newline, otherwise base64 encoding doesn't work -# # ATTENTION: if this script picks up wrong credentials, then you should manually edit subversion.credentials file on Jenkins in order to remove the wrong credential -# def svn_tag_from_jenkins: -# SCM_USERNAME="$(shell xpath ../subversion.credentials \(//userName\)[1]/text\(\))"\ -# SCM_PASSWORD="$(shell echo $$(xpath ../subversion.credentials \(//password\)[1]/text\(\) 2>/dev/null && echo) | openssl base64 -d)" -# -# tag -# end -# -# def clean_working_copy -# ${BUILD_SCRIPTS_PATH}CleanWorkingCopy.sh -# end +def test + build = File.join(BUILD_SCRIPTS_PATH, 'Build.py') + run_tests = File.join(BUILD_SCRIPTS_PATH, 'RunTests.sh') + generate_code_coverage_report = File.join(BUILD_SCRIPTS_PATH, 'GenerateCodeCoverageReport.sh') + + build_success = system("#{build} --project \"#{@config['PROJECT_TO_BUILD']}\"\ + --target \"#{@config['PROJECT_TARGET_TO_TEST']}\"\ + --workspace \"#{@config['WORKSPACE_TO_BUILD']}\"\ + --scheme \"#{@config['WORKSPACE_SCHEME_TO_TEST']}\"\ + --configuration \"Release\"\ + --sdk \"#{@config['SDK_FOR_TESTS']}\"\ + --env-var-prefix \"#{@config['ENV_VAR_PREFIX']}\"") + abort('Build for test error!') unless build_success + + run_tests_success = system("#{run_tests}") + abort('Run test error!') unless run_tests_success + + coverage_success = system("#{generate_code_coverage_report} \"#{@config['EXCLUDE_PATTERN_FOR_CODE_COVERAGE']}\" coverage.xml") + abort('Generate code coverage error!') unless coverage_success +end + +def code_duplication_report + generate_code_duplication_report = File.join(BUILD_SCRIPTS_PATH, 'GenerateCodeDuplicationReport.sh') + duplication_success = system("#{generate_code_duplication_report} \"#{@config['EXCLUDE_PATTERN_FOR_CODE_DUPLICATION']}\" duplication.xml") + abort('Generate code duplication error!') unless duplication_success +end + +def tag + make_tag = File.join(BUILD_SCRIPTS_PATH, 'MakeTag.sh ') + tag_success = system("#{make_tag} \"#{ENV['SCM_USERNAME']}\" \"#{ENV['SCM_PASSWORD']}\"") + abort('Make tag error!') unless tag_success +end + +# Jenkins stores SVN credentials locally in XML, so this command gets and uses them on making tag by finding the first credential in local credential storage +# ATTENTION: if this command picks up wrong credentials, then you should manually edit subversion.credentials file on Jenkins in order to remove the wrong credential +# Additional |echo| is needed in order to add newline, otherwise base64 encoding doesn't work +def svn_tag_from_jenkins + ENV['SCM_USERNAME']=%x[ $(shell xpath ../subversion.credentials \(//userName\)[1]/text\(\)) ] + ENV['SCM_PASSWORD']=%x[ $(shell echo $$(xpath ../subversion.credentials \(//password\)[1]/text\(\) 2>/dev/null && echo) | openssl base64 -d) ] + + tag +end + +def clean_working_copy + clean_working_copy = File.join(BUILD_SCRIPTS_PATH, 'CleanWorkingCopy.sh') + clean_success = system("#{clean_working_copy}") + abort('Clean working copy error!') unless clean_success +end