Xcode 4: Update CFBundleVersion on each build using Git repo commit version

前端 未结 3 1551
悲哀的现实
悲哀的现实 2020-12-28 10:40

I\'m using Xcode 4 in combination with Git and would like to increment the CFBundleVersion in Info.plist on each build. The value for the key CFBundleVersion should be updat

3条回答
  •  自闭症患者
    2020-12-28 11:37

    This works perfectly for me

    #!/usr/bin/ruby
    
    require 'rubygems'
        begin
            require 'Plist'
            rescue LoadError => e
            puts "You need to install the 'Plist' gem: [sudo] gem install plist"
        exit 1
    end
    
    raise "Must be run from Xcode" unless ENV['XCODE_VERSION_ACTUAL']
    
    GIT = "/usr/bin/env git"
    PRODUCT_PLIST = File.join(ENV['BUILT_PRODUCTS_DIR'], ENV['INFOPLIST_PATH'])
    HASH = `#{GIT} log -1 --pretty=format:%h`
    BUNDLE_VERSION = "CFBundleVersion"
    
    if File.file?(PRODUCT_PLIST) and HASH
    
        # update product plist
        `/usr/bin/plutil -convert xml1 \"#{PRODUCT_PLIST}\"`
        info = Plist::parse_xml(PRODUCT_PLIST)
        if info
            info[BUNDLE_VERSION] = HASH
            info["GCGitCommitHash"] = HASH
            info.save_plist(PRODUCT_PLIST)
        end
        `/usr/bin/plutil -convert binary1 \"#{PRODUCT_PLIST}\"`
    
        # log
        puts "updated #{BUNDLE_VERSION} to #{HASH}"
        puts "HEAD: #{HASH}"
    end
    

提交回复
热议问题