podspecpush 0.5.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3faa15aa12076b7850a59b1414ca8d0a516caa4
4
- data.tar.gz: eac72308586de8ff936dfcd20b12c389396e8d68
3
+ metadata.gz: 460568fb63be21ba9618be857fe0a35272fe11d3
4
+ data.tar.gz: ad3614c557b408e525cfed115bdbf32281422477
5
5
  SHA512:
6
- metadata.gz: 63d36c6148bd38b85ef99ff5b4bbbb462b1a0968390885073a4139e4751f8a1519afafe608702528833884a7ca594f252c120a249b7b2dd2642d59f94efff9e8
7
- data.tar.gz: a98f338180959ca2b261e3d98989ce8ec601ac69f0f81a8c3d523e48fd6bf83a22055ece9f150a90b8c304980254359f53b1f5c895a39286a0200e20ba63bb56
6
+ metadata.gz: d6e283b1f7fc12a758d6229b1ede14164b83f28cbf345db9cee3ea3d06a18e863e615d8b09756c22ab8f4223d30da16e38d11b7df5d2b03cd45b09f5b9da7093
7
+ data.tar.gz: 7a8fc7db807d5819714d5608d10773bb4fc6ceec4519d78189dcce2908b009c92958c942e8460e10b120dd4241737deb27fefd26bcb4695f0d3e2d031c5c0495
@@ -1,3 +1,3 @@
1
1
  module Podspecpush
2
- VERSION = "0.5.0"
2
+ VERSION = "0.9.0"
3
3
  end
data/lib/podspecpush.rb CHANGED
@@ -1,106 +1,151 @@
1
1
  require "podspecpush/version"
2
+ require 'colorize'
2
3
  require 'trollop'
3
4
 
4
5
  module Podspecpush
5
6
  class PodPush
6
- def push
7
- opts = Trollop::options do
8
- opt :repo, "Repo name", :type => :string
9
- opt :sources, "List of private repo sources to consider when linting private repo", :type => :string
10
- opt :force, "Pod verify & push with warnings"
11
- opt :privateRepo, "If set, assume repo is private and skip public checks"
12
- end
13
- Trollop::die :repo, "Repo must be provided" if opts[:repo] == nil
14
7
 
15
- force = opts[:force]
16
- repoName = opts[:repo]
17
- privateRepo = opts[:privateRepo]
18
- sources = opts[:sources]
8
+ def specfile
9
+ Dir["*.podspec"].first
10
+ end
11
+
12
+ def shouldUseBundleExec
13
+ File.exist?('Gemfile')
14
+ end
19
15
 
20
- podspecName = `ls | grep .podspec`.strip
16
+ def ensureSpecfile
17
+ podspecFile = specfile
21
18
 
22
- clean = `git status --porcelain`
19
+ puts "No spec file found".red unless podspecFile != nil
20
+ exit unless podspecFile != nil
21
+ end
23
22
 
24
- if clean.length != 0
25
- puts "Repo is not clean; will not push new version"
23
+ def ensureGitClean
24
+ if `git status --porcelain`.length != 0
25
+ puts "Repo is not clean; will not push new version".red
26
26
  exit
27
27
  end
28
28
 
29
- version = `git describe --abbrev=0`.strip
30
-
31
- newFile = ""
32
-
33
- File.readlines(podspecName).each do |line|
34
- idx = / s.version/ =~ line
35
- if idx != nil && idx >= 0
36
- startIdx = line.index("\'")
37
- endIdx = line.index("\'", startIdx + 1)
38
- currentVersion = line[startIdx + 1...endIdx]
39
- if currentVersion == version
40
- puts "Can't push same version silly!"
41
- exit
42
- end
43
- line[startIdx +1 ...endIdx] = version
44
- end
45
-
46
- newFile += line
47
- end
29
+ cmd = []
30
+ cmd << ['bundle exec'] if shouldUseBundleExec
31
+ cmd << ['pod cache clean --all'] if shouldUseBundleExec
32
+ system cmd.join(' ')
33
+ end
48
34
 
49
- File.open(podspecName, 'w') { |file| file.write(newFile) }
50
-
51
- isPrivateFlag = (privateRepo == true ? ' --private' : '')
52
- sourcesFlag = (sources == nil ? '' : " --sources=#{sources},https://github.com/CocoaPods/Specs.git")
53
- disallowWarningsLint = "pod spec lint #{podspecName}" + isPrivateFlag + sourcesFlag
54
- allowWarningsLint = disallowWarningsLint + " --allow-warnings"
55
-
56
- lintCmd = (force == true ? allowWarningsLint : disallowWarningsLint)
57
- lint = system(lintCmd)
58
-
59
- if lint == false
60
- puts "Linting failed, try again by allowing warnings? [Y/n]"
61
- decision = gets.chomp.downcase
62
- if decision == "y"
63
- tryAgainCmd = allowWarningsLint
64
- tryAgain = system(tryAgainCmd)
65
-
66
- if tryAgain == false
67
- puts "Even with warnings, something is wrong. Look for any errors"
68
- exit
69
- else
70
- puts "Proceeding by allowing warnings"
71
- end
72
- else
73
- exit
74
- end
75
- end
35
+ def makeLintCmd(opts)
36
+ lintCmd = []
37
+ lintCmd << ['bundle exec'] if shouldUseBundleExec
38
+ lintCmd = ["pod spec lint"]
76
39
 
