From 454ae16cbe130e244527c2f8046d87be0768966f Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Wed, 13 Jan 2021 18:21:54 +0300 Subject: [PATCH 01/25] remove GOOGLE_SERVICE_INFO_PLIST_PATH generation from xcconfig files --- xcode/config_generator/render_xcconfigs.rb | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/xcode/config_generator/render_xcconfigs.rb b/xcode/config_generator/render_xcconfigs.rb index e08f18a..69aee0b 100755 --- a/xcode/config_generator/render_xcconfigs.rb +++ b/xcode/config_generator/render_xcconfigs.rb @@ -75,27 +75,11 @@ def generate_provisioning_profile(provisioning_key, bundle_id, distribution_type end end -def generate_google_service_info_plist_path(google_service_info_plist_key, target_name, distribution_type) - google_service_info_plist_path = target_name + "/Resources/" - - path_suffix = case distribution_type - when "development" - "Standard-GoogleService-Info.plist" - when "enterprise" - "Enterprise-GoogleService-Info.plist" - else - "AppStore-GoogleService-Info.plist" - end - - return config_option(google_service_info_plist_key, google_service_info_plist_path + path_suffix) -end - # Generate missing properties if needed def generate_missing_properties(target_name, properties, distribution_type) result = [] development_team_key = "DEVELOPMENT_TEAM" provisioning_key = "PROVISIONING_PROFILE_SPECIFIER" - google_service_info_plist_key = "GOOGLE_SERVICE_INFO_PLIST_PATH" bundle_id_key = "PRODUCT_BUNDLE_IDENTIFIER" # Bundle_id_key should be among the properties (required by fastlane) @@ -111,10 +95,6 @@ def generate_missing_properties(target_name, properties, distribution_type) result.append(generate_provisioning_profile(provisioning_key, properties[bundle_id_key], distribution_type)) end - unless properties.key?(google_service_info_plist_key) - result.append(generate_google_service_info_plist_path(google_service_info_plist_key, target_name, distribution_type)) - end - return result end From 9c247bbf4a7fa251799f25ba11c926f3afcdb839 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 14 Jan 2021 18:00:09 +0300 Subject: [PATCH 02/25] improve copy-paste detection script --- xcode/build_phases/copy_paste_detection.sh | 110 +++++++++++++++++++-- xcode/build_phases/unused.sh | 4 +- 2 files changed, 102 insertions(+), 12 deletions(-) diff --git a/xcode/build_phases/copy_paste_detection.sh b/xcode/build_phases/copy_paste_detection.sh index 79a8806..2483291 100644 --- a/xcode/build_phases/copy_paste_detection.sh +++ b/xcode/build_phases/copy_paste_detection.sh @@ -1,20 +1,110 @@ +# Description: +# Validates code for copy-paste, prints results to standard output and report file. +# +# Parameters: +# $1 $2 $3 $n - folders to exclude from code checking. +# +# Required environment variables: +# PROJECT_DIR - project directory. +# +# Optional environment variables: +# SCRIPT_INPUT_FILE_COUNT - number of files listed in "Input files" of build phase. +# SCRIPT_INPUT_FILE_{N} - file path to directory that should be checked. +# +# Modified files: +# ${PROJECT_DIR}/code-quality-reports/CPDLog.txt - check report. +# ${PROJECT_DIR}/code-quality-reports/CPDCommit.txt - last checked commit. +# +# Example of usage: +# copy_paste_detection.sh Generated Localization Pods +# + +readonly EXIT_SUCCESS=0 +readonly EXIT_FAILURE=1 + +read_input_file_names() +{ + local -r DEFAULT_VALUE=${1} + + local INPUT_FILE_NAMES="" + + if [ "${SCRIPT_INPUT_FILE_COUNT}" -gt 0 ] ; then + for i in `seq 0 $((${SCRIPT_INPUT_FILE_COUNT}-1))` + do + SCRIPT_INPUT_FILE_VARIABLE_NAME="SCRIPT_INPUT_FILE_${i}" + COMMAND="echo \${${SCRIPT_INPUT_FILE_VARIABLE_NAME}}" + INPUT_FILE_NAME=`eval ${COMMAND}` + INPUT_FILE_NAMES=${INPUT_FILE_NAMES}${INPUT_FILE_NAME}" " + done + + echo ${INPUT_FILE_NAMES} + else + echo ${DEFAULT_VALUE} + fi +} + +is_nothing_changed_since_last_check() +{ + local -r COMMIT_FILE_PATH=${1} + local -r LAST_LINTED_COMMIT=`cat ${COMMIT_FILE_PATH}` || "" + + local -r CURRENT_COMMIT=${2} + + if [[ "${CURRENT_GIT_COMMIT}" = "${LAST_LINTED_COMMIT}" ]]; then + if git diff --quiet --exit-code; then + echo "Commit your changes and build again." + else + echo "Nothing was changed since ${LAST_LINTED_COMMIT}. Skipping code checking." + fi + + return ${EXIT_SUCCESS} + else + return ${EXIT_FAILURE} + fi +} + if which pmd >/dev/null; then - readonly CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - readonly SOURCES_DIR=${1:-${PROJECT_DIR}} # first argument or PROJECT_DIR - readonly REPORTS_DIR=${PROJECT_DIR}/code-quality-reports - readonly FILES_TO_EXCLUDE=`find ${SOURCES_DIR} -type d -name Localization -or -name Generated -or -name Carthage -or -name Pods | paste -sd " " -` + readonly REPORTS_DIR="${PROJECT_DIR}/code-quality-reports" - mkdir ${REPORTS_DIR} + readonly CPD_COMMIT_FILE_PATH="${REPORTS_DIR}/CPDCommit.txt" - pmd cpd --files ${SOURCES_DIR} --exclude ${FILES_TO_EXCLUDE} --minimum-tokens 50 --language swift --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer > ${REPORTS_DIR}/cpd-output.xml --failOnViolation true + readonly CURRENT_GIT_COMMIT=`git rev-parse --verify HEAD` - php ${CURRENT_DIR}/../aux_scripts/cpd_script.php ${REPORTS_DIR}/cpd-output.xml | tee ${REPORTS_DIR}/CPDLog.txt + if is_nothing_changed_since_last_check ${CPD_COMMIT_FILE_PATH} ${CURRENT_GIT_COMMIT}; then + exit ${EXIT_SUCCESS} + fi - # Make paths relative to SOURCES_DIR, so different developers won't rewrite entire file - readonly SED_REPLACEMENT_STRING=$(echo ${SOURCES_DIR} | sed "s/\//\\\\\//g") + readonly SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + + readonly SOURCES_DIRS=`read_input_file_names ${PROJECT_DIR}` + + readonly COMMAND_LINE_ARGUMENTS=$@ + + FOLDERS_TO_EXLUDE="" + + for argument in ${COMMAND_LINE_ARGUMENTS} + do + FOLDERS_TO_EXLUDE=${FOLDERS_TO_EXLUDE}"-or -name ${argument} " + done + + FOLDERS_TO_EXLUDE=`echo ${FOLDERS_TO_EXLUDE} | cut -c5-` # remove first "-or" + + readonly FILES_TO_EXCLUDE=`find ${PROJECT_DIR} -type d ${FOLDERS_TO_EXLUDE} | paste -sd " " -` + + mkdir -p ${REPORTS_DIR} + + pmd cpd --files ${SOURCES_DIRS} --exclude ${FILES_TO_EXCLUDE} --minimum-tokens 50 --language swift --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer --failOnViolation true > ${REPORTS_DIR}/cpd-output.xml + + php ${SCRIPT_DIR}/../aux_scripts/cpd_script.php ${REPORTS_DIR}/cpd-output.xml | tee ${REPORTS_DIR}/CPDLog.txt + + # Make paths relative to PROJECT_DIR, so different developers won't rewrite entire file + readonly SED_REPLACEMENT_STRING=$(echo ${PROJECT_DIR} | sed "s/\//\\\\\//g") sed -i '' "s/${SED_REPLACEMENT_STRING}//g" "${REPORTS_DIR}/CPDLog.txt" + + echo ${CURRENT_GIT_COMMIT} > ${CPD_COMMIT_FILE_PATH} else echo "warning: pmd not installed, install using 'brew install pmd'" - exit 1 + + exit ${EXIT_FAILURE} fi diff --git a/xcode/build_phases/unused.sh b/xcode/build_phases/unused.sh index 169967d..f137d8c 100644 --- a/xcode/build_phases/unused.sh +++ b/xcode/build_phases/unused.sh @@ -1,5 +1,5 @@ readonly ARGUMENTS=("$@") readonly IGNORED_FILES=$(IFS=, ; echo "${ARGUMENTS[*]}") -readonly CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +readonly SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -ruby ${CURRENT_DIR}/Unused.rb --config ${CURRENT_DIR}/../UnusedConfig.yml --exclude ${IGNORED_FILES} +ruby ${SCRIPT_DIR}/Unused.rb --config ${SCRIPT_DIR}/../UnusedConfig.yml --exclude ${IGNORED_FILES} From 2c5f978eebca28e6046da2a3be4c80d4544029ca Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 14 Jan 2021 18:16:50 +0300 Subject: [PATCH 03/25] final changes --- xcode/build_phases/copy_paste_detection.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xcode/build_phases/copy_paste_detection.sh b/xcode/build_phases/copy_paste_detection.sh index 2483291..42cb778 100644 --- a/xcode/build_phases/copy_paste_detection.sh +++ b/xcode/build_phases/copy_paste_detection.sh @@ -13,7 +13,7 @@ # # Modified files: # ${PROJECT_DIR}/code-quality-reports/CPDLog.txt - check report. -# ${PROJECT_DIR}/code-quality-reports/CPDCommit.txt - last checked commit. +# ${PROJECT_DIR}/code-quality-reports/CPDCommit - last checked commit. # # Example of usage: # copy_paste_detection.sh Generated Localization Pods @@ -31,9 +31,9 @@ read_input_file_names() if [ "${SCRIPT_INPUT_FILE_COUNT}" -gt 0 ] ; then for i in `seq 0 $((${SCRIPT_INPUT_FILE_COUNT}-1))` do - SCRIPT_INPUT_FILE_VARIABLE_NAME="SCRIPT_INPUT_FILE_${i}" - COMMAND="echo \${${SCRIPT_INPUT_FILE_VARIABLE_NAME}}" - INPUT_FILE_NAME=`eval ${COMMAND}` + local SCRIPT_INPUT_FILE_VARIABLE_NAME="SCRIPT_INPUT_FILE_${i}" + local COMMAND="echo \${${SCRIPT_INPUT_FILE_VARIABLE_NAME}}" + local INPUT_FILE_NAME=`eval ${COMMAND}` INPUT_FILE_NAMES=${INPUT_FILE_NAMES}${INPUT_FILE_NAME}" " done @@ -66,7 +66,7 @@ is_nothing_changed_since_last_check() if which pmd >/dev/null; then readonly REPORTS_DIR="${PROJECT_DIR}/code-quality-reports" - readonly CPD_COMMIT_FILE_PATH="${REPORTS_DIR}/CPDCommit.txt" + readonly CPD_COMMIT_FILE_PATH="${REPORTS_DIR}/CPDCommit" readonly CURRENT_GIT_COMMIT=`git rev-parse --verify HEAD` From 093f16a578356cdc1c0ddc5a92d67a4ec6855455 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 15 Jan 2021 11:35:26 +0300 Subject: [PATCH 04/25] remove yarn install, use new firebase plugin API --- xcode/commonFastfile | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 4feb6df..5bf6e4f 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -57,8 +57,6 @@ private_lane :uploadToFirebase do |options| releaseNotesFile = "release-notes.txt" sh("touch ../#{releaseNotesFile}") - sh("yarn install") - app_target_folder_name = options[:appName] || $appName configuration_type = Touchlane::ConfigurationType.from_type(options[:type]) @@ -70,8 +68,7 @@ private_lane :uploadToFirebase do |options| app: google_app_id, ipa_path: options[:ipa_path], groups: "touch-instinct", - release_notes_file: releaseNotesFile, - firebase_cli_path: File.expand_path("../node_modules/firebase-tools/lib/bin/firebase.js") + release_notes_file: releaseNotesFile ) upload_symbols_to_crashlytics( @@ -411,16 +408,16 @@ def generate_enabled_features_extension_if_needed(options) end if options[:features].nil? - builder_features_list = [] # If Enabled.swift exists and features option is nil we need to create empty extension to avoid unexpected features + builder_features_list = [] # If Enabled.swift exists and features option is nil we need to create empty extension to avoid unexpected features else builder_features_list = options[:features] .split(",").map { |feature_name| feature_name.strip } # [ "Feature1", "Feature2", "Feature3" ] - end + end build_settings_features_list = Managers::FileManager.load_from_file_YAML(build_settings_file_path)["features"] enabled_features_extension = Touchlane::Features.generate_enabled_features_extension(builder_features_list, build_settings_features_list) - + Managers::FileManager.save_data_to_file(project_enabled_features_file_path, enabled_features_extension) end From e0300fcd076eca13d7f679845945fd8403c5bd59 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 15 Jan 2021 18:51:15 +0300 Subject: [PATCH 05/25] remove carthage & rome --- xcode/commonFastfile | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 5bf6e4f..ec647c4 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -23,34 +23,6 @@ private_lane :installDependencies do |options| cocoapods( repo_update: true ) - - if File.exists? "../Cartfile" - use_rome = File.exists? "../Romefile" - - swift_version = sh("xcrun swift --version | head -1 | sed 's/.*\\(\(.*\)\\).*/\\1/' | tr -d \"()\" | tr \" \" \"-\"").chop - rome_path = "Pods/Rome/rome" - rome_options = "--platform iOS --cache-prefix #{swift_version} --romefile Romefile" - - carthage_install = lambda do - if use_rome - sh("cd .. && #{rome_path} download #{rome_options}") - end - - carthage(command: "bootstrap", platform: "iOS", cache_builds: true) - - if use_rome - sh("cd .. && #{rome_path} list --missing #{rome_options} | awk '{print $1}' | xargs -I framework_name #{rome_path} upload framework_name #{rome_options}") - end - end - - begin - carthage_install.call - rescue - # workaround for https://github.com/Carthage/Carthage/issues/2298 - sh("rm -rf ~/Library/Caches/org.carthage.CarthageKit") - carthage_install.call - end - end end private_lane :uploadToFirebase do |options| From be7e522f38843a3c74fb7fa749838cfb8c3d93ee Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 15 Jan 2021 18:51:53 +0300 Subject: [PATCH 06/25] copy_paste_detection refactoring --- scripts/runner.sh | 16 +++ .../common/read_input_file_names.sh | 49 ++++++++ xcode/build_phases/copy_paste_detection.sh | 118 ++++++++++++------ 3 files changed, 143 insertions(+), 40 deletions(-) create mode 100644 scripts/runner.sh create mode 100644 xcode/build_phases/common/read_input_file_names.sh diff --git a/scripts/runner.sh b/scripts/runner.sh new file mode 100644 index 0000000..2903ce2 --- /dev/null +++ b/scripts/runner.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Description: +# This is a wrapper that defines common variables and passes all parameters to sh. +# +# Example of usage: +# runner.sh copy_paste_detection.sh Generated Localization Pods +# + +readonly EXIT_SUCCESS=0 +readonly EXIT_FAILURE=1 + +readonly TRUE=0 +readonly FALSE=1 + +. $@ \ No newline at end of file diff --git a/xcode/build_phases/common/read_input_file_names.sh b/xcode/build_phases/common/read_input_file_names.sh new file mode 100644 index 0000000..0fdbf2b --- /dev/null +++ b/xcode/build_phases/common/read_input_file_names.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +# Description: +# Converts SCRIPT_INPUT_FILE_{N} variables to single string using passed separator. +# +# Parameters: +# $1 - separator to use. +# $2 - default value to return if SCRIPT_INPUT_FILE_COUNT is zero. +# +# Optional environment variables: +# FILE_NAMES_SEPARATOR - number of files listed in "Input files" of build phase. +# DEFAULT_FILE_NAMES - file path to directory that should be checked. +# +# Examples of usage: +# read_input_file_names +# read_input_file_names.sh " " path/to/project +# + +if [ -z "${FILE_NAMES_SEPARATOR}" ]; then + if [ ! -z "${1}" ]; then + FILE_NAMES_SEPARATOR=${1} + else + FILE_NAMES_SEPARATOR="" + fi +fi + +if [ -z "${DEFAULT_FILE_NAMES}" ]; then + if [ ! -z "${2}" ]; then + DEFAULT_FILE_NAMES=${2} + else + DEFAULT_FILE_NAMES="" + fi +fi + +if [ "${SCRIPT_INPUT_FILE_COUNT}" -gt 0 ] ; then + INPUT_FILE_NAMES="" + + for i in `seq 0 $((${SCRIPT_INPUT_FILE_COUNT}-1))` + do + SCRIPT_INPUT_FILE_VARIABLE_NAME="SCRIPT_INPUT_FILE_${i}" + COMMAND="echo \${${SCRIPT_INPUT_FILE_VARIABLE_NAME}}" + INPUT_FILE_NAME=`eval ${COMMAND}` + INPUT_FILE_NAMES=${INPUT_FILE_NAMES}${INPUT_FILE_NAME}" " + done + + echo ${INPUT_FILE_NAMES} +else + echo ${DEFAULT_VALUE} +fi \ No newline at end of file diff --git a/xcode/build_phases/copy_paste_detection.sh b/xcode/build_phases/copy_paste_detection.sh index 42cb778..1bd10a6 100644 --- a/xcode/build_phases/copy_paste_detection.sh +++ b/xcode/build_phases/copy_paste_detection.sh @@ -1,3 +1,5 @@ +#!/bin/sh + # Description: # Validates code for copy-paste, prints results to standard output and report file. # @@ -10,51 +12,62 @@ # Optional environment variables: # SCRIPT_INPUT_FILE_COUNT - number of files listed in "Input files" of build phase. # SCRIPT_INPUT_FILE_{N} - file path to directory that should be checked. +# REFACTORING_MODE - special bool flag for unconditional code checking. # # Modified files: # ${PROJECT_DIR}/code-quality-reports/CPDLog.txt - check report. # ${PROJECT_DIR}/code-quality-reports/CPDCommit - last checked commit. # # Example of usage: -# copy_paste_detection.sh Generated Localization Pods +# runner.sh copy_paste_detection.sh Generated Localization Pods # -readonly EXIT_SUCCESS=0 -readonly EXIT_FAILURE=1 - -read_input_file_names() +is_refactoring_mode() { - local -r DEFAULT_VALUE=${1} - - local INPUT_FILE_NAMES="" - - if [ "${SCRIPT_INPUT_FILE_COUNT}" -gt 0 ] ; then - for i in `seq 0 $((${SCRIPT_INPUT_FILE_COUNT}-1))` - do - local SCRIPT_INPUT_FILE_VARIABLE_NAME="SCRIPT_INPUT_FILE_${i}" - local COMMAND="echo \${${SCRIPT_INPUT_FILE_VARIABLE_NAME}}" - local INPUT_FILE_NAME=`eval ${COMMAND}` - INPUT_FILE_NAMES=${INPUT_FILE_NAMES}${INPUT_FILE_NAME}" " - done - - echo ${INPUT_FILE_NAMES} - else - echo ${DEFAULT_VALUE} + if [ -z "${REFACTORING_MODE}" ]; then + return ${FALSE} fi + + local -r STR_MODE=`tr "[:upper:]" "[:lower:]" <<< ${REFACTORING_MODE}` + + if [ ${STR_MODE} == "yes" ] || [ ${STR_MODE} == "true" ] || [ ${STR_MODE} == "1" ]; then + return ${TRUE} + fi + + return ${FALSE} } is_nothing_changed_since_last_check() { - local -r COMMIT_FILE_PATH=${1} - local -r LAST_LINTED_COMMIT=`cat ${COMMIT_FILE_PATH}` || "" + if is_refactoring_mode; then + echo "Refactoring mode detected. Skipping commits comparison." + return ${EXIT_FAILURE} + fi - local -r CURRENT_COMMIT=${2} - - if [[ "${CURRENT_GIT_COMMIT}" = "${LAST_LINTED_COMMIT}" ]]; then - if git diff --quiet --exit-code; then - echo "Commit your changes and build again." + if [ -z "${COMMIT_FILE_PATH}" ]; then + if [ ! -z "${1}" ]; then + local -r COMMIT_FILE_PATH=${1} else - echo "Nothing was changed since ${LAST_LINTED_COMMIT}. Skipping code checking." + echo "COMMIT_FILE_PATH should be defined or passed as first argument!" + return ${EXIT_FAILURE} + fi + fi + + if [ -z "${CURRENT_COMMIT}" ]; then + if [ ! -z "${2}" ]; then + local -r CURRENT_COMMIT=${2} + else + local -r CURRENT_COMMIT=`git rev-parse --verify HEAD` + fi + fi + + local -r LAST_CHECKED_COMMIT=`cat ${COMMIT_FILE_PATH}` || "" + + if [ ${CURRENT_COMMIT} = ${LAST_CHECKED_COMMIT} ]; then + if git diff --quiet --exit-code; then + echo "Commit your changes and run script again." + else + echo "Nothing was changed since ${LAST_CHECKED_COMMIT}. Skipping." fi return ${EXIT_SUCCESS} @@ -63,20 +76,45 @@ is_nothing_changed_since_last_check() fi } -if which pmd >/dev/null; then - readonly REPORTS_DIR="${PROJECT_DIR}/code-quality-reports" - - readonly CPD_COMMIT_FILE_PATH="${REPORTS_DIR}/CPDCommit" - - readonly CURRENT_GIT_COMMIT=`git rev-parse --verify HEAD` - - if is_nothing_changed_since_last_check ${CPD_COMMIT_FILE_PATH} ${CURRENT_GIT_COMMIT}; then +record_current_commit() +{ + if is_refactoring_mode; then + echo "Refactoring mode detected. Commit won't be recorder." exit ${EXIT_SUCCESS} fi - readonly SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + if [ -v "${CURRENT_COMMIT}" ]; then + if [ ! -v "${1}" ]; then + local -r CURRENT_COMMIT=${1} + else + local -r CURRENT_COMMIT=`git rev-parse --verify HEAD` + fi + fi - readonly SOURCES_DIRS=`read_input_file_names ${PROJECT_DIR}` + if [ -v "${COMMIT_FILE_PATH}" ]; then + if [ ! -v "${2}" ]; then + local -r COMMIT_FILE_PATH=${2} + else + echo "COMMIT_FILE_PATH should be defined or passed as second argument!" + return ${EXIT_FAILURE} + fi + fi + + echo ${CURRENT_COMMIT} > ${COMMIT_FILE_PATH} +} + +if which pmd >/dev/null; then + readonly REPORTS_DIR="${PROJECT_DIR}/code-quality-reports" + + readonly COMMIT_FILE_PATH="${REPORTS_DIR}/CPDCommit" + + readonly CURRENT_COMMIT=`git rev-parse --verify HEAD` + + if is_nothing_changed_since_last_check; then + exit ${EXIT_SUCCESS} + fi + + readonly SOURCES_DIRS=`. ${SCRIPT_DIR}/common/read_input_file_names.sh " " ${PROJECT_DIR}` readonly COMMAND_LINE_ARGUMENTS=$@ @@ -102,7 +140,7 @@ if which pmd >/dev/null; then sed -i '' "s/${SED_REPLACEMENT_STRING}//g" "${REPORTS_DIR}/CPDLog.txt" - echo ${CURRENT_GIT_COMMIT} > ${CPD_COMMIT_FILE_PATH} + record_current_commit else echo "warning: pmd not installed, install using 'brew install pmd'" From bb432d422018b5282cce28773030c4f3007468be Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Fri, 15 Jan 2021 18:58:45 +0300 Subject: [PATCH 07/25] add doc about SCRIPT_DIR variable --- xcode/build_phases/copy_paste_detection.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/xcode/build_phases/copy_paste_detection.sh b/xcode/build_phases/copy_paste_detection.sh index 1bd10a6..0ab2b1a 100644 --- a/xcode/build_phases/copy_paste_detection.sh +++ b/xcode/build_phases/copy_paste_detection.sh @@ -8,6 +8,7 @@ # # Required environment variables: # PROJECT_DIR - project directory. +# SCRIPT_DIR - directory of current script. # # Optional environment variables: # SCRIPT_INPUT_FILE_COUNT - number of files listed in "Input files" of build phase. From e2f85337c0a0bf1dbc93fd5e48637a4bc7cb12db Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 18 Jan 2021 15:54:54 +0300 Subject: [PATCH 08/25] remove REFACTORING_MODE --- xcode/build_phases/copy_paste_detection.sh | 95 +--------------------- 1 file changed, 4 insertions(+), 91 deletions(-) diff --git a/xcode/build_phases/copy_paste_detection.sh b/xcode/build_phases/copy_paste_detection.sh index 0ab2b1a..132a7d5 100644 --- a/xcode/build_phases/copy_paste_detection.sh +++ b/xcode/build_phases/copy_paste_detection.sh @@ -13,108 +13,23 @@ # Optional environment variables: # SCRIPT_INPUT_FILE_COUNT - number of files listed in "Input files" of build phase. # SCRIPT_INPUT_FILE_{N} - file path to directory that should be checked. -# REFACTORING_MODE - special bool flag for unconditional code checking. # # Modified files: # ${PROJECT_DIR}/code-quality-reports/CPDLog.txt - check report. -# ${PROJECT_DIR}/code-quality-reports/CPDCommit - last checked commit. # # Example of usage: # runner.sh copy_paste_detection.sh Generated Localization Pods # -is_refactoring_mode() -{ - if [ -z "${REFACTORING_MODE}" ]; then - return ${FALSE} - fi +readonly EXIT_SUCCESS=0 +readonly EXIT_FAILURE=1 - local -r STR_MODE=`tr "[:upper:]" "[:lower:]" <<< ${REFACTORING_MODE}` - - if [ ${STR_MODE} == "yes" ] || [ ${STR_MODE} == "true" ] || [ ${STR_MODE} == "1" ]; then - return ${TRUE} - fi - - return ${FALSE} -} - -is_nothing_changed_since_last_check() -{ - if is_refactoring_mode; then - echo "Refactoring mode detected. Skipping commits comparison." - return ${EXIT_FAILURE} - fi - - if [ -z "${COMMIT_FILE_PATH}" ]; then - if [ ! -z "${1}" ]; then - local -r COMMIT_FILE_PATH=${1} - else - echo "COMMIT_FILE_PATH should be defined or passed as first argument!" - return ${EXIT_FAILURE} - fi - fi - - if [ -z "${CURRENT_COMMIT}" ]; then - if [ ! -z "${2}" ]; then - local -r CURRENT_COMMIT=${2} - else - local -r CURRENT_COMMIT=`git rev-parse --verify HEAD` - fi - fi - - local -r LAST_CHECKED_COMMIT=`cat ${COMMIT_FILE_PATH}` || "" - - if [ ${CURRENT_COMMIT} = ${LAST_CHECKED_COMMIT} ]; then - if git diff --quiet --exit-code; then - echo "Commit your changes and run script again." - else - echo "Nothing was changed since ${LAST_CHECKED_COMMIT}. Skipping." - fi - - return ${EXIT_SUCCESS} - else - return ${EXIT_FAILURE} - fi -} - -record_current_commit() -{ - if is_refactoring_mode; then - echo "Refactoring mode detected. Commit won't be recorder." - exit ${EXIT_SUCCESS} - fi - - if [ -v "${CURRENT_COMMIT}" ]; then - if [ ! -v "${1}" ]; then - local -r CURRENT_COMMIT=${1} - else - local -r CURRENT_COMMIT=`git rev-parse --verify HEAD` - fi - fi - - if [ -v "${COMMIT_FILE_PATH}" ]; then - if [ ! -v "${2}" ]; then - local -r COMMIT_FILE_PATH=${2} - else - echo "COMMIT_FILE_PATH should be defined or passed as second argument!" - return ${EXIT_FAILURE} - fi - fi - - echo ${CURRENT_COMMIT} > ${COMMIT_FILE_PATH} -} +readonly TRUE=0 +readonly FALSE=1 if which pmd >/dev/null; then readonly REPORTS_DIR="${PROJECT_DIR}/code-quality-reports" - readonly COMMIT_FILE_PATH="${REPORTS_DIR}/CPDCommit" - - readonly CURRENT_COMMIT=`git rev-parse --verify HEAD` - - if is_nothing_changed_since_last_check; then - exit ${EXIT_SUCCESS} - fi - readonly SOURCES_DIRS=`. ${SCRIPT_DIR}/common/read_input_file_names.sh " " ${PROJECT_DIR}` readonly COMMAND_LINE_ARGUMENTS=$@ @@ -140,8 +55,6 @@ if which pmd >/dev/null; then readonly SED_REPLACEMENT_STRING=$(echo ${PROJECT_DIR} | sed "s/\//\\\\\//g") sed -i '' "s/${SED_REPLACEMENT_STRING}//g" "${REPORTS_DIR}/CPDLog.txt" - - record_current_commit else echo "warning: pmd not installed, install using 'brew install pmd'" From bd2138f58d688bf3a68f07907ac6bee817b38006 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 18 Jan 2021 15:55:07 +0300 Subject: [PATCH 09/25] update swiftlint config --- xcode/.swiftlint.yml | 53 +++++++++++--------------------------------- 1 file changed, 13 insertions(+), 40 deletions(-) diff --git a/xcode/.swiftlint.yml b/xcode/.swiftlint.yml index 35c417c..337f194 100644 --- a/xcode/.swiftlint.yml +++ b/xcode/.swiftlint.yml @@ -65,6 +65,7 @@ opt_in_rules: - identical_operands - overridden_super_call - unowned_variable_capture + - comment_spacing # metrics @@ -187,26 +188,12 @@ custom_rules: regex: '(?!\n)[^ \n]+ {2,}.+' message: "Remove excess empty spaces" severity: warning - match_kinds: - - argument - - attribute.builtin - - attribute.id - - buildconfig.id - - buildconfig.keyword - - identifier - - keyword - - number - - objectliteral - - parameter - - placeholder - # - string # all except string literals - # - comment # and comments - # - comment.mark - # - comment.url - # - doccomment - # - doccomment.field - - string_interpolation_anchor - - typeidentifier + excluded_match_kinds: + - comment + - comment.mark + - comment.url + - doccomment + - doccomment.field getter_setter_style: name: "Wrong getter/setter code style" @@ -221,26 +208,12 @@ custom_rules: regex: "(== true)|(== false)|(!= true)|(!= false)" message: "Comparing a boolean to true is redundant (use `?? false` for optionals), and `!`-syntax is preferred over comparing to false." severity: error - match_kinds: - - argument - - attribute.builtin - - attribute.id - - buildconfig.id - - buildconfig.keyword - - identifier - - keyword - - number - - objectliteral - - parameter - - placeholder - # - string # all except string literals - # - comment # and comments - # - comment.mark - # - comment.url - # - doccomment - # - doccomment.field - - string_interpolation_anchor - - typeidentifier + excluded_match_kinds: + - comment + - comment.mark + - comment.url + - doccomment + - doccomment.field redundant_ternary_operator: name: "Redundant Ternary Operator" From b27fa554fb4dab242ccf7a520e38ec918416dad3 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 18 Jan 2021 15:55:40 +0300 Subject: [PATCH 10/25] delete runner.sh, update swiftlint script --- .../common/read_input_file_names.sh | 9 +++- xcode/build_phases/swiftlint.sh | 46 ++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) mode change 100644 => 100755 xcode/build_phases/swiftlint.sh diff --git a/xcode/build_phases/common/read_input_file_names.sh b/xcode/build_phases/common/read_input_file_names.sh index 0fdbf2b..8717544 100644 --- a/xcode/build_phases/common/read_input_file_names.sh +++ b/xcode/build_phases/common/read_input_file_names.sh @@ -40,10 +40,15 @@ if [ "${SCRIPT_INPUT_FILE_COUNT}" -gt 0 ] ; then SCRIPT_INPUT_FILE_VARIABLE_NAME="SCRIPT_INPUT_FILE_${i}" COMMAND="echo \${${SCRIPT_INPUT_FILE_VARIABLE_NAME}}" INPUT_FILE_NAME=`eval ${COMMAND}` - INPUT_FILE_NAMES=${INPUT_FILE_NAMES}${INPUT_FILE_NAME}" " + INPUT_FILE_NAMES=${INPUT_FILE_NAMES}${INPUT_FILE_NAME}${FILE_NAMES_SEPARATOR} done - echo ${INPUT_FILE_NAMES} + FILE_NAMES_SEPARATOR_LENGTH=`awk '{ print length; }' <<< ${FILE_NAMES_SEPARATOR}` + INPUT_FILE_NAMES_LENGTH=`awk '{ print length; }' <<< ${INPUT_FILE_NAMES}` + INPUT_FILE_NAMES_TRIMMED_LENGTH=$((INPUT_FILE_NAMES_LENGTH - FILE_NAMES_SEPARATOR_LENGTH)) + + # remove separator suffix + echo ${INPUT_FILE_NAMES} | cut -c1-${INPUT_FILE_NAMES_TRIMMED_LENGTH} else echo ${DEFAULT_VALUE} fi \ No newline at end of file diff --git a/xcode/build_phases/swiftlint.sh b/xcode/build_phases/swiftlint.sh old mode 100644 new mode 100755 index f1f8fb8..38f8b82 --- a/xcode/build_phases/swiftlint.sh +++ b/xcode/build_phases/swiftlint.sh @@ -1,2 +1,44 @@ -SOURCES_DIR=${1:-${TARGET_NAME}} # first argument or TARGET_NAME -${PODS_ROOT}/SwiftLint/swiftlint autocorrect --path ${SOURCES_DIR} --config ${PROJECT_DIR}/build-scripts/xcode/.swiftlint.yml && ${PODS_ROOT}/SwiftLint/swiftlint --path ${SOURCES_DIR} --config ${PROJECT_DIR}/build-scripts/xcode/.swiftlint.yml +#!/bin/sh + +# Description: +# Runs swiftlint with selected or default config file. +# +# Parameters: +# $1 - path to swiftlint executable. +# $2 - path to swiftlint config. +# +# Required environment variables: +# SCRIPT_DIR - directory of current script. +# PODS_ROOT - cocoapods installation directory (eg. ${SRCROOT}/Pods). +# +# Optional environment variables: +# SWIFTLINT_EXECUTABLE - path to swiftlint executable. +# SWIFTLINT_CONFIG_PATH - path to swiftlint config. +# +# Example of usage: +# swiftlint.sh +# swiftlint.sh Pods/Swiftlint/swiftlint build-scripts/xcode/.swiftlint.yml +# + +readonly SOURCES_DIRS=`. ${SCRIPT_DIR}/common/read_input_file_names.sh "\n" ${PROJECT_DIR}` + +if [ -z "${SWIFTLINT_EXECUTABLE}" ]; then + if [ ! -z "${1}" ]; then + readonly SWIFTLINT_EXECUTABLE=${1} + else + readonly SWIFTLINT_EXECUTABLE=${PODS_ROOT}/SwiftLint/swiftlint + fi +fi + +if [ -z "${SWIFTLINT_CONFIG_PATH}" ]; then + if [ ! -z "${2}" ]; then + readonly SWIFTLINT_CONFIG_PATH=${2} + else + readonly SWIFTLINT_CONFIG_PATH=${SCRIPT_DIR}/../.swiftlint.yml + fi +fi + +for SOURCE_DIR in ${SOURCES_DIRS}; do + ${SWIFTLINT_EXECUTABLE} autocorrect --path ${SOURCE_DIR} --config ${SWIFTLINT_CONFIG_PATH} + ${SWIFTLINT_EXECUTABLE} --path ${SOURCE_DIR} --config ${SWIFTLINT_CONFIG_PATH} +done From a682c25dd544ce096857a8821bdadd8bac0e4dda Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 18 Jan 2021 15:57:16 +0300 Subject: [PATCH 11/25] misunstaged runner.sh --- scripts/runner.sh | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 scripts/runner.sh diff --git a/scripts/runner.sh b/scripts/runner.sh deleted file mode 100644 index 2903ce2..0000000 --- a/scripts/runner.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -# Description: -# This is a wrapper that defines common variables and passes all parameters to sh. -# -# Example of usage: -# runner.sh copy_paste_detection.sh Generated Localization Pods -# - -readonly EXIT_SUCCESS=0 -readonly EXIT_FAILURE=1 - -readonly TRUE=0 -readonly FALSE=1 - -. $@ \ No newline at end of file From 7819b0e4cdb6f251be5533b43c5ba55fc0b4296d Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 18 Jan 2021 16:18:00 +0300 Subject: [PATCH 12/25] add doc about SRCROOT --- xcode/build_phases/swiftlint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xcode/build_phases/swiftlint.sh b/xcode/build_phases/swiftlint.sh index 38f8b82..d148924 100755 --- a/xcode/build_phases/swiftlint.sh +++ b/xcode/build_phases/swiftlint.sh @@ -9,6 +9,7 @@ # # Required environment variables: # SCRIPT_DIR - directory of current script. +# SRCROOT - project directory. # PODS_ROOT - cocoapods installation directory (eg. ${SRCROOT}/Pods). # # Optional environment variables: @@ -20,7 +21,7 @@ # swiftlint.sh Pods/Swiftlint/swiftlint build-scripts/xcode/.swiftlint.yml # -readonly SOURCES_DIRS=`. ${SCRIPT_DIR}/common/read_input_file_names.sh "\n" ${PROJECT_DIR}` +readonly SOURCES_DIRS=`. ${SCRIPT_DIR}/common/read_input_file_names.sh "\n" ${SRCROOT}` if [ -z "${SWIFTLINT_EXECUTABLE}" ]; then if [ ! -z "${1}" ]; then From ca37784c577145c16039a8b6f48b721ee94a0c54 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 18 Jan 2021 16:36:18 +0300 Subject: [PATCH 13/25] add doc to swiftlint about input files --- xcode/build_phases/swiftlint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xcode/build_phases/swiftlint.sh b/xcode/build_phases/swiftlint.sh index d148924..5052f54 100755 --- a/xcode/build_phases/swiftlint.sh +++ b/xcode/build_phases/swiftlint.sh @@ -15,6 +15,8 @@ # Optional environment variables: # SWIFTLINT_EXECUTABLE - path to swiftlint executable. # SWIFTLINT_CONFIG_PATH - path to swiftlint config. +# SCRIPT_INPUT_FILE_COUNT - number of files listed in "Input files" of build phase. +# SCRIPT_INPUT_FILE_{N} - file path to directory that should be checked. # # Example of usage: # swiftlint.sh From 8794713900d9812f5c46863793a5fc6cfc208c7f Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 18 Jan 2021 18:19:41 +0300 Subject: [PATCH 14/25] add smart skipping for api_generator script --- xcode/build_phases/api_generator.sh | 141 ++++++++++++++++++++- xcode/build_phases/copy_paste_detection.sh | 3 - 2 files changed, 138 insertions(+), 6 deletions(-) mode change 100644 => 100755 xcode/build_phases/api_generator.sh mode change 100644 => 100755 xcode/build_phases/copy_paste_detection.sh diff --git a/xcode/build_phases/api_generator.sh b/xcode/build_phases/api_generator.sh old mode 100644 new mode 100755 index cb09e6b..2c99954 --- a/xcode/build_phases/api_generator.sh +++ b/xcode/build_phases/api_generator.sh @@ -1,9 +1,144 @@ +#!/bin/sh + +# Description: +# Generates API models & methods. +# +# Parameters: +# $1 - api generator version. +# +# Optional environment variables: +# OUTPUT_PATH - path to Generated folder. +# +# Examples of usage: +# . api_generator.sh 1.4.0-beta1 +# . api_generator.sh 1.4.0-beta1 ${TARGET_NAME}/Generated +# + +readonly EXIT_SUCCESS=0 +readonly EXIT_FAILURE=1 + +readonly TRUE=0 +readonly FALSE=1 + +is_force_run() +{ + if [ -z "${FORCE_RUN}" ]; then + return ${FALSE} + fi + + local -r STR_MODE=`tr "[:upper:]" "[:lower:]" <<< ${FORCE_RUN}` + + if [ ${STR_MODE} == "yes" ] || [ ${STR_MODE} == "true" ] || [ ${STR_MODE} == "1" ]; then + return ${TRUE} + fi + + return ${FALSE} +} + +get_current_commit() +{ + if [ -z "${CURRENT_COMMIT}" ]; then + if [ -z "${REPO_PATH}" ]; then + if [ ! -z "${1}" ]; then + echo `git -C ${1} rev-parse --verify HEAD` + else + echo `git rev-parse --verify HEAD` + fi + else + echo `git -C ${REPO_PATH} rev-parse --verify HEAD` + fi + else + echo ${CURRENT_COMMIT} + fi +} + +is_nothing_changed_since_last_check() +{ + if is_force_run; then + echo "Force run detected. Skipping commits comparison." + return ${EXIT_FAILURE} + fi + + if [ -z "${COMMIT_FILE_PATH}" ]; then + if [ ! -z "${1}" ]; then + local -r COMMIT_FILE_PATH=${1} + else + echo "COMMIT_FILE_PATH should be defined or passed as first argument!" + return ${EXIT_FAILURE} + fi + fi + + if [ -z "${2}" ]; then + local -r CURRENT_COMMIT=`get_current_commit` + else + local -r CURRENT_COMMIT=${2} + fi + + local -r LAST_CHECKED_COMMIT=`cat ${COMMIT_FILE_PATH}` || "" + + if [ ${CURRENT_COMMIT} = "${LAST_CHECKED_COMMIT}" ]; then + return ${EXIT_SUCCESS} + else + return ${EXIT_FAILURE} + fi +} + +record_current_commit() +{ + if is_force_run; then + echo "Force run detected. Commit won't be recorder." + exit ${EXIT_SUCCESS} + fi + + if [ -z "${1}" ]; then + local -r CURRENT_COMMIT=`get_current_commit` + else + local -r CURRENT_COMMIT=${1} + fi + + if [ -z "${COMMIT_FILE_PATH}" ]; then + if [ ! -v "${2}" ]; then + local -r COMMIT_FILE_PATH=${2} + else + echo "COMMIT_FILE_PATH should be defined or passed as second argument!" + return ${EXIT_FAILURE} + fi + fi + + echo ${CURRENT_COMMIT} > ${COMMIT_FILE_PATH} +} + +readonly BUILD_PHASES_DIR=${SRCROOT}/build_phases + +mkdir -p ${BUILD_PHASES_DIR} + +readonly COMMIT_FILE_PATH=${BUILD_PHASES_DIR}/api-generator-commit + +readonly REPO_PATH="common" + +if is_nothing_changed_since_last_check; then + echo "Nothing was changed models generation skipped." + exit ${EXIT_SUCCESS} +fi + VERSION=$1 FILE_NAME="api-generator-${VERSION}.jar" +if [ -z "${OUTPUT_PATH}" ]; then + if [ ! -z "${2}" ]; then + readonly OUTPUT_PATH=${2} + else + readonly OUTPUT_PATH="Generated" + fi +fi + +mkdir -p ${OUTPUT_PATH} + # download api generator -link="https://dl.bintray.com/touchin/touchin-tools/ru/touchin/api-generator/${VERSION}/${FILE_NAME}" -. build-scripts/xcode/aux_scripts/download_file.sh ${FILE_NAME} ${link} +readonly DOWNLOAD_URL="https://dl.bintray.com/touchin/touchin-tools/ru/touchin/api-generator/${VERSION}/${FILE_NAME}" +. build-scripts/xcode/aux_scripts/download_file.sh ${FILE_NAME} ${DOWNLOAD_URL} # execute api generator -java -Xmx6g -jar "Downloads/${FILE_NAME}" generate-client-code --output-language SWIFT --specification-path common/api --output-path ${PRODUCT_NAME}/Generated --single-file true +java -Xmx6g -jar "Downloads/${FILE_NAME}" generate-client-code --output-language SWIFT --specification-path common/api --output-path ${OUTPUT_PATH} --single-file true + +record_current_commit diff --git a/xcode/build_phases/copy_paste_detection.sh b/xcode/build_phases/copy_paste_detection.sh old mode 100644 new mode 100755 index 132a7d5..653b093 --- a/xcode/build_phases/copy_paste_detection.sh +++ b/xcode/build_phases/copy_paste_detection.sh @@ -24,9 +24,6 @@ readonly EXIT_SUCCESS=0 readonly EXIT_FAILURE=1 -readonly TRUE=0 -readonly FALSE=1 - if which pmd >/dev/null; then readonly REPORTS_DIR="${PROJECT_DIR}/code-quality-reports" From 0546268696d3880c5527586d49da6a270a27d8ab Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 21 Jan 2021 12:03:34 +0300 Subject: [PATCH 15/25] add support for xcfilelist list in read_input_file_names --- .../common/read_input_file_names.sh | 55 ++++++++++++++----- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/xcode/build_phases/common/read_input_file_names.sh b/xcode/build_phases/common/read_input_file_names.sh index 8717544..2a37807 100644 --- a/xcode/build_phases/common/read_input_file_names.sh +++ b/xcode/build_phases/common/read_input_file_names.sh @@ -1,15 +1,20 @@ #!/bin/sh # Description: -# Converts SCRIPT_INPUT_FILE_{N} variables to single string using passed separator. +# Converts SCRIPT_INPUT_FILE_{N} or SCRIPT_INPUT_FILE_LIST_{N} variables to string that contains +# list of file names splitted by given separator. # # Parameters: # $1 - separator to use. -# $2 - default value to return if SCRIPT_INPUT_FILE_COUNT is zero. +# $2 - default value to return if SCRIPT_INPUT_FILE_COUNT or SCRIPT_INPUT_FILE_LIST_COUNT is zero. # # Optional environment variables: -# FILE_NAMES_SEPARATOR - number of files listed in "Input files" of build phase. -# DEFAULT_FILE_NAMES - file path to directory that should be checked. +# FILE_NAMES_SEPARATOR - separator to use. +# DEFAULT_FILE_NAMES - default value if was found in environment variables. +# SCRIPT_INPUT_FILE_COUNT - number of files listed in "Input files" section of build phase. +# SCRIPT_INPUT_FILE_{N} - file path of specific input file at index. +# SCRIPT_INPUT_FILE_LIST_COUNT - number of files listed in "Input File Lists" section of build phase. +# SCRIPT_INPUT_FILE_LIST_{N} - file path to specifis xcfilelist file at index. # # Examples of usage: # read_input_file_names @@ -32,23 +37,43 @@ if [ -z "${DEFAULT_FILE_NAMES}" ]; then fi fi -if [ "${SCRIPT_INPUT_FILE_COUNT}" -gt 0 ] ; then - INPUT_FILE_NAMES="" +INPUT_FILE_NAMES="" + +if [ ! -z "${SCRIPT_INPUT_FILE_COUNT}" ] && \ + [ ${SCRIPT_INPUT_FILE_COUNT} -gt 0 ]; then for i in `seq 0 $((${SCRIPT_INPUT_FILE_COUNT}-1))` do SCRIPT_INPUT_FILE_VARIABLE_NAME="SCRIPT_INPUT_FILE_${i}" - COMMAND="echo \${${SCRIPT_INPUT_FILE_VARIABLE_NAME}}" - INPUT_FILE_NAME=`eval ${COMMAND}` - INPUT_FILE_NAMES=${INPUT_FILE_NAMES}${INPUT_FILE_NAME}${FILE_NAMES_SEPARATOR} + SHELL_VARIABLE="\${${SCRIPT_INPUT_FILE_VARIABLE_NAME}}" + RESOLVED_FILE_NAME=`envsubst <<< ${SHELL_VARIABLE}` + INPUT_FILE_NAMES=${INPUT_FILE_NAMES}${FILE_NAMES_SEPARATOR}${RESOLVED_FILE_NAME} done - FILE_NAMES_SEPARATOR_LENGTH=`awk '{ print length; }' <<< ${FILE_NAMES_SEPARATOR}` - INPUT_FILE_NAMES_LENGTH=`awk '{ print length; }' <<< ${INPUT_FILE_NAMES}` - INPUT_FILE_NAMES_TRIMMED_LENGTH=$((INPUT_FILE_NAMES_LENGTH - FILE_NAMES_SEPARATOR_LENGTH)) + FILE_NAMES_SEPARATOR_LENGTH=`awk '{ print length; }' <<< "${FILE_NAMES_SEPARATOR}"` - # remove separator suffix - echo ${INPUT_FILE_NAMES} | cut -c1-${INPUT_FILE_NAMES_TRIMMED_LENGTH} + if [ ${FILE_NAMES_SEPARATOR_LENGTH} -gt 0 ] && \ + [ ! -z "${INPUT_FILE_NAMES}" ]; then + + # remove separator prefix + INPUT_FILE_NAMES=`cut -c${FILE_NAMES_SEPARATOR_LENGTH}- <<< ${INPUT_FILE_NAMES}` + fi +elif [ "${SCRIPT_INPUT_FILE_LIST_COUNT}" -gt 0 ]; then + for i in `seq 0 $((${SCRIPT_INPUT_FILE_LIST_COUNT}-1))` + do + SCRIPT_INPUT_FILE_LIST_VARIABLE_NAME="SCRIPT_INPUT_FILE_LIST_${i}" + SHELL_VARIABLE="\${${SCRIPT_INPUT_FILE_LIST_VARIABLE_NAME}}" + FILE_NAME=`envsubst <<< ${SHELL_VARIABLE}` + RESOLVED_FILE_NAMES=`envsubst < ${FILE_NAME}` + + for INPUT_FILE_NAME in ${RESOLVED_FILE_NAMES}; do + INPUT_FILE_NAMES=${INPUT_FILE_NAMES}${INPUT_FILE_NAME}${FILE_NAMES_SEPARATOR} + done + done +fi + +if [ -z "${INPUT_FILE_NAMES}" ]; then + echo ${DEFAULT_FILE_NAMES} else - echo ${DEFAULT_VALUE} + echo ${INPUT_FILE_NAMES} fi \ No newline at end of file From d0256372c1e352fb1e6d96981b9e58a0d0552783 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 21 Jan 2021 17:28:52 +0300 Subject: [PATCH 16/25] add check for simultaneous usage of Input Files and Input File Lists --- .../common/read_input_file_names.sh | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/xcode/build_phases/common/read_input_file_names.sh b/xcode/build_phases/common/read_input_file_names.sh index 2a37807..8d3f543 100644 --- a/xcode/build_phases/common/read_input_file_names.sh +++ b/xcode/build_phases/common/read_input_file_names.sh @@ -21,11 +21,21 @@ # read_input_file_names.sh " " path/to/project # +has_input_files() +{ + [ ! -z "${SCRIPT_INPUT_FILE_COUNT}" ] && [ ${SCRIPT_INPUT_FILE_COUNT} -gt 0 ] +} + +has_input_file_lists() +{ + [ ! -z "${SCRIPT_INPUT_FILE_LIST_COUNT}" ] && [ ${SCRIPT_INPUT_FILE_LIST_COUNT} -gt 0 ] +} + if [ -z "${FILE_NAMES_SEPARATOR}" ]; then if [ ! -z "${1}" ]; then FILE_NAMES_SEPARATOR=${1} else - FILE_NAMES_SEPARATOR="" + FILE_NAMES_SEPARATOR=" " fi fi @@ -39,7 +49,11 @@ fi INPUT_FILE_NAMES="" -if [ ! -z "${SCRIPT_INPUT_FILE_COUNT}" ] && \ +if has_input_files && has_input_file_lists; then + >&2 echo "Passing Input Files and Input Files Lists is not supported!\nOnly Input Files will be used." +fi + +if has_input_files && \ [ ${SCRIPT_INPUT_FILE_COUNT} -gt 0 ]; then for i in `seq 0 $((${SCRIPT_INPUT_FILE_COUNT}-1))` @@ -58,7 +72,7 @@ if [ ! -z "${SCRIPT_INPUT_FILE_COUNT}" ] && \ # remove separator prefix INPUT_FILE_NAMES=`cut -c${FILE_NAMES_SEPARATOR_LENGTH}- <<< ${INPUT_FILE_NAMES}` fi -elif [ "${SCRIPT_INPUT_FILE_LIST_COUNT}" -gt 0 ]; then +elif has_input_file_lists; then for i in `seq 0 $((${SCRIPT_INPUT_FILE_LIST_COUNT}-1))` do SCRIPT_INPUT_FILE_LIST_VARIABLE_NAME="SCRIPT_INPUT_FILE_LIST_${i}" From f0e0cb7e02b0e784dcb0db1101c386fabb545727 Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 11 Feb 2021 18:22:14 +0300 Subject: [PATCH 17/25] add fallthrough rule, use warnings instead of errors for most kind of custom rules --- xcode/.swiftlint.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/xcode/.swiftlint.yml b/xcode/.swiftlint.yml index 337f194..0d26641 100644 --- a/xcode/.swiftlint.yml +++ b/xcode/.swiftlint.yml @@ -33,6 +33,7 @@ opt_in_rules: - extension_access_modifier - explicit_init - prefer_zero_over_explicit_init + - fallthrough # style @@ -201,13 +202,13 @@ custom_rules: match_kinds: - keyword message: "Make a new line break when use getter or setter" - severity: error + severity: warning redundant_boolean_condition: name: "Redundant Boolean Condition" regex: "(== true)|(== false)|(!= true)|(!= false)" message: "Comparing a boolean to true is redundant (use `?? false` for optionals), and `!`-syntax is preferred over comparing to false." - severity: error + severity: warning excluded_match_kinds: - comment - comment.mark @@ -219,43 +220,43 @@ custom_rules: name: "Redundant Ternary Operator" regex: "(\\? true \\: false)|(\\? false \\: true)" message: "Returning a boolean as true is redundant, and `!`-syntax is preferred over returning as false." - severity: error + severity: warning single_line_closure: name: "Single line closure" regex: '\{([^\n\/]*\[[^\]]+\][^\n\/]*)?([^\n\/]*[a-zA-Z]\w*(, \w+)*)? in [^\n\/]+' message: "Too complex expression for single line closure. Improve readability by making it multiline." - severity: error + severity: warning addSubview_in_cell: name: "Usage addSubview in cell" regex: '(extension|class)\s*\w+Cell(:| )(?s).*(self\.|\s{2,})add(Subv|V)iews?\(\w' message: "Use сontentView instead of self for addSubview or addSubviews methods in cell." - severity: error + severity: warning redundant_type_annotation_bool: name: "Redundant type annotation for Bool" regex: '\s((var|let))\s{1,}\w+ *((: *Bool *=)|((\w| |<|>|:)*= *BehaviorRelay\( *value *:)) *((true)|(false))' message: "Using a type annotation for Bool is redundant." - severity: error + severity: warning parameter_repetition: name: "Parameter repetition" regex: 'func ((\w+([A-Z]\w+))|(\w+)) *(<[^>]+>)? *\( *(?i)(\3|\4):' message: "The parameter name is actually used in the function name. Use _ instead." - severity: error + severity: warning parameter_closure: name: "Parameter closure" regex: '\w*Closure<[^\r\n\t\f\v]*, Void[^\r\n\t\f\v]*>' message: "Use `ParameterClosure` instead of declaring an explicit return value of `Void`." - severity: error + severity: warning strong_self: name: "Strong self" regex: '(if|guard)\s+let\s+self\s+=\s+self' message: "Use a local function instead of capture strong self" - severity: error + severity: warning # Rx From 2c0e89dbf5c876029517217e2512948252d2c3b1 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 9 Mar 2021 13:14:49 +0300 Subject: [PATCH 18/25] Add path to pmd --- xcode/build_phases/copy_paste_detection.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xcode/build_phases/copy_paste_detection.sh b/xcode/build_phases/copy_paste_detection.sh index 653b093..b3b1f04 100755 --- a/xcode/build_phases/copy_paste_detection.sh +++ b/xcode/build_phases/copy_paste_detection.sh @@ -24,7 +24,7 @@ readonly EXIT_SUCCESS=0 readonly EXIT_FAILURE=1 -if which pmd >/dev/null; then +if which /usr/local/bin/pmd >/dev/null; then readonly REPORTS_DIR="${PROJECT_DIR}/code-quality-reports" readonly SOURCES_DIRS=`. ${SCRIPT_DIR}/common/read_input_file_names.sh " " ${PROJECT_DIR}` @@ -44,7 +44,7 @@ if which pmd >/dev/null; then mkdir -p ${REPORTS_DIR} - pmd cpd --files ${SOURCES_DIRS} --exclude ${FILES_TO_EXCLUDE} --minimum-tokens 50 --language swift --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer --failOnViolation true > ${REPORTS_DIR}/cpd-output.xml + /usr/local/bin/pmd cpd --files ${SOURCES_DIRS} --exclude ${FILES_TO_EXCLUDE} --minimum-tokens 50 --language swift --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer --failOnViolation true > ${REPORTS_DIR}/cpd-output.xml php ${SCRIPT_DIR}/../aux_scripts/cpd_script.php ${REPORTS_DIR}/cpd-output.xml | tee ${REPORTS_DIR}/CPDLog.txt From e5c4db8c108ff32572bdabcfc58b48d2c0dca5a1 Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 12 Mar 2021 19:41:16 +0300 Subject: [PATCH 19/25] Add resources to exclude --- xcode/.swiftlint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/xcode/.swiftlint.yml b/xcode/.swiftlint.yml index 0d26641..2747b3e 100644 --- a/xcode/.swiftlint.yml +++ b/xcode/.swiftlint.yml @@ -77,6 +77,7 @@ excluded: - Pods - Generated - "**/Generated" + - "**/Resources" line_length: warning: 128 From fc1c0ac74b452fd64dbbea7b582817e2c1fea78a Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 23 Mar 2021 16:29:00 +0300 Subject: [PATCH 20/25] Add cpde generation phase --- xcode/commonFastfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 6319ae9..5a6ad82 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -108,6 +108,7 @@ private_lane :buildConfiguration do |options| installDependencies(options) + run_code_generation_phase_if_needed() generate_enabled_features_extension_if_needed(options) if !(options[:uploadToFabric] || options[:uploadToAppStore]) @@ -425,3 +426,14 @@ def set_xcconfig_for_configuration_of_project(lane_name, configuration, xcodepro project.save() end + +# Build phases + +def run_code_generation_phase_if_needed() + code_generation_script_path = File.expand_path "../.githooks/scripts/CodeGen.sh" + + if File.exists? code_generation_script_path + sh(code_generation_script_path) + end + +end From f5d3b7e4ea8f47bac1e14e2add1f563bd4df910a Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 23 Mar 2021 16:49:22 +0300 Subject: [PATCH 21/25] Add xcodeproj_path to code generation --- xcode/commonFastfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 5a6ad82..950a2d8 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -429,11 +429,12 @@ end # Build phases -def run_code_generation_phase_if_needed() +def run_code_generation_phase_if_needed(options) code_generation_script_path = File.expand_path "../.githooks/scripts/CodeGen.sh" + xcodeproj_path = File.expand_path options[:xcodeproj_path] if File.exists? code_generation_script_path - sh(code_generation_script_path) + sh("code_generation_script_path ${xcodeproj_path}") end end From 43485eb8f5076f94a56ec52f44fac7ea0cb3c563 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 23 Mar 2021 16:56:39 +0300 Subject: [PATCH 22/25] Correct params input to sh --- xcode/commonFastfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 950a2d8..92a3102 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -434,7 +434,7 @@ def run_code_generation_phase_if_needed(options) xcodeproj_path = File.expand_path options[:xcodeproj_path] if File.exists? code_generation_script_path - sh("code_generation_script_path ${xcodeproj_path}") + sh("#{code_generation_script_path} #{xcodeproj_path}") end end From ddf7e0228b06c2d76d309b37541a2738c60c82f3 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 23 Mar 2021 17:07:09 +0300 Subject: [PATCH 23/25] Correct code generation input --- xcode/commonFastfile | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index 92a3102..f4d4e61 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -89,12 +89,12 @@ private_lane :buildConfiguration do |options| configuration_type = Touchlane::ConfigurationType.from_lane_name(lane_name) options = fill_up_options_using_configuration_type(options, configuration_type) - openKeychain(options) + #openKeychain(options) if !options[:buildNumber].nil? - increment_build_number( - build_number: options[:buildNumber] - ) + #increment_build_number( + # build_number: options[:buildNumber] + #) end ipa_name = "#{appName}.ipa" @@ -106,9 +106,9 @@ private_lane :buildConfiguration do |options| options[:xcodeproj_path] = "../#{appName}.xcodeproj" options[:workspace] = "./#{appName}.xcworkspace" - installDependencies(options) + #installDependencies(options) - run_code_generation_phase_if_needed() + run_code_generation_phase_if_needed(options) generate_enabled_features_extension_if_needed(options) if !(options[:uploadToFabric] || options[:uploadToAppStore]) @@ -433,8 +433,9 @@ def run_code_generation_phase_if_needed(options) code_generation_script_path = File.expand_path "../.githooks/scripts/CodeGen.sh" xcodeproj_path = File.expand_path options[:xcodeproj_path] + if File.exists? code_generation_script_path - sh("#{code_generation_script_path} #{xcodeproj_path}") + sh(code_generation_script_path, xcodeproj_path) end end From 8529a6f41f4a44928eb24a8bc0ed7c04abf7a125 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 23 Mar 2021 17:37:51 +0300 Subject: [PATCH 24/25] Remove comments --- xcode/commonFastfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index f4d4e61..f939208 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -89,12 +89,12 @@ private_lane :buildConfiguration do |options| configuration_type = Touchlane::ConfigurationType.from_lane_name(lane_name) options = fill_up_options_using_configuration_type(options, configuration_type) - #openKeychain(options) + openKeychain(options) if !options[:buildNumber].nil? - #increment_build_number( - # build_number: options[:buildNumber] - #) + increment_build_number( + build_number: options[:buildNumber] + ) end ipa_name = "#{appName}.ipa" @@ -106,7 +106,7 @@ private_lane :buildConfiguration do |options| options[:xcodeproj_path] = "../#{appName}.xcodeproj" options[:workspace] = "./#{appName}.xcworkspace" - #installDependencies(options) + installDependencies(options) run_code_generation_phase_if_needed(options) generate_enabled_features_extension_if_needed(options) From bfad757f236486b21aeb85ff23a822a3b30ffb83 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 23 Mar 2021 17:54:53 +0300 Subject: [PATCH 25/25] Remove empty spaces --- xcode/commonFastfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/xcode/commonFastfile b/xcode/commonFastfile index f939208..e7f4c13 100644 --- a/xcode/commonFastfile +++ b/xcode/commonFastfile @@ -433,9 +433,7 @@ def run_code_generation_phase_if_needed(options) code_generation_script_path = File.expand_path "../.githooks/scripts/CodeGen.sh" xcodeproj_path = File.expand_path options[:xcodeproj_path] - if File.exists? code_generation_script_path sh(code_generation_script_path, xcodeproj_path) end - end