homebrew_automation 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/homebrew_automation/bottle.rb +20 -6
- data/lib/homebrew_automation/brew.rb +6 -1
- data/lib/homebrew_automation/cli/workflow_commands.rb +6 -1
- data/lib/homebrew_automation/git.rb +66 -84
- data/lib/homebrew_automation/logger.rb +38 -0
- data/lib/homebrew_automation/version.rb +1 -1
- data/lib/homebrew_automation/workflow.rb +49 -3
- data/lib/homebrew_automation.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8f714b1824002b10ec76bb31f58b61e18a78c998d0464fef5a434516fbb3d2e
|
4
|
+
data.tar.gz: 221d5a56b7832045fc66b3eb173da08e62e18e94d55d83581e660b6e3a6cf18c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dabc4291c10fd6810e6a36bcd1a8336e1e69ea10c8e6d2deb81f3c3afc353caa4e16d09f54fdbbeac6870c351093863190bdfbfc85aa6a4608e37abdecef0a9
|
7
|
+
data.tar.gz: da1f8b49b4b5d6e28acbfcbddc89aa10bf4223889378ab8158f73e4de653680d7f026622304577c98b0d63d43a7fd513132f04e63fbc9ac8afaab05864c1fbe3
|
@@ -9,6 +9,14 @@ module HomebrewAutomation
|
|
9
9
|
class Bottle
|
10
10
|
|
11
11
|
class Error < StandardError
|
12
|
+
|
13
|
+
attr_reader :original
|
14
|
+
|
15
|
+
def initialize(msg, original:)
|
16
|
+
@original = original
|
17
|
+
super(msg)
|
18
|
+
end
|
19
|
+
|
12
20
|
end
|
13
21
|
|
14
22
|
# @param tap_name [String] For use with +brew tap+
|
@@ -46,9 +54,8 @@ module HomebrewAutomation
|
|
46
54
|
# @yieldparam contents [String] The data of the binary Bottle tarball, as if
|
47
55
|
# read via {File#read}
|
48
56
|
# @return [NilClass]
|
49
|
-
# @raise [Error]
|
50
57
|
def build!(&block)
|
51
|
-
raise
|
58
|
+
raise StandardError, "Bottle#build! expects a block" unless block
|
52
59
|
call_brew! do
|
53
60
|
json_str = @bottle_finder.read_json!
|
54
61
|
(minus_minus, filename) = parse_for_tarball_path(json_str)
|
@@ -91,21 +98,28 @@ module HomebrewAutomation
|
|
91
98
|
# @return [Tuple<String, String>] +[minus_minus, filename]+
|
92
99
|
def parse_for_tarball_path(json_str)
|
93
100
|
begin
|
94
|
-
|
101
|
+
json = JSON.parse(json_str)
|
102
|
+
focus = json
|
95
103
|
[fully_qualified_formula_name, 'bottle', 'tags', @os_name].each do |key|
|
96
104
|
focus = focus[key]
|
97
105
|
if focus.nil?
|
98
|
-
raise
|
106
|
+
raise Error.new(
|
107
|
+
"unexpected JSON structure, couldn't find key: #{key}",
|
108
|
+
original: json)
|
99
109
|
end
|
100
110
|
end
|
101
111
|
# https://github.com/Homebrew/brew/pull/4612
|
102
112
|
minus_minus, filename = focus['local_filename'], focus['filename']
|
103
113
|
if minus_minus.nil? || filename.nil?
|
104
|
-
raise
|
114
|
+
raise Error.new(
|
115
|
+
"unexpected JSON structure, couldn't find both `local_filename` and `filename` keys: #{minus_minus.inspect}, #{filename.inspect}",
|
116
|
+
original: json)
|
105
117
|
end
|
106
118
|
[minus_minus, filename]
|
107
119
|
rescue JSON::ParserError => e
|
108
|
-
raise
|
120
|
+
raise Error.new(
|
121
|
+
"error parsing JSON: #{e}",
|
122
|
+
original: json_str)
|
109
123
|
end
|
110
124
|
end
|
111
125
|
|
@@ -7,6 +7,9 @@ module HomebrewAutomation
|
|
7
7
|
class Error < StandardError
|
8
8
|
end
|
9
9
|
|
10
|
+
class OlderVersionAlreadyInstalled < StandardError
|
11
|
+
end
|
12
|
+
|
10
13
|
# +brew tap "$name" "$url"+
|
11
14
|
#
|
12
15
|
# @param name [String]
|
@@ -28,6 +31,8 @@ module HomebrewAutomation
|
|
28
31
|
# @param fully_qualified_formula_name [String]
|
29
32
|
def self.install!(opts, fully_qualified_formula_name)
|
30
33
|
checked('brew', 'install', *opts, fully_qualified_formula_name)
|
34
|
+
rescue Error
|
35
|
+
raise OlderVersionAlreadyInstalled
|
31
36
|
end
|
32
37
|
|
33
38
|
# +brew bottle [opts] "$fully_qualified_formula_name"+
|
@@ -41,7 +46,7 @@ module HomebrewAutomation
|
|
41
46
|
private_class_method def self.checked(*args)
|
42
47
|
result = system(*args)
|
43
48
|
unless result
|
44
|
-
raise
|
49
|
+
raise Error.new(args.join(' '))
|
45
50
|
end
|
46
51
|
result
|
47
52
|
end
|
@@ -35,6 +35,7 @@ class HomebrewAutomation::CLI::WorkflowCommands < Thor
|
|
35
35
|
git,
|
36
36
|
formula_name,
|
37
37
|
bintray_version,
|
38
|
+
logger,
|
38
39
|
keep_tap_repo: options[:keep_tap_repo],
|
39
40
|
keep_homebrew_tmp: options[:keep_brew_tmp])
|
40
41
|
end
|
@@ -71,7 +72,7 @@ class HomebrewAutomation::CLI::WorkflowCommands < Thor
|
|
71
72
|
end
|
72
73
|
|
73
74
|
def git
|
74
|
-
HomebrewAutomation::Git
|
75
|
+
HomebrewAutomation::Git.new
|
75
76
|
end
|
76
77
|
|
77
78
|
# DOC: default values here
|
@@ -98,4 +99,8 @@ class HomebrewAutomation::CLI::WorkflowCommands < Thor
|
|
98
99
|
HomebrewAutomation::Workflow.new
|
99
100
|
end
|
100
101
|
|
102
|
+
def logger
|
103
|
+
HomebrewAutomation::Logger.new
|
104
|
+
end
|
105
|
+
|
101
106
|
end
|
@@ -9,106 +9,88 @@ module HomebrewAutomation
|
|
9
9
|
class Error < StandardError
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
raise_unless 'git', 'config', '--global', 'user.name', name
|
28
|
-
raise_unless 'git', 'config', '--global', 'user.email', email
|
29
|
-
end
|
12
|
+
# Set Git user's name and email
|
13
|
+
#
|
14
|
+
# Reads environment variables:
|
15
|
+
# - TRAVIS_GIT_USER_NAME
|
16
|
+
# - TRAVIS_GIT_USER_EMAIL
|
17
|
+
#
|
18
|
+
# If either env var is not set, do nothing.
|
19
|
+
#
|
20
|
+
# @return [NilClass]
|
21
|
+
def config!
|
22
|
+
name = ENV['TRAVIS_GIT_USER_NAME']
|
23
|
+
email = ENV['TRAVIS_GIT_USER_EMAIL']
|
24
|
+
if name && email
|
25
|
+
raise_unless 'git', 'config', '--global', 'user.name', name
|
26
|
+
raise_unless 'git', 'config', '--global', 'user.email', email
|
30
27
|
end
|
28
|
+
end
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
30
|
+
# Just +git clone+ the given URL
|
31
|
+
#
|
32
|
+
# @param url [String] git-friendly URL; could be filesystem path
|
33
|
+
# @param dir [String] optionally specify target dir name
|
34
|
+
# @return [NilClass]
|
35
|
+
def clone!(url, dir: nil)
|
36
|
+
if dir
|
37
|
+
raise_unless 'git', 'clone', url, dir
|
38
|
+
else
|
39
|
+
raise_unless 'git', 'clone', url
|
43
40
|
end
|
41
|
+
end
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
else
|
63
|
-
puts "Strange, you're calling Git#with_clone! without a block."
|
43
|
+
# Like {#clone!} , but allows you to do something inside
|
44
|
+
# the newly cloned directory, pushd-style.
|
45
|
+
#
|
46
|
+
# @see clone!
|
47
|
+
# @param url [String]
|
48
|
+
# @param dir [String]
|
49
|
+
# @param keep_dir [Boolean]
|
50
|
+
# @yieldparam dir [String] name of freshly cloned dir
|
51
|
+
# @yieldreturn [a] anything
|
52
|
+
# @return [a]
|
53
|
+
def with_clone!(url, dir, keep_dir: false, &block)
|
54
|
+
begin
|
55
|
+
clone! url, dir: dir
|
56
|
+
if block
|
57
|
+
Dir.chdir dir do
|
58
|
+
block.call(File.realpath '.')
|
64
59
|
end
|
65
|
-
|
66
|
-
|
67
|
-
FileUtils.remove_dir(dir) unless keep_dir
|
60
|
+
else
|
61
|
+
puts "Strange, you're calling Git#with_clone! without a block."
|
68
62
|
end
|
63
|
+
nil
|
64
|
+
ensure
|
65
|
+
FileUtils.remove_dir(dir) unless keep_dir
|
69
66
|
end
|
67
|
+
end
|
70
68
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
# Just +git push+
|
80
|
-
#
|
81
|
-
# @return [NilClass]
|
82
|
-
def push!
|
83
|
-
raise_unless 'git', 'push'
|
84
|
-
end
|
69
|
+
# +git commit --allow-empty -am "$msg"+
|
70
|
+
#
|
71
|
+
# @param msg [String] Git commit message
|
72
|
+
# @return [NilClass]
|
73
|
+
def commit_am!(msg)
|
74
|
+
raise_unless 'git', 'commit', '--allow-empty', '-am', msg
|
75
|
+
end
|
85
76
|
|
86
|
-
|
77
|
+
# Just +git push+
|
78
|
+
#
|
79
|
+
# @return [NilClass]
|
80
|
+
def push!
|
81
|
+
raise_unless 'git', 'push'
|
82
|
+
end
|
87
83
|
|
88
|
-
|
89
|
-
begin
|
90
|
-
result = system(*args)
|
91
|
-
unless result
|
92
|
-
raise Error, "Git command failed: #{args}"
|
93
|
-
end
|
94
|
-
result
|
95
|
-
end
|
96
|
-
end
|
84
|
+
private
|
97
85
|
|
98
|
-
|
99
|
-
|
86
|
+
def raise_unless(*args)
|
87
|
+
begin
|
100
88
|
result = system(*args)
|
101
89
|
unless result
|
102
|
-
|
103
|
-
puts caller
|
90
|
+
raise Error, args.join(' ')
|
104
91
|
end
|
105
92
|
result
|
106
93
|
end
|
107
|
-
|
108
|
-
def silently(*args)
|
109
|
-
system(*args)
|
110
|
-
end
|
111
|
-
|
112
94
|
end
|
113
95
|
|
114
96
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module HomebrewAutomation
|
5
|
+
|
6
|
+
# Help you see which parts of STDOUT came from HomebrewAutomation
|
7
|
+
class Logger
|
8
|
+
|
9
|
+
def info!(msg)
|
10
|
+
puts(bold(green("homebrew_automation.rb [info] (#{DateTime.now}): ")) + msg)
|
11
|
+
end
|
12
|
+
|
13
|
+
def error!(msg)
|
14
|
+
puts(red("homebrew_automation.rb [error] (#{DateTime.now}): ") + msg)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# https://stackoverflow.com/questions/1489183/colorized-ruby-output
|
20
|
+
def coloured(colour, msg)
|
21
|
+
"\e[#{colour}m#{msg}\e[0m"
|
22
|
+
end
|
23
|
+
|
24
|
+
def green(x)
|
25
|
+
coloured(32, x)
|
26
|
+
end
|
27
|
+
|
28
|
+
def red(x)
|
29
|
+
coloured(31, x)
|
30
|
+
end
|
31
|
+
|
32
|
+
def bold(x)
|
33
|
+
"\e[1m#{x}\e[22m"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -17,6 +17,7 @@ module HomebrewAutomation
|
|
17
17
|
# @param tap [Tap]
|
18
18
|
# @param formula_name [String] the name of the formula in the Tap
|
19
19
|
# @param bversion [Bintray::Version]
|
20
|
+
# @param logger [HomebrewAutomation::Logger]
|
20
21
|
#
|
21
22
|
# @param mac_os [Class] the MacOS class
|
22
23
|
# @param bottle [Class] the Bottle class
|
@@ -29,16 +30,25 @@ module HomebrewAutomation
|
|
29
30
|
git,
|
30
31
|
formula_name,
|
31
32
|
bversion,
|
33
|
+
logger,
|
32
34
|
mac_os: MacOS,
|
33
35
|
bottle: Bottle,
|
34
36
|
keep_tap_repo: false,
|
35
37
|
keep_homebrew_tmp: false)
|
38
|
+
logger.info!(
|
39
|
+
"Hello, this is HomebrewAutomation! I will now build your Formula and upload the " \
|
40
|
+
"bottles to Bintray.")
|
36
41
|
os_name = mac_os.identify_version!
|
42
|
+
logger.info!("First let's clone your Tap repo to see the Formula.")
|
37
43
|
git.with_clone!(tap.url, tap.repo, keep_dir: keep_tap_repo) do |cloned_dir|
|
38
44
|
tap.on_formula! formula_name do |formula|
|
39
45
|
formula.put_sdist(sdist.url, sdist.sha256)
|
40
46
|
end
|
41
47
|
git.commit_am! "Throwaway commit; just for building bottles"
|
48
|
+
logger.info!(
|
49
|
+
"I've updated the Formula file in our local Tap clone, and we're ready "\
|
50
|
+
"to start building the Bottle. This could take a long time if your Formula "\
|
51
|
+
"is slow to compile.")
|
42
52
|
bot = bottle.new(
|
43
53
|
'homebrew-automation/tmp-tap',
|
44
54
|
cloned_dir,
|
@@ -49,14 +59,40 @@ module HomebrewAutomation
|
|
49
59
|
# Bintray auto-creates Versions on file-upload.
|
50
60
|
# Re-creating an existing Version results in a 409.
|
51
61
|
#bversion.create!
|
62
|
+
logger.info!("Bottle built! Let me now upload the Bottle tarball to Bintray.")
|
52
63
|
begin
|
53
64
|
bversion.upload_file!(filename, contents)
|
54
65
|
rescue Bintray::Version::FileAlreadyExists
|
55
|
-
|
66
|
+
logger.info!("A file with the same name as the one we're uploading already exits on Bintray.")
|
56
67
|
end
|
57
68
|
end
|
58
69
|
bot
|
59
70
|
end
|
71
|
+
logger.info!("All done!")
|
72
|
+
rescue HomebrewAutomation::Bottle::Error => e
|
73
|
+
logger.error!([
|
74
|
+
"Something went wrong in a Bottle: " + e.message,
|
75
|
+
"Original JSON:",
|
76
|
+
e.original,
|
77
|
+
"Backtrace:",
|
78
|
+
e.backtrace.join("\n")
|
79
|
+
].join("\n"))
|
80
|
+
rescue HomebrewAutomation::Bottle::OlderVersionAlreadyInstalled => e
|
81
|
+
logger.error!([
|
82
|
+
"An older version of the Formula is already installed on your system. " \
|
83
|
+
"Please either manually uninstall or upgrade it, then try again.",
|
84
|
+
e.to_s,
|
85
|
+
"Caused by: #{e.cause}",
|
86
|
+
(e.cause ? e.cause.backtrace.join("\n") : '')
|
87
|
+
].join("\n"))
|
88
|
+
rescue HomebrewAutomation::Brew::Error => e
|
89
|
+
logger.error!(
|
90
|
+
"Something went wrong in this Homebrew command: " +
|
91
|
+
e.message + "\n" + e.backtrace.join("\n"))
|
92
|
+
rescue HomebrewAutomation::Git::Error => e
|
93
|
+
logger.error!(
|
94
|
+
"Something went wrong in this Git command: " +
|
95
|
+
e.message + "\n" + e.backtrace.join("\n"))
|
60
96
|
end
|
61
97
|
|
62
98
|
# Gather and publish bottles.
|
@@ -70,10 +106,19 @@ module HomebrewAutomation
|
|
70
106
|
# @param tap [Tap]
|
71
107
|
# @param formula_name [String] the name of the formula in the Tap
|
72
108
|
# @param bversion [Bintray::Version]
|
109
|
+
# @param logger [HomebrewAutomation::Logger]
|
73
110
|
# @return [NilClass]
|
74
|
-
def gather_and_publish_bottles!(sdist, tap, formula_name, bversion)
|
111
|
+
def gather_and_publish_bottles!(sdist, tap, formula_name, bversion, logger)
|
112
|
+
logger.info!(
|
113
|
+
"Hello, this is HomebrewAutomation! I will browse through your Bintray to " \
|
114
|
+
"see if there may be Bottles built earlier for your Formula, and update your " \
|
115
|
+
"Tap to refer to them.")
|
116
|
+
logger.info!(
|
117
|
+
"I will also update the source tarball of your Formula in your Tap, " \
|
118
|
+
"effectively releasing a new version of your Formula.")
|
75
119
|
git.with_clone!(tap.url, tap.repo) do
|
76
120
|
tap.on_formula! formula_name do |formula|
|
121
|
+
logger.info!("Let's see if any files on your Bintray look like Bottles.")
|
77
122
|
bottles = bversion.gather_bottles
|
78
123
|
bottles.reduce(
|
79
124
|
formula.
|
@@ -85,9 +130,10 @@ module HomebrewAutomation
|
|
85
130
|
end
|
86
131
|
git.config!
|
87
132
|
git.commit_am! "Add bottles for #{formula_name}@#{bversion.version_name}"
|
133
|
+
logger.info!("I've refered to the Bottles I found in this new commit. Let's push to your Tap!")
|
88
134
|
git.push!
|
89
135
|
end
|
90
|
-
|
136
|
+
logger.info!("All done!")
|
91
137
|
end
|
92
138
|
|
93
139
|
end
|
data/lib/homebrew_automation.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative 'homebrew_automation/bintray.rb'
|
|
5
5
|
require_relative 'homebrew_automation/bottle.rb'
|
6
6
|
require_relative 'homebrew_automation/formula.rb'
|
7
7
|
require_relative 'homebrew_automation/git.rb'
|
8
|
+
require_relative 'homebrew_automation/logger.rb'
|
8
9
|
require_relative 'homebrew_automation/mac_os.rb'
|
9
10
|
require_relative 'homebrew_automation/source_dist.rb'
|
10
11
|
require_relative 'homebrew_automation/tap.rb'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: homebrew_automation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- easoncxz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- lib/homebrew_automation/cli/workflow_commands.rb
|
157
157
|
- lib/homebrew_automation/formula.rb
|
158
158
|
- lib/homebrew_automation/git.rb
|
159
|
+
- lib/homebrew_automation/logger.rb
|
159
160
|
- lib/homebrew_automation/mac_os.rb
|
160
161
|
- lib/homebrew_automation/source_dist.rb
|
161
162
|
- lib/homebrew_automation/tap.rb
|