77
- pushCmd = "pod repo push #{repoName} #{podspecName} --allow-warnings"
78
- repoPush = system(pushCmd)
40
+ # Build sources
41
+ sources = ["https://github.com/CocoaPods/Specs.git"]
42
+ sources << opts[:sources] unless opts[:sources] == nil
43
+ sourcesArg = "--sources=" + sources.join(",")
79
44
 
80
- if repoPush == false
81
- puts "Push failed, see errors."
82
- exit
45
+ # Build lintCmd
46
+ lintCmd << specfile
47
+ lintCmd << sourcesArg
48
+ lintCmd << ["--private"] unless opts[:private] == false
49
+
50
+ # finalize
51
+ lintCmd.join(' ')
52
+ end
53
+
54
+ def makePushCmd(opts)
55
+ cmd = []
56
+ cmd << ['bundle exec'] if shouldUseBundleExec
57
+ cmd << ["pod repo push #{opts[:specRepo]} #{specfile} --allow-warnings"]
58
+
59
+ cmd.join(' ')
60
+ end
61
+
62
+ def updateVersion
63
+ puts "Please enter new version of the pod so we can tag, lint and push it! (e.g. 1.2.0)".blue
64
+ @podVersion = gets.chomp.downcase
65
+
66
+ puts "Please enter new a brief message to put in the git tag describing what's changed".blue
67
+ @podVersionMessage = gets.chomp.downcase
68
+
69
+ system "git tag -a #{@podVersion} -m #{@podVersionMessage}"
70
+ system "git push --tags"
71
+
72
+ contents = File.read(specfile)
73
+ oldVersion = Regexp.new('[0-9.]{2,6}').match(Regexp.new('(s.version)\s*=.*\n').match(contents).to_s).to_s
74
+ File.write(specfile, contents.gsub!(oldVersion, @podVersion))
75
+ end
76
+
77
+ def rollbackTag
78
+ puts "Rolling back git tags".green
79
+ system "git tag -d #{@podVersion}"
80
+ system "git push -d origin #{@podVersion}"
81
+ exit
82
+ end
83
+
84
+ def executeLint(withWarnings)
85
+ cmd = [@lintCmd]
86
+ cmd << "--allow-warnings" unless withWarnings == false
87
+
88
+ command = cmd.join(' ')
89
+
90
+ puts "Executing: #{command}".green
91
+ success = system command
92
+
93
+ if success == false && withWarnings == false
94
+ # Try again?
95
+ puts "Linting failed, try again by allowing warnings? [Y/n]".blue
96
+ gets.chomp.downcase == "y" ? executeLint(true) : rollbackTag
97
+ elsif success == false && withWarnings == true
98
+ puts "Even with warnings, something is wrong. Look for any errors".red
99
+ rollbackTag
83
100
  end
101
+ end
84
102
 
85
- addExecute = system('git add .')
103
+ def executePush
104
+ puts "Executing: #{@pushCmd}".green
105
+ success = system @pushCmd
86
106
 
87
- if addExecute == false
88
- puts "Could not add files to git, consider finishing by hand by performing a git add, commit, and push. Your spec repo should be up to date"
89
- exit
107
+ if success == false
108
+ puts "Push failed, see errors.".red
109
+ rollbackTag
90
110
  end
111
+ end
91
112
 
92
- commitExecute = system('git commit -m "[Versioning] Updating podspec"')
113
+ def commitThisRepo
114
+ puts "Congrats! The pod has been linted and successfully push to the spec repo! All that is left is to commit the podspec here!".green
93
115
 
94
- if commitExecute == false
95
- puts "Could not commit files, consider finishing by hand by performing a git commit and push. Your spec repo should be up to date"
96
- exit
116
+ puts "Could not commit files, consider finishing by hand by performing a git commit and push. Your spec repo should be up to date".red unless system('git commit -am "[Versioning] Updating podspec"') == true
117
+ puts "Could not push to server, consider finishing by hand by performing a git push. Your spec repo should be up to date".red unless system('git push origin master')
118
+ end
119
+
120
+ def push
121
+ opts = Trollop::options do
122
+ opt :specRepo, "Name of the repo to push to. See pod repo list for available repos", :type => :string
123
+ opt :workspace, "Path to cocoapod workspace", :type => :string
124
+ opt :sources, "Comma delimited list of private repo sources to consider when linting private repo. Master is included by default so private repos can source master", :type => :string
125
+ opt :private, "If set, assume the cocoapod is private and skip public checks"
97
126
  end
127
+ # Need these two
128
+ Trollop::die :specRepo, "Spec Repo must be provided" if opts[:specRepo] == nil
129
+ Trollop::die :workspace, "Workspace path must be provided" if opts[:workspace] == nil
98
130
 
99
- pushToServer = system('git push origin master')
131
+ Dir.chdir(opts[:workspace]) do
132
+ # Check
133
+ ensureGitClean
134
+ ensureSpecfile
100
135
 
101
- if pushToServer == false
102
- puts "Could not push to server, consider finishing by hand by performing a git push. Your spec repo should be up to date"
103
- exit
136
+ # User input
137
+ updateVersion
138
+
139
+ # Cmds
140
+ @lintCmd = makeLintCmd(opts)
141
+ @pushCmd = makePushCmd(opts)
142
+
143
+ # execute
144
+ executeLint(false)
145
+ executePush
146
+
147
+ # Tidy up this repo!!
148
+ commitThisRepo
104
149
  end
105
150
  end
106
151
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: podspecpush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Carroll
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-30 00:00:00.000000000 Z
11
+ date: 2018-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop