Module: GkdPushPod

Defined in:
lib/gkd_push_pod.rb,
lib/gkd_push_pod/ui.rb,
lib/gkd_push_pod/version.rb,
lib/gkd_push_pod/pod_push.rb,
lib/gkd_push_pod/cp_podspec.rb,
lib/gkd_push_pod/git_tag_flow.rb,
lib/gkd_push_pod/modify_podspec.rb,
lib/gkd_push_pod/pod_updater_file.rb

Defined Under Namespace

Classes: PodUpdaterFile, UI

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.copy_podspec(from_path, distination, pod_version) ⇒ Object

desc:将podspec文件拷贝到备份的文件目录



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gkd_push_pod/cp_podspec.rb', line 8

def copy_podspec(from_path, distination, pod_version)

  return unless distination

  unless File.exist?(distination)
    UI.msg("cp_path:#{distination}不存在,请提供正确的路径:")
    distination = gets.to_s.chomp
    copy_podspec(from_path, distination, pod_version)
    return
  end
  unless File.directory?(distination)
    UI.msg("cp_path:#{distination}不是目录,请提供正确的路径")
    distination = gets.to_s.chomp
    copy_podspec(from_path, distination, pod_version)
    return
  end

  pod_name = File.basename(from_path, '.podspec')
  destination_path = destination_path_from(distination, pod_name, pod_version)

  unless destination_path
    UI.err('无法计算出正确的copy路径,podspec文件复制失败')
  else
    FileUtils.cp(from_path, destination_path)
  end

end

.destination_path_from(to_path, pod_name, pod_version) ⇒ Object

desc:负责对cp路径进行检查修正,保证目的路径是包含了以库名为名称的目录,并且在下面新建一个对应版本的文件夹



37
38
39
# File 'lib/gkd_push_pod/cp_podspec.rb', line 37

def destination_path_from(to_path, pod_name, pod_version)

end

.git_tag_flow(path, msg, tag_version) ⇒ Object

提供路径,然后将项目打包上git,标记tag



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gkd_push_pod/git_tag_flow.rb', line 6

def git_tag_flow(path,msg,tag_version)

  cmd = []

  cmd << %(cd #{path})
  cmd << 'git add .'
  cmd << %(git commit -m  "#{msg}")
  cmd << 'git push'

  UI.log_cmd(cmd)
  IO.popen(cmd.join(" && ")) do |io|
    io.each do |line|
      UI.msg line
    end
    io.close
  end

  tag_cmd = []
  tag_cmd << %(git tag -f #{tag_version} -m "#{msg}")
  tag_cmd << 'git push --tags -f'

  UI.log_cmd(tag_cmd)
  IO.popen(tag_cmd.join(" && ")) do |io|
    io.each do |line|
      UI.msg line
    end
    io.close
  end

end

.modifyPodspec(path: "", version: "0.0.0") ⇒ Object

修改podspec的s.verison的值



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gkd_push_pod/modify_podspec.rb', line 6

def modifyPodspec(path:"",version:"0.0.0")

  if version == "0.0.0"
    UI.msg "请指定版本好的值,如 modifyPodspec version:#{version}"
    return
  end
  unless version =~ /^\d{1,}.\d.\d$|^\d{1,}.\d$|^\d{1,}$/
    UI.msg "version:#{version}的格式不对"
    return 
  end
  unless File.exist?path
    UI.err "路径不存在"
    return
  end

  UI.msg "***修改podspec文件***"
  File.open(path, "r+") do |f|
    s = ""
    f.each_line do |line|
      # puts "#{line}"
      if line.to_s =~ /[s|spec]\.version\s*=\s*["|'](\d{1,}.\d{1,}.\d{1,})["|']/
        line = line.sub(/\d{1,}.\d{1,}.\d{1,}/) do |match|
          version.to_s
        end
      end
      s += line
    end
    UI.msg "#{s}"
    File.open(path, "w+") do |f| f.write(s) end
  end

end

.pathWithPodspecSuffix(path) ⇒ Object

找到指定路径下的podspec文件名



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
# File 'lib/gkd_push_pod/modify_podspec.rb', line 40

def pathWithPodspecSuffix(path)

  path = File.expand_path(path)
  return nil unless File.exist?(path)

  unless path =~ /.podspec$/

    if File.directory?(path)
      podfiles = Dir.glob("#{path}/*.podspec")

      if podfiles.length == 0
        UI.err %(#{path} 路径下无法找到'.podspec'文件)
        return nil
      elsif podfiles.length == 1
        path = podfiles.first
      else
        UI.msg "目录下找到多个podspec文件!"
        podfiles.each_with_index do |elem, index|
          basename = File.basename(elem)
          puts %(#{index}.#{basename} )
        end
        UI.msg "请指定您当前需要的操作的文件,输入它的序号:"
        i = gets.to_i

        case i
        when 0 .. (podfiles.length-1)
          path = podfiles[i.to_i]
        else
          UI.err "输入错误❌"
          path = nil
        end

      end
    end
  end

  path

end

.pushPodToSevice(path, version, cp_path, message) ⇒ Object

给定pod库项目的路径,以及新版pod库的版本,将自己的pod提交到git,然后打上tag,再push trunk到pod服务器去,如果cp_path存在则将最后的podspec文件拷贝到cp_path下



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
# File 'lib/gkd_push_pod/pod_push.rb', line 10

def pushPodToSevice(path, version, cp_path, message)

  # 在路径中找到.podspec文件
  podFilePath = pathWithPodspecSuffix(path)

  unless podFilePath
    return  # 未找到相应的podspec文件
  end

  #  pod lib lint 检查
  lib_cmd = %(pod lib lint #{podFilePath} --allow-warnings --skip-import-validation --sources='http://gitlab.sojex.net/iOSClient/GKDSpecs.git,https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git')
  output = ""
  UI.log_cmd(lib_cmd)
  IO.popen(lib_cmd) do |io|
    io.each do |line|
      UI.msg(line)
      output += line.to_s
    end
  end

  if output =~ %r(ERROR|error)
    UI.err("pod lib lint 发生错误")
    return
  end

  msg = "for pod version:#{version} #{message}"

  modifyPodspec(path:podFilePath,version:version) #将podspec文件的版本号进行修改

  if cp_path
    copy_podspec(podFilePath, cp_path,version)
  end

  pod_updater_file = PodUpdaterFile.new(File.dirname(podFilePath))
  if pod_updater_file.paths
    pod_updater_file.paths.each_with_index do |elem, index|
      copy_podspec(podFilePath,elem.to_s, version)
    end
  end

  git_tag_flow(path,msg,version)

  cmd = []
  cmd << %(pod repo push sojex-iosclient-gkdspecs #{podFilePath} --use-libraries --allow-warnings --skip-import-validation --sources='http://gitlab.sojex.net/iOSClient/GKDSpecs.git,https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git')
  push_cmd_output = ""
  UI.log_cmd(cmd)
  IO.popen(cmd.join('')) do |io|
    io.each do |line|
      UI.msg(line)
      push_cmd_output += line.to_s
    end
  end

  if push_cmd_output =~ %r(ERROR|error)
    UI.err("pod lib lint push 发生错误")
  else
    UI.notification(title: "上传完成✅")
  end

end

.run(version, cp_path, message) ⇒ Object



5
6
7
8
# File 'lib/gkd_push_pod.rb', line 5

def self.run(version, cp_path, message)
  path = File.expand_path(Dir.pwd)
  pushPodToSevice(path, version, cp_path, message)
end