MuranoCLI 3.2.1.pre.beta.4 → 3.2.1.pre.beta.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/Gemfile +4 -3
  4. data/HISTORY.md +826 -0
  5. data/Rakefile +415 -47
  6. data/docs/release.rst +275 -0
  7. data/lib/MrMurano/Account.rb +46 -47
  8. data/lib/MrMurano/AccountBase.rb +1 -0
  9. data/lib/MrMurano/Business.rb +183 -44
  10. data/lib/MrMurano/Config.rb +1 -0
  11. data/lib/MrMurano/Exchange.rb +3 -4
  12. data/lib/MrMurano/Solution-Services.rb +25 -7
  13. data/lib/MrMurano/Webservice-File.rb +5 -7
  14. data/lib/MrMurano/commands/business.rb +231 -24
  15. data/lib/MrMurano/commands/child.rb +3 -3
  16. data/lib/MrMurano/commands/element.rb +1 -0
  17. data/lib/MrMurano/commands/settings.rb +7 -0
  18. data/lib/MrMurano/http.rb +1 -3
  19. data/lib/MrMurano/progress.rb +12 -2
  20. data/lib/MrMurano/verbosing.rb +7 -7
  21. data/lib/MrMurano/version.rb +1 -1
  22. data/spec/Account_spec.rb +9 -0
  23. data/spec/ProjectFile_spec.rb +7 -9
  24. data/spec/Webservice-File_spec.rb +2 -1
  25. data/spec/cmd_business_spec.rb +1 -1
  26. data/spec/cmd_common.rb +75 -30
  27. data/spec/cmd_content_spec.rb +3 -1
  28. data/spec/cmd_cors_spec.rb +3 -1
  29. data/spec/cmd_device_spec.rb +7 -5
  30. data/spec/cmd_domain_spec.rb +6 -2
  31. data/spec/cmd_help_spec.rb +13 -6
  32. data/spec/cmd_init_spec.rb +19 -10
  33. data/spec/cmd_keystore_spec.rb +3 -1
  34. data/spec/cmd_link_spec.rb +5 -5
  35. data/spec/cmd_setting_application_spec.rb +13 -16
  36. data/spec/cmd_setting_product_spec.rb +14 -14
  37. data/spec/cmd_status_spec.rb +6 -2
  38. data/spec/cmd_syncdown_application_spec.rb +3 -1
  39. data/spec/cmd_syncdown_both_spec.rb +6 -2
  40. data/spec/cmd_syncdown_unit_spec.rb +3 -0
  41. data/spec/cmd_syncup_spec.rb +8 -4
  42. data/spec/cmd_usage_spec.rb +10 -2
  43. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value 0.webmock +98 -0
  44. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value 1.webmock +98 -0
  45. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value No.webmock +98 -0
  46. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value Yes.webmock +98 -0
  47. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value bob.webmock +72 -0
  48. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value false.webmock +98 -0
  49. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value off.webmock +98 -0
  50. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value on STDIN.webmock +98 -0
  51. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value on.webmock +98 -0
  52. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value true.webmock +98 -0
  53. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a json array blob with STDIN.webmock +98 -0
  54. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a json array blob.webmock +98 -0
  55. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) an array.webmock +98 -0
  56. data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) appends an array.webmock +98 -0
  57. data/spec/fixtures/snapshots/murano application setting reads Webservice.cors to a file.webmock +72 -0
  58. data/spec/fixtures/snapshots/murano application setting reads Webservice.cors.webmock +72 -0
  59. data/spec/fixtures/snapshots/murano business list as json.webmock +27 -0
  60. data/spec/fixtures/snapshots/murano business list as table.webmock +27 -0
  61. data/spec/fixtures/snapshots/murano business list fewer fields.webmock +27 -0
  62. data/spec/fixtures/snapshots/murano business list only ids.webmock +27 -0
  63. data/spec/fixtures/snapshots/murano business list output to file.webmock +27 -0
  64. data/spec/fixtures/snapshots/murano business without project help.webmock +9 -0
  65. data/spec/fixtures/snapshots/murano config Needs a key.webmock +9 -0
  66. data/spec/fixtures/snapshots/murano config Reads a key.webmock +9 -0
  67. data/spec/fixtures/snapshots/murano config Removes a key.webmock +9 -0
  68. data/spec/fixtures/snapshots/murano config Sets a key.webmock +9 -0
  69. data/spec/fixtures/snapshots/murano config Sets a user key.webmock +9 -0
  70. data/spec/fixtures/snapshots/murano content life cycle.webmock +144 -0
  71. data/spec/fixtures/snapshots/murano cors sets CORS.webmock +78 -0
  72. data/spec/fixtures/snapshots/murano cors show CORS.webmock +64 -0
  73. data/spec/fixtures/snapshots/murano device activates.webmock +86 -0
  74. data/spec/fixtures/snapshots/murano device enables a batch.webmock +76 -0
  75. data/spec/fixtures/snapshots/murano device enables and lists.webmock +78 -0
  76. data/spec/fixtures/snapshots/murano device writes and reads.webmock +136 -0
  77. data/spec/fixtures/snapshots/murano domain show domain.webmock +101 -0
  78. data/spec/fixtures/snapshots/murano element edit unknown as unknown element.webmock +43 -0
  79. data/spec/fixtures/snapshots/murano element show --help.webmock +9 -0
  80. data/spec/fixtures/snapshots/murano element show as csv.webmock +43 -0
  81. data/spec/fixtures/snapshots/murano element show as default-table.webmock +43 -0
  82. data/spec/fixtures/snapshots/murano element show as json.webmock +43 -0
  83. data/spec/fixtures/snapshots/murano element show as table truncate.webmock +43 -0
  84. data/spec/fixtures/snapshots/murano element show as table wrap.webmock +43 -0
  85. data/spec/fixtures/snapshots/murano element show as yaml.webmock +43 -0
  86. data/spec/fixtures/snapshots/murano element show using ambiguous name.webmock +43 -0
  87. data/spec/fixtures/snapshots/murano element without project usage.webmock +9 -0
  88. data/spec/fixtures/snapshots/murano exchange with project list as json.webmock +59 -0
  89. data/spec/fixtures/snapshots/murano exchange with project list as table.webmock +59 -0
  90. data/spec/fixtures/snapshots/murano exchange with project list fewer fields.webmock +59 -0
  91. data/spec/fixtures/snapshots/murano exchange with project list only ids.webmock +59 -0
  92. data/spec/fixtures/snapshots/murano exchange with project list output to file.webmock +59 -0
  93. data/spec/fixtures/snapshots/murano exchange with project list purchase is already added ID.webmock +83 -0
  94. data/spec/fixtures/snapshots/murano exchange with project list purchase is ambiguous name.webmock +59 -0
  95. data/spec/fixtures/snapshots/murano exchange without project help.webmock +9 -0
  96. data/spec/fixtures/snapshots/murano help using commander as --help.webmock +9 -0
  97. data/spec/fixtures/snapshots/murano help using commander no args.webmock +9 -0
  98. data/spec/fixtures/snapshots/murano help using subshell no args.webmock +9 -0
  99. data/spec/fixtures/snapshots/murano help using subshell with --help.webmock +9 -0
  100. data/spec/fixtures/snapshots/murano init Won't init in HOME (gracefully).webmock +9 -0
  101. data/spec/fixtures/snapshots/murano init in empty directory with existing project.webmock +201 -0
  102. data/spec/fixtures/snapshots/murano init in empty directory without existing project.webmock +193 -0
  103. data/spec/fixtures/snapshots/murano init in existing project directory with ProjectFile.webmock +213 -0
  104. data/spec/fixtures/snapshots/murano init in existing project directory with SolutionFile 0.2.0.webmock +213 -0
  105. data/spec/fixtures/snapshots/murano init in existing project directory with SolutionFile 0.3.0.webmock +213 -0
  106. data/spec/fixtures/snapshots/murano init in existing project directory without ProjectFile.webmock +213 -0
  107. data/spec/fixtures/snapshots/murano keystore can call other commands.webmock +108 -0
  108. data/spec/fixtures/snapshots/murano keystore clearAll.webmock +124 -0
  109. data/spec/fixtures/snapshots/murano keystore deletes.webmock +112 -0
  110. data/spec/fixtures/snapshots/murano keystore gets.webmock +96 -0
  111. data/spec/fixtures/snapshots/murano keystore infos.webmock +96 -0
  112. data/spec/fixtures/snapshots/murano keystore lists.webmock +96 -0
  113. data/spec/fixtures/snapshots/murano link with project links and lists.webmock +149 -0
  114. data/spec/fixtures/snapshots/murano link with project unlinks.webmock +165 -0
  115. data/spec/fixtures/snapshots/murano link without project help.webmock +9 -0
  116. data/spec/fixtures/snapshots/murano link without project subshell vs inline using commander will not list.webmock +27 -0
  117. data/spec/fixtures/snapshots/murano link without project subshell vs inline using subshell will not list.webmock +27 -0
  118. data/spec/fixtures/snapshots/murano logs when project is setup tail log.webmock +9 -0
  119. data/spec/fixtures/snapshots/murano password Lists when no file.webmock +9 -0
  120. data/spec/fixtures/snapshots/murano password deletes a password.webmock +9 -0
  121. data/spec/fixtures/snapshots/murano password sets a password.webmock +9 -0
  122. data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a forced string value on STDIN.webmock +90 -0
  123. data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a forced string value.webmock +90 -0
  124. data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a number value fiftyHalf.webmock +64 -0
  125. data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a number value float 12.67.webmock +90 -0
  126. data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a number value integer 12.webmock +90 -0
  127. data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a number value on STDIN.webmock +90 -0
  128. data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a string value.webmock +90 -0
  129. data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) merges into a dictionary.webmock +90 -0
  130. data/spec/fixtures/snapshots/murano single sync without ProjectFile syncdown.webmock +322 -0
  131. data/spec/fixtures/snapshots/murano status with ProjectFile status.webmock +153 -0
  132. data/spec/fixtures/snapshots/murano status with Solutionfile 0.2.0 status.webmock +153 -0
  133. data/spec/fixtures/snapshots/murano status with Solutionfile 0.3.0 status.webmock +153 -0
  134. data/spec/fixtures/snapshots/murano status without ProjectFile matches file path.webmock +153 -0
  135. data/spec/fixtures/snapshots/murano status without ProjectFile matches route.webmock +153 -0
  136. data/spec/fixtures/snapshots/murano status without ProjectFile status.webmock +153 -0
  137. data/spec/fixtures/snapshots/murano syncdown stubbed without ProjectFile syncdown.webmock +151 -0
  138. data/spec/fixtures/snapshots/murano syncdown without ProjectFile syncdown.webmock +479 -0
  139. data/spec/fixtures/snapshots/murano syncup without ProjectFile syncup.webmock +357 -0
  140. data/spec/fixtures/snapshots/murano token with project list as table.webmock +9 -0
  141. data/spec/fixtures/snapshots/murano token without project help.webmock +9 -0
  142. data/spec/fixtures/snapshots/murano usage show usage.webmock +93 -0
  143. data/spec/spec_helper.rb +9 -3
  144. data/spec/webmock_snapshot.rb +296 -0
  145. metadata +133 -2
