Как автоматически установить версию и номер сборки Service Pu sh Extension - PullRequest
0 голосов
/ 19 июня 2020

Привет, в моем проекте у меня есть скрипт двух типов для увеличения моей версии проекта и номера сборки при фиксации.

#!/usr/bin/ruby

require "rubygems"
require "plist"

# fail if not run from Xcode
unless ENV['XCODE_VERSION_ACTUAL']
    puts "error: Must be run from Xcode's Run Script Build Phase"
    exit false
end

revision = `svnversion`.chomp

if not $?.success?
    puts "error: svnversion failed"
    exit false
end

if revision =~ /[^0-9]/
    if ENV['CONFIGURATION'] == 'Release'
        puts "error: Working copy has mixed revision or uncommitted changes, cannot build in #{ENV['CONFIGURATION']} configuration"
        exit false
    end

    mixed_revision = revision
    revision = revision[/[0-9]+/] or '0'
    puts "warning: Mixed/flagged revision #{mixed_revision} corrected to #{revision}"
end

plistFile = "#{ENV['BUILT_PRODUCTS_DIR']}/#{ENV['INFOPLIST_PATH']}"
`/usr/bin/plutil -convert xml1 "#{plistFile}"`
unless pl = Plist::parse_xml(plistFile) 
    puts "Could parse #{plistFile}"
    exit
end

freshPlFile = "#{ENV['SOURCE_ROOT']}/Resources/Info.plist"
`/usr/bin/plutil -convert xml1 "#{freshPlFile}"`
unless freshPl = Plist::parse_xml(freshPlFile)
    puts "Could parse #{freshPlFile}"
   exit
end


begin
    file = File.new("Resources/brands/#{ENV['BRAND_NAME']}/versions.txt", "r")
    while (line = file.gets)
        strp_line = line.strip
        strp_line.gsub!(/ /,'')
        strp_line.gsub!("ver",'')
        equal_pos = strp_line.index('=')
        str_len = strp_line.length
        if strp_line[0,equal_pos] == freshPl["CFBundleShortVersionString"]
            puts "Custom version found: #{strp_line[equal_pos+1,str_len -1]}"
            pl["CFBundleShortVersionString"] = strp_line[equal_pos+1,str_len -1]
            next
        end
    end
    file.close
rescue => err
    puts "Exception: #{err}"
    err
end

version = pl["CFBundleShortVersionString"].gsub(/ \([a-f0-9 \/:]*\)/, '')
# keep only the major and minor version number and add the revision
version.gsub!(/([^\.]*)\.([^\.]*).*/, "\\1.\\2.#{revision}");

pl["CFBundleShortVersionString"] = version
pl["CFBundleVersion"] = Time.now.utc.strftime("%Y%m%d%H%M%S")

pl.save_plist(plistFile)

`/usr/bin/plutil -convert binary1 #{plistFile}`

puts "#{plistFile}:"
puts "CFBundleVersion = #{pl["CFBundleVersion"]}"
puts "CFBundleShortVersionString = #{pl["CFBundleShortVersionString"]}"

#!/usr/bin/ruby

require "rubygems"
require "plist"

# fail if not run from Xcode
unless ENV['XCODE_VERSION_ACTUAL']
    puts "error: Must be run from Xcode's Run Script Build Phase"
    exit false
end

if ENV['EXPORT_COMPLIANCE_CODE']
    plistFile = "#{ENV['BUILT_PRODUCTS_DIR']}/#{ENV['INFOPLIST_PATH']}"
    `/usr/bin/plutil -convert xml1 "#{plistFile}"`
    unless pl = Plist::parse_xml(plistFile) 
        puts "Could parse #{plistFile}"
        exit
    end

    freshPlFile = "#{ENV['SOURCE_ROOT']}/Resources/Info.plist"
    `/usr/bin/plutil -convert xml1 "#{freshPlFile}"`
    unless freshPl = Plist::parse_xml(freshPlFile)
        puts "Could parse #{freshPlFile}"
        exit
    end

    pl['ITSAppUsesNonExemptEncryption'] = true
    pl['ITSEncryptionExportComplianceCode'] = ENV['EXPORT_COMPLIANCE_CODE']

    pl.save_plist(plistFile)

    `/usr/bin/plutil -convert binary1 #{plistFile}`
end

Когда я добавляю расширение pu sh в свой проект , мне нужно увеличить номер версии и сборки в соответствии с моим проектом, я не знаю, куда добавить их путь. Я думал в plistFile, но не уверен. Любая помощь ценится.

...