Created
February 2, 2024 16:19
-
-
Save tooszovski/be9cba25c7fc9d7a4c121a96d9b29e6e to your computer and use it in GitHub Desktop.
up_version.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
require 'xcodeproj' | |
project_path = 'path/to/ProjectName.xcodeproj' | |
project = Xcodeproj::Project.open(project_path) | |
# Флаг для инкремента версии хотфикса | |
increment_hotfix = ARGV.include?('--increment-hotfix') | |
# Находим нужную конфигурацию сборки и читаем текущую marketing_version | |
current_version = nil | |
project.targets.each do |target| | |
target.build_configurations.each do |config| | |
if config.build_settings['MARKETING_VERSION'] | |
current_version = config.build_settings['MARKETING_VERSION'] | |
break | |
end | |
end | |
break if current_version | |
end | |
unless current_version | |
puts "MARKETING_VERSION not found." | |
exit | |
end | |
# Разбиение версии на компоненты | |
year, release_number, hotfix_version = current_version.split('.').map(&:to_i) | |
# Получение текущего года и месяца | |
current_year = Date.today.year | |
current_month = Date.today.month | |
# Обновление компонентов версии | |
if year != current_year || (release_number != current_month && !increment_hotfix) | |
year = current_year | |
release_number = current_month | |
hotfix_version = 1 | |
elsif increment_hotfix | |
hotfix_version += 1 | |
end | |
# Формирование новой версии | |
new_version = [year, release_number, hotfix_version].join('.') | |
# Обновление версии во всех target и конфигурациях | |
project.targets.each do |target| | |
target.build_configurations.each do |config| | |
config.build_settings['MARKETING_VERSION'] = new_version | |
end | |
end | |
# Сохранение изменений в файле project.pbxproj | |
project.save | |
puts "Updated MARKETING_VERSION to #{new_version}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment