rubinjam 0.6.0 → 0.7.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: 16e1a95902b0ae96f7958bcc3bcae3ece2e8e0d5
4
- data.tar.gz: cb9a318a818923447b55eba4818937da5bbe379a
3
+ metadata.gz: 41b26872945b7c2f6fc312b964accc2764e4580a
4
+ data.tar.gz: a826f2d5aa67ef8520c7fd11ce98e1a50f830a3a
5
5
  SHA512:
6
- metadata.gz: 2bbf2dae2a452d2fa1d086a041748b19cda0c015d8114f1576cc806b2c5c77cd396d1191ace604d05166428baeeb00614980cbe2186cb9f5e6dbaa9398630426
7
- data.tar.gz: 0de50fa021af6a5dd339c8d3c496974c4727870e321b70eab66f420380a7e07faba7de840a0f351a72b5ce92a920763fdb2b1de9eb90c12ffe2e247817f995ae
6
+ metadata.gz: 6586b7b6e6f4394eb0c09d9b859cfcf27c8f3d657958d96d0505e6a241b7f0f2c856c207708b4585336c6dc3f2a8409569426dd39cd2722cb0330c46ed901963
7
+ data.tar.gz: 624ce47a552d0b14589cc29a70950d400f8a8283ae1e246d02e87da8b82b92a34c1f48c9281c158b780d2094337d75f60c5b4dfbbb9043825ad258c66ea60827
data/bin/rubinjam CHANGED
@@ -19,7 +19,4 @@ BANNER
19
19
  opts.on('-v', '--version','Show Version'){ require 'rubinjam/version'; puts Rubinjam::VERSION; exit}
20
20
  end.parse!
21
21
 
22
- name, content = Rubinjam.pack(Dir.pwd)
23
- File.open(name, 'w') { |f| f.write content }
24
- `chmod +x #{name}`
25
- raise "Unable to add execution bit" unless $?.success?
22
+ Rubinjam.write(Dir.pwd)
data/lib/rubinjam.rb CHANGED
@@ -6,14 +6,21 @@ module Rubinjam
6
6
  HEADER = '#!/usr/bin/env ruby'.freeze
7
7
 
8
8
  class << self
9
+ # pack and write a binary given a directory
10
+ def write(dir)
11
+ name, content = pack(Dir.pwd)
12
+ write_file name, content
13
+ `chmod +x #{name}`
14
+ raise "Unable to add execution bit" unless $?.success?
15
+ name
16
+ end
17
+
9
18
  # pack a directory
10
19
  def pack(dir)
11
20
  Dir.chdir(dir) do
12
- binaries = Dir["bin/*"]
13
- raise "No binary found in ./bin" if binaries.size == 0
14
- raise "Can only pack exactly 1 binary, found #{binaries.join(",")} in ./bin" unless binaries.size == 1
15
- content = environment + File.read(binaries.first)
16
- [File.basename(binaries.first), content]
21
+ binary = binary_path
22
+ content = environment + File.read(binary)
23
+ return [File.basename(binary), content]
17
24
  end
18
25
  end
19
26
 
@@ -36,7 +43,7 @@ module Rubinjam
36
43
 
37
44
  # bundle
38
45
  Dir.chdir(gem_ball.sub(".gem", "")) do
39
- File.open("#{gem}.gemspec", "w") { |f| f.write spec }
46
+ write_file "#{gem}.gemspec", spec
40
47
  Rubinjam.pack(Dir.pwd)
41
48
  end
42
49
  end
@@ -45,6 +52,24 @@ module Rubinjam
45
52
 
46
53
  private
47
54
 
55
+ def binary_path
56
+ folders = ["./exe", "./bin"]
57
+ folders.each do |folder|
58
+ binaries = Dir["#{folder}/*"]
59
+ next if binaries.size == 0
60
+ if binaries.size != 1
61
+ local = File.join(folder, File.basename(Dir.pwd))
62
+ if binaries.include?(local)
63
+ binaries = [local]
64
+ else
65
+ raise "Can only pack exactly 1 binary, found #{binaries.join(", ")} in #{folder}"
66
+ end
67
+ end
68
+ return binaries.first
69
+ end
70
+ raise "No binary found in #{folders.join(" or ")}"
71
+ end
72
+
48
73
  def libraries