data/Rakefile CHANGED
@@ -6,7 +6,9 @@
6
6
  # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'bundler/gem_tasks'
9
+ require 'open3'
9
10
  require 'shellwords'
11
+ require 'tmpdir'
10
12
 
11
13
  task default: %i[test]
12
14
 
@@ -53,21 +55,6 @@ task :tail do
53
55
  sh %(tail -F .trustme.log curldebug.out)
54
56
  end
55
57
 
56
- desc 'display remind of how to release'
57
- task :release_reminder do
58
- reminder = %(
59
- git flow release start <newversion>
60
- gvim lib/MrMurano/version.rb
61
- git commit -a -m 'version bump'
62
- git flow release finish <newversion>
63
- # When editing message for tag, add release notes.
64
- #rake git:all
65
- # Wait for all tests to complete.
66
- # if all passed: rake gemit
67
- ).lines.map(&:strip).join("\n")
68
- puts reminder
69
- end
70
-
71
58
  desc 'Prints a cmd to test this in another directory'
72
59
  task :testwith do
73
60
  pwd = Dir.pwd.sub(Dir.home, '~')
@@ -111,39 +98,415 @@ task :test_clean_up do
111
98
  end
112
99
  end
113
100
 
114
- ###
115
- # When new tags are pushed to upstream, the CI will kick-in and build the release
116
- #namespace :git do
117
- # desc 'Push only develop, master, and tags to origin'
118
- # task :origin do
119
- # sh %(git push origin develop)
120
- # sh %(git push origin master)
121
- # sh %(git push origin --tags)
122
- # end
123
- #
124
- # desc 'Push only develop, master, and tags to upstream'
125
- # task :upstream do
126
- # sh %(git push upstream develop)
127
- # sh %(git push upstream master)
128
- # sh %(git push upstream --tags)
129
- # end
101
+ # ***
102
+
103
+ def exit_task(msg)
104
+ require 'rainbow'
105
+ $stderr.print Rainbow(msg + "\n").red.bright
106
+ exit 1
107
+ end
108
+
109
+ # ***
110
+
111
+ def current_ver
112
+ Bundler::GemHelper.gemspec.version.version
113
+ end
114
+
115
+ def verify_semantic_version!(parts, must_beta: nil)
116
+ msg = nil
117
+ if must_beta == true && parts.length <= 3
118
+ msg = 'ERROR: Current version is not pre-release/beta versioned'
119
+ elsif must_beta == false && parts.length != 3
120
+ msg = 'ERROR: Current version is not normal-release versioned'
121
+ elsif parts.length < 3
122
+ msg = 'ERROR: Not a semantic version'
123
+ else
124
+ (parts[0..2] + parts[-1..-1]).each do |number|
125
+ begin
126
+ Integer(number)
127
+ rescue ArgumentError => _err
128
+ msg = 'ERROR: Contains non-integers'
129
+ end
130
+ end
131
+ end
132
+ exit_task("#{msg}: #{current_ver}") if msg
133
+ end
134
+
135
+ def split_version_string(must_beta: nil)
136
+ parts = current_ver.split('.')
137
+ verify_semantic_version!(parts, must_beta: must_beta)
138
+ parts
139
+ end
140
+
141
+ # ***
142
+
143
+ def git_working_tree_clean?
144
+ out, err, status = Open3.capture3(%(git status --short))
145
+ out == '' && err == '' && status.exitstatus == 0
146
+ end
147
+
148
+ def git_working_tree_clean!
149
+ return true if git_working_tree_clean?
150
+ msg = 'ERROR: Please clean your git working tree!'
151
+ exit_task(msg)
152
+ end
153
+
154
+ def git_branchname
155
+ current_branch, _err, _status = Open3.capture3(%(git rev-parse --abbrev-ref HEAD))
156
+ current_branch
157
+ end
158
+
159
+ def git_username
160
+ git_user, _err, _status = Open3.capture3(%(git config user.name))
161
+ git_user
162
+ end
163
+
164
+ # ***
165
+
166
+ def ff_branch(branch)
167
+ git_working_tree_clean!
168
+ sh %(git checkout #{branch})
169
+ sh %(git fetch --prune --multiple origin upstream)
170
+ sh %(git merge --ff-only upstream/#{branch})
171
+ sh %(git push origin #{branch})
172
+ end
173
+
174
+ def ff_develop
175
+ ff_branch('develop')
176
+ end
177
+
178
+ def ff_master
179
+ ff_branch('master')
180
+ end
181
+
182
+ desc 'Fast-forward merge upstream/develop into origin/develop'
183
+ task :ff do
184
+ current_branch = git_branchname
185
+ ff_develop
186
+ sh %(git checkout #{current_branch})
187
+ end
188
+
189
+ # ***
190
+
191
+ desc 'Start a Pull Request for the current branch in a new browser tab'
192
+ task :pr do
193
+ # NOTE: On Unity (unity-control-centre), you might need `xdg-open` instead.
194
+ sh %(sensible-browser "https://github.com/exosite/MuranoCLI/compare/develop...#{git_username}:#{git_branchname}")
195
+ end
196
+
197
+ # ***
198
+
199
+ namespace :bump do
200
+ def bump_version(next_ver)
201
+ git_working_tree_clean!
202
+
203
+ # Change the version number.
204
+ sh %(/bin/sed \
205
+ -i "s/^ VERSION = '[a-zA-Z0-9.]\\+'$/ VERSION = '#{next_ver}'/" \
206
+ lib/MrMurano/version.rb)
207
+ $stdout.puts
208
+ # Sanity check.
209
+ msg = 'INVALID: After editing version, your git working tree is still clean?'
210
+ exit_task(msg) if git_working_tree_clean?
211
+
212
+ # Make a commit.
213
+ sh %(git add lib/MrMurano/version.rb)
214
+ $stdout.puts
215
+ sh %(git commit -m "Version: #{current_ver} → #{next_ver}")
216
+ $stdout.puts
217
+ # (lb): Meh. We could push to origin. Or not.
218
+ # sh %(git push origin HEAD)
219
+ require 'rainbow'
220
+ $stdout.puts Rainbow("Bumped! New version: #{next_ver}").magenta.bright
221
+ end
222
+
223
+ def feature_version(next_ver)
224
+ bump_version(next_ver)
225
+ end
226
+
227
+ def release_version(next_ver)
228
+ # Remember what branch the user's on.
229
+ current_branch = git_branchname
230
+ # Bring your user's develop branch up to date with upstream.
231
+ ff_develop
232
+ # Create a release branch
233
+ sh %(git checkout develop)
234
+ $stdout.puts
235
+ sh %(git checkout -b release/#{next_ver})
236
+ $stdout.puts
237
+ # Change the version number.
238
+ bump_version(next_ver)
239
+ # Restore the working branch.
240
+ sh %(git checkout #{current_branch})
241
+ $stdout.puts
242
+ # Notify the new version number.
243
+ require 'rainbow'
244
+ $stdout.puts Rainbow("Bumped! New version: #{next_ver}\n").magenta.bright
245
+ # Tell the user what to do next.
246
+ gh_pr_uri = %(https://github.com/exosite/MuranoCLI/compare/develop...#{git_username}:release/#{next_ver})
247
+ $stdout.puts %(
248
+ 1. Visit GitHub and make a PR.
249
+
250
+ #{gh_pr_uri}
251
+
252
+ 2. Approve the PR, merge into develop, and delete the release branch.
253
+
254
+ 3. Run `rake ff` to fast-forward your user's copy of develop.
255
+
256
+ 4. Run `rake publish:develop` or `rake publish:master` to create and
257
+ upload a pre-release or production Gem.
258
+ ).strip
259
+ sh %(sensible-browser "#{gh_pr_uri}")
260
+ end
261
+
262
+ # ***
263
+
264
+ desc 'Bump the pre-release (beta) version'
265
+ task :beta do
266
+ git_working_tree_clean!
267
+ parts = split_version_string
268
+ if parts.length == 3
269
+ msg = 'ERROR: First start a pre-release version with: `bump major|minor|patch`'
270
+ exit_task(msg)
271
+ else
272
+ parts[-1] = (parts[-1].to_i + 1).to_s
273
+ next_ver = parts.join('.')
274
+ end
275
+ feature_version(next_ver)
276
+ end
277
+
278
+ desc 'Increment the patch version, and add pre-release (beta) postfix'
279
+ task :patch do
280
+ git_working_tree_clean!
281
+ parts = split_version_string
282
+ parts[2] = (parts[2].to_i + 1).to_s
283
+ next_ver = parts[0..2].join('.') + '.beta.1'
284
+ feature_version(next_ver)
285
+ end
286
+
287
+ desc 'Increment the minor version, and add pre-release (beta) postfix'
288
+ task :minor do
289
+ git_working_tree_clean!
290
+ parts = split_version_string
291
+ minor_num = (parts[1].to_i + 1).to_s
292
+ next_ver = "#{parts[0]}.#{minor_num}.0.beta.1"
293
+ feature_version(next_ver)
294
+ end
295
+
296
+ desc 'Increment the major version, and add pre-release (beta) postfix'
297
+ task :major do
298
+ git_working_tree_clean!
299
+ parts = split_version_string
300
+ major_num = (parts[0].to_i + 1).to_s
301
+ next_ver = "#{major_num}.0.0.beta.1"
302
+ feature_version(next_ver)
303
+ end
304
+
305
+ desc 'Drop the beta to make an official release'
306
+ task :release do
307
+ git_working_tree_clean!
308
+ parts = split_version_string(must_beta: true)
309
+ next_ver = parts[0..2].join('.')
310
+ release_version(next_ver)
311
+ end
312
+ end
313
+
314
+ # ***
315
+
316
+ namespace :package do
317
+ GH_OWNER = 'exosite'
318
+ GH_REPO = 'MuranoCLI'
319
+
320
+ def print_next_steps
321
+ jenkins_job_uri = %(https://jenkins.exosite.com/job/MuranoCLI/job/Murano_CLI_Gem_Release/)
322
+ $stdout.puts %(
323
+ 1. Wait for the Gem release builder to start (or poke it yourself).
324
+
325
+ #{jenkins_job_uri}
326
+
327
+ The job should start within 5 minutes, per its Jenkins poll config: `H/5 * * * *`.
328
+
329
+ 2. Run `rake package:publish` to download the Jenkins CI-built Gem from
330
+ GitHub and upload it to rubygems.org.
331
+ ).strip
332
+ sh %(sensible-browser "#{jenkins_job_uri}")
333
+ end
334
+
335
+ def tag_version(tag_ver, branch)
336
+ sh %(git checkout #{branch})
337
+ sh %(git tag -a "#{tag_ver}" -m "Version: #{tag_ver}" #{branch})
338
+ sh %(git push upstream "#{tag_ver}")
339
+ end
340
+
341
+ desc 'Publish a pre-release Gem after tagging the develop branch'
342
+ task :develop do
343
+ _parts = split_version_string(must_beta: true)
344
+ current_branch = git_branchname
345
+ ff_develop
346
+ tag_version("v#{current_ver}", 'develop')
347
+ sh %(git checkout #{current_branch})
348
+ # Tell the user what to do next.
349
+ print_next_steps
350
+ end
351
+
352
+ desc 'Publish a release Gem after tagging the master branch'
353
+ task :master do
354
+ _parts = split_version_string(must_beta: false)
355
+ current_branch = git_branchname
356
+ ff_master
357
+ tag_version("v#{current_ver}", 'master')
358
+ sh %(git checkout #{current_branch})
359
+ # Tell the user what to do next.
360
+ print_next_steps
361
+ end
362
+
363
+ # ***
364
+
365
+ def must_env_github_token!
366
+ return unless ENV['GITHUB_TOKEN'].to_s.empty?
367
+ $stdout.puts %(
368
+ Please set the GITHUB_TOKEN environ to your user's token. E.g.,
369
+
370
+ export GITHUB_TOKEN=XXX
371
+
372
+ Here's some light reading if you need help:
373
+
374
+ https://gist.github.com/Integralist/9482061
375
+
376
+ https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
377
+
378
+ https://gist.github.com/maxim/6e15aa45ba010ab030c4
379
+
380
+ ).lstrip
381
+ exit 1
382
+ end
383
+
384
+ def api_gh_fetch_releases
385
+ # If the GitHub project was public, we could just `wget https://....gem`,
386
+ # but the project is private, so we gotta use the GitHub API to fetch it.
387
+ _out, _err, _status = Open3.capture3(
388
+ %(
389
+ curl --header "Authorization: token #{ENV['GITHUB_TOKEN']}" \
390
+ --header "Accept: application/json" \
391
+ --remote-name \
392
+ --location \
393
+ https://api.github.com/repos/#{GH_OWNER}/#{GH_REPO}/releases
394
+ )
395
+ )
396
+ sh %(cat releases | head -n 14)
397
+ $stdout.puts %(...\n\n)
398
+ end
399
+
400
+ def api_gh_fetch_asset_id
401
+ _out, _err, _status = Open3.capture3(
402
+ %(
403
+ curl --header "Authorization: token #{ENV['GITHUB_TOKEN']}" \
404
+ --header "Accept: application/json" \
405
+ --remote-name \
406
+ --location \
407
+ https://api.github.com/repos/#{GH_OWNER}/#{GH_REPO}/releases/tags/v#{current_ver}
408
+ )
409
+ )
410
+ sh %(cat v#{current_ver} | head -n 14)
411
+ $stdout.puts %(...\n\n)
412
+
413
+ asset_id, _err, _status = Open3.capture3(%(cat v#{current_ver} | jq '.assets[0].id'))
414
+ $stdout.puts %(asset_id: #{asset_id}\n)
415
+ asset_id
416
+ end
417
+
418
+ def api_gh_fetch_asset(asset_id)
419
+ gem_name = "MuranoCLI-#{current_ver}.gem"
420
+ _out, _err, _status = Open3.capture3(
421
+ %(
422
+ wget -q --auth-no-challenge \
423
+ --header='Accept:application/octet-stream' \
424
+ -O #{gem_name} \
425
+ https://#{ENV['GITHUB_TOKEN']}:@api.github.com/repos/#{GH_OWNER}/#{GH_REPO}/releases/assets/#{asset_id}
426
+ )
427
+ )
428
+ gem_name
429
+ end
430
+
431
+ def must_gem_downloaded!(gem_name)
432
+ unless File.exist?(gem_name)
433
+ msg = 'ERROR: There was a problem downloading the Gem from GitHub!'
434
+ exit_task(msg)
435
+ end
436
+ sh %(/bin/ls -la #{gem_name})
437
+ end
438
+
439
+ TRUTHY_WORDS = %w[1 on t true y yes +].freeze
440
+
441
+ def truthy?(text)
442
+ TRUTHY_WORDS.include? text.to_s.downcase
443
+ end
444
+
445
+ def prompt_user_smoke_test!(gem_name)
446
+ sh %(gem install -i #{Gem.dir} #{gem_name})
447
+ $stdout.puts
448
+ require 'rainbow'
449
+ $stdout.puts Rainbow('You should run smoke tests on the gem!').green.bright
450
+ $stdout.puts
451
+ $stdout.puts %(Type something affirmative when you're satisfied. )
452
+ $stdout.print %(Upload to rubygems.org? [y/n] )
453
+ $stdout.flush
454
+ answer = $stdin.gets.chomp
455
+ exit_task('Your loss!') unless truthy?(answer)
456
+ sh %(gem uninstall MuranoCLI --version #{current_ver})
457
+ end
458
+
459
+ def publish_gem(gem_name)
460
+ sh %(gem push #{gem_name})
461
+ # To undo:
462
+ # gem yank MuranoCLI -v <MuranoCLI Version>
463
+ end
464
+
465
+ def print_test_steps
466
+ $stdout.puts %(
467
+ Now, smoke test!
468
+
469
+ gem uninstall MuranoCLI
470
+ murano -v
471
+
472
+ gem install MuranoCLI
473
+ murano -v
474
+
475
+ gem install MuranoCLI --pre
476
+ murano -v
477
+ ).strip
478
+ end
479
+
480
+ desc 'Copy the Gem from GitHub and publish on Rubygems.org'
481
+ task :publish do
482
+ # (lb): I don't recall what we do this dance and don't just have
483
+ # Jenkins publish the Gem. (I know why we don't build the Gem
484
+ # locally and push that -- because we want all builds to come
485
+ # from the same, non-developer machine. Perhaps we don't have
486
+ # Jenkins push the gem so that we can smoke test it first!)
487
+ must_env_github_token!
488
+ Dir.mktmpdir do |tmpdir|
489
+ Dir.chdir(tmpdir)
490
+ api_gh_fetch_releases
491
+ asset_id = api_gh_fetch_asset_id
492
+ gem_name = api_gh_fetch_asset(asset_id)
493
+ must_gem_downloaded!(gem_name)
494
+ prompt_user_smoke_test!(gem_name)
495
+ publish_gem(gem_name)
496
+ print_test_steps
497
+ # NOTE: The temporary directory does not get cleaned up
498
+ # immediately (it gets removed when the OS decides to).
499
+ # We could remove it now, but it doesn't hurt to leave
500
+ # it (and we might need it to troubleshoot!).
501
+ end
502
+ end
503
+ end
504
+
505
+ # *** Push tasks (used by Jenkins CI release job).
130
506
  #
131
- # desc 'Push to origin and upstream'
132
- # task all: %i[origin upstream]
133
- #end
134
-
135
- desc 'Build, install locally, and push gem'
136
- task :gemit do
137
- mrt = Bundler::GemHelper.gemspec.version
138
- sh %(git checkout v#{mrt})
139
- Rake::Task[:build].invoke
140
- Rake::Task[:bob].invoke
141
- Rake::Task['push:gem'].invoke
142
- sh %(git checkout develop)
143
- end
144
-
145
- ###########################################
146
- # Tasks below are largly used by CI systems
507
+ # NOTE: It is unlikely that you will run these tasks yourself.
508
+ # See instead: `rake publish:develop` and `rake publish:master`
509
+
147
510
  namespace :push do
148
511
  desc 'Push gem up to RubyGems'
149
512
  task :gem do
@@ -194,6 +557,9 @@ namespace :push do
194
557
  end
195
558
  end
196
559
 
560
+ # (lb): You can run this task via `rake ReadMe.txt` (the rocket ship
561
+ # operator indicates that that target depends on a file prerequisite).
562
+ # (Note that this tasks simply translates the readme for Windows.)
197
563
  file 'ReadMe.txt' => ['README.markdown'] do |t|
198
564
  File.open(t.prerequisites.first) do |rio|
199
565
  File.open(t.name, 'w') do |wio|
@@ -202,6 +568,8 @@ file 'ReadMe.txt' => ['README.markdown'] do |t|
202
568
  end
203
569
  end
204
570
 
571
+ # Windows tasks.
572
+
205
573
  if Gem.win_platform?
206
574
  desc 'Build as a single windows exe'
207
575
  file 'murano.exe' => Dir['lib/**/*.{rb,erb,yaml}'] do