Class: Pod::Command::Release

Inherits:
Pod::Command show all
Defined in:
lib/pod/command/release.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Release

Returns a new instance of Release.



24
25
26
27
28
29
30
# File 'lib/pod/command/release.rb', line 24

def initialize(argv)
  warnings = argv.flag?('allow-warnings')
  @allow_warnings = warnings ? "--allow-warnings" : ""
  @repo = argv.shift_argument unless argv.arguments.empty?
  @carthage = argv.flag?('carthage')
  super
end

Class Method Details

.optionsObject



17
18
19
20
21
22
# File 'lib/pod/command/release.rb', line 17

def self.options
  [
    ['--allow-warnings', 'Allows push even if there are lint warnings'],
    ['--carthage', 'Validates project for carthage deployment'],
  ].concat(super.reject { |option, _| option == '--silent' })
end

Instance Method Details

#execute(command, options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/pod/command/release.rb', line 6

def execute(command, options = {})
  options = { :optional => false }.merge options

  puts "#{"==>".magenta} #{command}"
  abort unless (system(command) || options[:optional])
end

#runObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/pod/command/release.rb', line 32

def run
  specs = Dir.entries(".").select { |s| s.end_with? ".podspec" }
  abort "No podspec found" unless specs.count > 0

  puts "#{"==>".magenta} updating repositories"
  SourcesManager.update

  for spec in specs
    name = spec.gsub(".podspec", "")
    version = Specification.from_file(spec).version
    name = Specification.from_file(spec).name

    sources = SourcesManager.all.select { |r| r.name == "master" || r.url.start_with?("git") }
    sources = sources.select { |s| s.name == @repo } if @repo
    pushed_sources = []
    available_sources = SourcesManager.all.map { |r| r.name }

    abort "Please run #{"pod install".green} to continue" if sources.count == 0
    for source in sources
      pushed_versions = source.versions(name)
      next unless pushed_versions

      pushed_sources << source
      pushed_versions = pushed_versions.collect { |v| v.to_s }
      abort "#{name} (#{version}) has already been pushed to #{source.name}".red if pushed_versions.include? version.to_s
    end

    repo_unspecified = pushed_sources.count == 0 && sources.count > 1
    if repo_unspecified
      puts "When pushing a new podspec, please specify a repository to push #{name} to:"
      puts ""
      for source in sources
        puts "  * pod release #{source.name}"
      end
      puts ""
      abort
    end

    if pushed_sources.count > 1
      puts "#{name} has already been pushed to #{pushed_sources.join(', ')}. Please specify a repository to push #{name} to:"
      puts ""
      for source in sources
        puts "  * pod release #{source.name}"
      end
      puts ""
      abort
    end

    # verify lib
    execute "pod lib lint #{spec} #{@allow_warnings} --sources=#{available_sources.join(',')}"
    execute "pod lib lint #{spec} --use-libraries #{@allow_warnings} --sources=#{available_sources.join(',')}"

    if @carthage
      execute "carthage build --no-skip-current"
    end

    # TODO: create git tag for current version
    unless system("git tag | grep #{version} > /dev/null")
      execute "git add -A && git commit -m \"Releases #{version}.\"", :optional => true
      execute "git tag #{version}"
      execute "git push && git push --tags"
    end

    repo = @repo || pushed_sources.first.name
    if repo == "master"
      execute "pod trunk push #{spec} #{@allow_warnings}"
    else
      execute "pod repo push #{repo} #{spec} #{@allow_warnings}"
    end

    if @carthage && `git remote show origin`.include?("github.com")
      execute "carthage archive #{name}"

      user, repo = /(\w*)\/(\w*).git$/.match(`git remote show origin`)[1, 2]
      file = "#{name}.framework.zip"

      create_release = %(github-release release --user #{user} --repo #{repo} --tag #{version} --name "Version #{version}" --description "Release of version #{version}")
      upload_release = %(github-release upload --user #{user} --repo #{repo} --tag #{version} --name "#{file}" --file "#{file}")

      if ENV['GITHUB_TOKEN'] && system("which github-release")
        execute create_release
        execute upload_release
        execute "rm #{file}"
      else
        puts "Run `#{create_release} --security-token XXX` to create a github release and"
        puts "    `#{upload_release} --security-token XXX` to upload to github releases"
      end
    end
  end
end