49
74
  libs_from_paths(["lib"]).
50
75
  merge!(gem_libraries).
@@ -73,8 +98,8 @@ module Rubinjam
73
98
  Dir.mktmpdir do |dir|
74
99
  sh "cp -R . #{dir}/"
75
100
  Dir.chdir(dir) do
76
- write gemspec, content
77
- write "Gemfile", <<-RUBY.gsub(/^ /, "")
101
+ write_file gemspec, content
102
+ write_file "Gemfile", <<-RUBY.gsub(/^ /, "")
78
103
  source "https://rubygems.org"
79
104
  gemspec
80
105
  RUBY
@@ -102,7 +127,7 @@ module Rubinjam
102
127
  result
103
128
  end
104
129
 
105
- def write(file, content)
130
+ def write_file(file, content)
106
131
  FileUtils.mkdir_p(File.dirname(file))
107
132
  File.open(file, "w") { |f| f.write content }
108
133
  end
@@ -0,0 +1,63 @@
1
+ require 'shellwords'
2
+ require 'json'
3
+
4
+ module Rubinjam
5
+ module Tasks
6
+ API_BASE =
7
+
8
+ class << self
9
+ def upload_binary(tag, github_token)
10
+ # https://github.com/foo/bar or git@github.com:foo/bar.git -> foo/bar
11
+ repo = sh("git", "remote", "get-url", "origin")
12
+ repo.sub!(/\.git$/, "")
13
+ repo = repo.split(/[:\/]/).last(2).join("/")
14
+
15
+ auth = ["-H", "Authorization: token #{github_token}"]
16
+
17
+ # create release
18
+ # TODO: fallback to finding an existing release
19
+ reply = sh("curl", *auth, "--data", {tag_name: tag}.to_json, "https://api.github.com/repos/#{repo}/releases")
20
+ id = JSON.parse(reply).fetch("id") # fails when release already exists
21
+
22
+ # upload binary
23
+ begin
24
+ name = Rubinjam.write(Dir.pwd)
25
+ sh(
26
+ "curl",
27
+ "-X", "POST",
28
+ "--data-binary", "@#{name}",
29
+ "-H", "Content-Type: application/octet-stream",
30
+ *auth,
31
+ "https://uploads.github.com/repos/#{repo}/releases/#{id}/assets?name=#{name}"
32
+ )
33
+ ensure
34
+ sh "rm", "-f", name.to_s
35
+ end
36
+ end
37
+
38
+ def sh(*command)
39
+ command = command.shelljoin
40
+ result = `#{command}`
41
+ raise "Command failed:\n#{command}\n#{result}" unless $?.success?
42
+ result
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ namespace :rubinjam do
49
+ task :upload_binary do
50
+ # find token for auth
51
+ github_token = begin
52
+ Rubinjam::Tasks.sh("git", "config", "github.token").strip
53
+ rescue
54
+ abort "Set github.token with: git config --global github.token <GITHUB-TOKEN>"
55
+ end
56
+
57
+ # find current tag
58
+ # TODO: allow users to set TAG= or do fuzzy match ?
59
+ tag = Rubinjam::Tasks.sh("git", "describe", "--tags", "--exact-match").strip
60
+
61
+ Rubinjam::Tasks.upload_binary(tag, github_token)
62
+ end
63
+ end
@@ -1,3 +1,3 @@
1
1
  module Rubinjam
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubinjam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-04 00:00:00.000000000 Z
11
+ date: 2018-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -35,6 +35,7 @@ files:
35
35
  - bin/rubinjam
36
36
  - lib/rubinjam.rb
37
37
  - lib/rubinjam/internal.rb
38
+ - lib/rubinjam/tasks.rb
38
39
  - lib/rubinjam/version.rb
39
40
  homepage: https://github.com/grosser/rubinjam
40
41
  licenses: