homebrew_automation 0.1.5 → 0.1.6
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/bintray/version.rb +19 -6
- data/lib/homebrew_automation/bottle.rb +78 -65
- data/lib/homebrew_automation/brew.rb +50 -0
- data/lib/homebrew_automation/cli/workflow_commands.rb +14 -9
- data/lib/homebrew_automation/git.rb +116 -0
- data/lib/homebrew_automation/mac_os.rb +3 -3
- data/lib/homebrew_automation/tap.rb +18 -80
- data/lib/homebrew_automation/version.rb +1 -1
- data/lib/homebrew_automation/workflow.rb +45 -25
- data/lib/homebrew_automation.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7857fc3a55cf794b0138e422f94c7ca6d259ba9cca51df74c46a07c2986231bb
|
4
|
+
data.tar.gz: d2c5d3a431e0983dafbd8d3504bfea58b6e2c4673272260f18a69ffba8fe3d76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a6ee4421b0b4a460b6cd6fc818b1e72952fdd1e0d17522cb1ec0787d28e66b05dbfae92bd21638c68a7a1a2c305a4fe52c4ff2dec52a0e35883836311879371
|
7
|
+
data.tar.gz: e0c4ae780bc69a17951f9d248a0b29e99a03f06f2f2343332f11d5693d343ab182fd18549a3f8cf3dcfc3d99efb2a080efba81fb25ab10e0b0243874ccc3bac3
|
@@ -11,6 +11,10 @@ module HomebrewAutomation::Bintray
|
|
11
11
|
# As per Bintray, a +Version+ is part of a +Package+ is part of a +Repository+.
|
12
12
|
class Version
|
13
13
|
|
14
|
+
# The file to upload already exists on Bintray
|
15
|
+
class FileAlreadyExists < StandardError
|
16
|
+
end
|
17
|
+
|
14
18
|
# @param client [Client] Connection to Bintray servers
|
15
19
|
# @param repo_name [String]
|
16
20
|
# @param package_name [String]
|
@@ -39,12 +43,21 @@ module HomebrewAutomation::Bintray
|
|
39
43
|
# @param filename [String]
|
40
44
|
# @param content [String] the bytes in the file
|
41
45
|
def upload_file!(filename, content)
|
42
|
-
|
43
|
-
@
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
begin
|
47
|
+
@client.upload_file(
|
48
|
+
@repo_name,
|
49
|
+
@package_name,
|
50
|
+
@version_name,
|
51
|
+
filename,
|
52
|
+
content)
|
53
|
+
rescue RestClient::ExceptionWithResponse => e
|
54
|
+
case e.response.code
|
55
|
+
when 409
|
56
|
+
raise FileAlreadyExists
|
57
|
+
else
|
58
|
+
raise e
|
59
|
+
end
|
60
|
+
end
|
48
61
|
end
|
49
62
|
|
50
63
|
# Download metadata about files that exist on Bintray for this +Version+
|
@@ -1,103 +1,116 @@
|
|
1
1
|
|
2
2
|
require 'json'
|
3
3
|
|
4
|
+
require_relative './brew.rb'
|
5
|
+
|
4
6
|
module HomebrewAutomation
|
5
7
|
|
6
|
-
#
|
8
|
+
# Metadata for building a Bottle for a Homebrew package
|
7
9
|
class Bottle
|
8
10
|
|
11
|
+
class Error < StandardError
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param tap_name [String] For use with +brew tap+
|
9
15
|
# @param tap_url [String] Something suitable for +git clone+, e.g. +git@github.com:easoncxz/homebrew-tap.git+ or +/some/path/to/my-git-repo+
|
10
16
|
# @param formula_name [String] As known by Homebrew
|
11
17
|
# @param os_name [String] As known by Homebrew, e.g. +el_capitan+
|
12
|
-
# @param filename [String] ???
|
13
|
-
# @param content [String] ???
|
14
18
|
# @param keep_tmp [Boolean] pass +--keep-tmp+ to +brew+
|
19
|
+
# @param brew [Brew] Homebrew effects
|
20
|
+
# @param bottle_finder [Bottle] Bottle-related filesystem effects
|
15
21
|
def initialize(
|
22
|
+
tap_name,
|
16
23
|
tap_url,
|
17
24
|
formula_name,
|
18
25
|
os_name,
|
19
|
-
|
20
|
-
|
21
|
-
|
26
|
+
keep_tmp: false,
|
27
|
+
brew: Brew,
|
28
|
+
bottle_finder: Bottle)
|
29
|
+
@tap_name = tap_name
|
22
30
|
@tap_url = tap_url
|
23
31
|
@formula_name = formula_name
|
24
32
|
@os_name = os_name
|
25
|
-
@filename = filename
|
26
|
-
@minus_minus = nil # https://github.com/Homebrew/brew/pull/4612
|
27
|
-
@content = content
|
28
33
|
@keep_tmp = keep_tmp
|
34
|
+
@brew = brew
|
35
|
+
@bottle_finder = bottle_finder
|
29
36
|
end
|
30
37
|
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# @raise [StandardError]
|
34
|
-
# @return [nil]
|
35
|
-
def build
|
36
|
-
complain unless system 'brew', 'tap', tmp_tap_name, @tap_url
|
37
|
-
maybe_keep_tmp = @keep_tmp ? ['--keep-tmp'] : []
|
38
|
-
install_cmd = ['brew', 'install', '--verbose'] + maybe_keep_tmp + ['--build-bottle', fully_qualified_formula_name]
|
39
|
-
complain unless system(*install_cmd)
|
40
|
-
complain unless system 'brew', 'bottle', '--verbose', '--json', '--no-rebuild', fully_qualified_formula_name
|
41
|
-
end
|
42
|
-
|
43
|
-
# Read and analyse metadata JSON file
|
44
|
-
# @return [Array<(String, String)>] {#minus_minus} and {#filename}
|
45
|
-
def locate_tarball
|
46
|
-
json_filename = Dir['*.bottle.json'].first
|
47
|
-
unless json_filename
|
48
|
-
build
|
49
|
-
return locate_tarball
|
50
|
-
end
|
51
|
-
json = JSON.parse(File.read(json_filename))
|
52
|
-
focus = json || complain
|
53
|
-
focus = focus[json.keys.first] || complain
|
54
|
-
focus = focus['bottle'] || complain
|
55
|
-
focus = focus['tags'] || complain
|
56
|
-
focus = focus[@os_name] || complain
|
57
|
-
@minus_minus, @filename = focus['local_filename'], focus['filename']
|
58
|
-
end
|
59
|
-
|
60
|
-
# The +brew bottle+ original output filename
|
38
|
+
# Build the bottle and get a binary tarball suitable for upload to Bintray
|
61
39
|
#
|
62
|
-
#
|
40
|
+
# Unless you've already run +brew install --build-bottle+ on that Formula
|
41
|
+
# on your system before, the returned effect would take ages to run (looking
|
42
|
+
# at about 30-60 minutes).
|
63
43
|
#
|
64
|
-
# @
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
#
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
44
|
+
# @yieldparam filename [String] A filename to tell Bintray which Homebrew can
|
45
|
+
# recognise
|
46
|
+
# @yieldparam contents [String] The data of the binary Bottle tarball, as if
|
47
|
+
# read via {File#read}
|
48
|
+
# @return [NilClass]
|
49
|
+
# @raise [Error]
|
50
|
+
def build!(&block)
|
51
|
+
raise Error, "Bottle#build! expects a block" unless block
|
52
|
+
call_brew! do
|
53
|
+
json_str = @bottle_finder.read_json!
|
54
|
+
(minus_minus, filename) = parse_for_tarball_path(json_str)
|
55
|
+
contents = @bottle_finder.read_tarball! minus_minus
|
56
|
+
block.call(filename, contents)
|
57
|
+
end
|
74
58
|
end
|
75
59
|
|
76
|
-
|
77
|
-
|
78
|
-
File.
|
79
|
-
@content = File.read filename
|
60
|
+
def self.read_json!
|
61
|
+
json_filename = Dir['*.bottle.json'].first
|
62
|
+
File.read(json_filename)
|
80
63
|
end
|
81
64
|
|
82
|
-
|
83
|
-
|
84
|
-
@content || load_tarball_from_disk
|
65
|
+
def self.read_tarball!(minus_minus)
|
66
|
+
File.read(minus_minus)
|
85
67
|
end
|
86
68
|
|
87
69
|
private
|
88
70
|
|
89
|
-
#
|
90
|
-
def
|
91
|
-
|
71
|
+
# tap, install, and bottle
|
72
|
+
def call_brew!(&block)
|
73
|
+
tapped = false
|
74
|
+
begin
|
75
|
+
@brew.tap!(@tap_name, @tap_url)
|
76
|
+
tapped = true
|
77
|
+
@brew.install!(
|
78
|
+
%w[--verbose --build-bottle] + if @keep_tmp then %w[--keep-tmp] else [] end,
|
79
|
+
fully_qualified_formula_name)
|
80
|
+
@brew.bottle!(
|
81
|
+
%w[--verbose --json --no-rebuild],
|
82
|
+
fully_qualified_formula_name)
|
83
|
+
block.call
|
84
|
+
ensure
|
85
|
+
@brew.untap! @tap_name if tapped
|
86
|
+
end
|
92
87
|
end
|
93
88
|
|
94
|
-
|
95
|
-
|
89
|
+
# pure-ish; raises exception
|
90
|
+
#
|
91
|
+
# @return [Tuple<String, String>] +[minus_minus, filename]+
|
92
|
+
def parse_for_tarball_path(json_str)
|
93
|
+
begin
|
94
|
+
focus = JSON.parse(json_str)
|
95
|
+
[fully_qualified_formula_name, 'bottle', 'tags', @os_name].each do |key|
|
96
|
+
focus = focus[key]
|
97
|
+
if focus.nil?
|
98
|
+
raise BottleError.new "unexpected JSON structure, couldn't find key: #{key}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
# https://github.com/Homebrew/brew/pull/4612
|
102
|
+
minus_minus, filename = focus['local_filename'], focus['filename']
|
103
|
+
if minus_minus.nil? || filename.nil?
|
104
|
+
raise BottleError.new "unexpected JSON structure, couldn't find both `local_filename` and `filename` keys: #{minus_minus.inspect}, #{filename.inspect}"
|
105
|
+
end
|
106
|
+
[minus_minus, filename]
|
107
|
+
rescue JSON::ParserError => e
|
108
|
+
raise BottleError.new "error parsing JSON: #{e}"
|
109
|
+
end
|
96
110
|
end
|
97
111
|
|
98
|
-
def
|
99
|
-
|
100
|
-
puts caller
|
112
|
+
def fully_qualified_formula_name
|
113
|
+
@tap_name + '/' + @formula_name
|
101
114
|
end
|
102
115
|
|
103
116
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
module HomebrewAutomation
|
3
|
+
|
4
|
+
# Homebrew effects
|
5
|
+
class Brew
|
6
|
+
|
7
|
+
class Error < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
# +brew tap "$name" "$url"+
|
11
|
+
#
|
12
|
+
# @param name [String]
|
13
|
+
# @param url [String]
|
14
|
+
def self.tap!(name, url)
|
15
|
+
checked('brew', 'tap', name, url)
|
16
|
+
end
|
17
|
+
|
18
|
+
# +brew untap "$name"+
|
19
|
+
#
|
20
|
+
# @param name [String]
|
21
|
+
def self.untap!(name)
|
22
|
+
checked('brew', 'untap', name)
|
23
|
+
end
|
24
|
+
|
25
|
+
# +brew install [opts] "$fully_qualified_formula_name"+
|
26
|
+
#
|
27
|
+
# @param opts [Array<String>]
|
28
|
+
# @param fully_qualified_formula_name [String]
|
29
|
+
def self.install!(opts, fully_qualified_formula_name)
|
30
|
+
checked('brew', 'install', *opts, fully_qualified_formula_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
# +brew bottle [opts] "$fully_qualified_formula_name"+
|
34
|
+
#
|
35
|
+
# @param opts [Array<String>]
|
36
|
+
# @param fully_qualified_formula_name [String]
|
37
|
+
def self.bottle!(opts, fully_qualified_formula_name)
|
38
|
+
checked('brew', 'bottle', *opts, fully_qualified_formula_name)
|
39
|
+
end
|
40
|
+
|
41
|
+
private_class_method def self.checked(*args)
|
42
|
+
result = system(*args)
|
43
|
+
unless result
|
44
|
+
raise BrewError.new("Command failed: #{args}")
|
45
|
+
end
|
46
|
+
result
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -21,19 +21,21 @@ class HomebrewAutomation::CLI::WorkflowCommands < Thor
|
|
21
21
|
class_option :bintray_repo
|
22
22
|
class_option :bintray_package
|
23
23
|
class_option :bintray_version
|
24
|
-
class_option :keep_tap_repo, :type => :boolean
|
25
24
|
|
26
25
|
desc 'build-and-upload', 'Build binary tarball from source tarball, then upload to Bintray'
|
27
26
|
long_desc <<-HERE_HERE
|
28
27
|
Since we're uploading to Bintray, we need a Bintray API KEY at `bintray_token`.
|
29
28
|
HERE_HERE
|
29
|
+
option :keep_tap_repo, :type => :boolean
|
30
30
|
option :keep_brew_tmp, :type => :boolean
|
31
31
|
def build_and_upload
|
32
|
-
workflow.build_and_upload_bottle(
|
32
|
+
workflow.build_and_upload_bottle!(
|
33
33
|
sdist,
|
34
34
|
tap,
|
35
|
+
git,
|
35
36
|
formula_name,
|
36
37
|
bintray_version,
|
38
|
+
keep_tap_repo: options[:keep_tap_repo],
|
37
39
|
keep_homebrew_tmp: options[:keep_brew_tmp])
|
38
40
|
end
|
39
41
|
|
@@ -45,7 +47,11 @@ class HomebrewAutomation::CLI::WorkflowCommands < Thor
|
|
45
47
|
Tap repo on Github via a Github OAuth token via `tap_token`.
|
46
48
|
HERE_HERE
|
47
49
|
def gather_and_publish
|
48
|
-
workflow.gather_and_publish_bottles(
|
50
|
+
workflow.gather_and_publish_bottles!(
|
51
|
+
sdist,
|
52
|
+
tap,
|
53
|
+
formula_name,
|
54
|
+
bintray_version)
|
49
55
|
end
|
50
56
|
|
51
57
|
private
|
@@ -57,16 +63,15 @@ class HomebrewAutomation::CLI::WorkflowCommands < Thor
|
|
57
63
|
options[:source_tag])
|
58
64
|
end
|
59
65
|
|
60
|
-
def keep_tap_repo?
|
61
|
-
options[:keep_tap_repo]
|
62
|
-
end
|
63
|
-
|
64
66
|
def tap
|
65
67
|
HomebrewAutomation::Tap.new(
|
66
68
|
options[:tap_user],
|
67
69
|
options[:tap_repo],
|
68
|
-
options[:tap_token]
|
69
|
-
|
70
|
+
options[:tap_token])
|
71
|
+
end
|
72
|
+
|
73
|
+
def git
|
74
|
+
HomebrewAutomation::Git
|
70
75
|
end
|
71
76
|
|
72
77
|
# DOC: default values here
|
@@ -0,0 +1,116 @@
|
|
1
|
+
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module HomebrewAutomation
|
5
|
+
|
6
|
+
# Git effects
|
7
|
+
class Git
|
8
|
+
|
9
|
+
class Error < StandardError
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
# Set Git user's name and email
|
15
|
+
#
|
16
|
+
# Reads environment variables:
|
17
|
+
# - TRAVIS_GIT_USER_NAME
|
18
|
+
# - TRAVIS_GIT_USER_EMAIL
|
19
|
+
#
|
20
|
+
# If either env var is not set, do nothing.
|
21
|
+
#
|
22
|
+
# @return [NilClass]
|
23
|
+
def config!
|
24
|
+
name = ENV['TRAVIS_GIT_USER_NAME']
|
25
|
+
email = ENV['TRAVIS_GIT_USER_EMAIL']
|
26
|
+
if name && email
|
27
|
+
raise_unless 'git', 'config', '--global', 'user.name', name
|
28
|
+
raise_unless 'git', 'config', '--global', 'user.email', email
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Just +git clone+ the given URL
|
33
|
+
#
|
34
|
+
# @param url [String] git-friendly URL; could be filesystem path
|
35
|
+
# @param dir [String] optionally specify target dir name
|
36
|
+
# @return [NilClass]
|
37
|
+
def clone!(url, dir: nil)
|
38
|
+
if dir
|
39
|
+
raise_unless 'git', 'clone', url, dir
|
40
|
+
else
|
41
|
+
raise_unless 'git', 'clone', url
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Like {#clone!} , but allows you to do something inside
|
46
|
+
# the newly cloned directory, pushd-style.
|
47
|
+
#
|
48
|
+
# @see clone!
|
49
|
+
# @param url [String]
|
50
|
+
# @param dir [String]
|
51
|
+
# @param keep_dir [Boolean]
|
52
|
+
# @yieldparam dir [String] name of freshly cloned dir
|
53
|
+
# @yieldreturn [a] anything
|
54
|
+
# @return [a]
|
55
|
+
def with_clone!(url, dir, keep_dir: false, &block)
|
56
|
+
begin
|
57
|
+
clone! url, dir: dir
|
58
|
+
if block
|
59
|
+
Dir.chdir dir do
|
60
|
+
block.call(File.realpath '.')
|
61
|
+
end
|
62
|
+
else
|
63
|
+
puts "Strange, you're calling Git#with_clone! without a block."
|
64
|
+
end
|
65
|
+
nil
|
66
|
+
ensure
|
67
|
+
FileUtils.remove_dir(dir) unless keep_dir
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# +git commit --allow-empty -am "$msg"+
|
72
|
+
#
|
73
|
+
# @param msg [String] Git commit message
|
74
|
+
# @return [NilClass]
|
75
|
+
def commit_am!(msg)
|
76
|
+
raise_unless 'git', 'commit', '--allow-empty', '-am', msg
|
77
|
+
end
|
78
|
+
|
79
|
+
# Just +git push+
|
80
|
+
#
|
81
|
+
# @return [NilClass]
|
82
|
+
def push!
|
83
|
+
raise_unless 'git', 'push'
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def raise_unless(*args)
|
89
|
+
begin
|
90
|
+
result = system(*args)
|
91
|
+
unless result
|
92
|
+
raise Error, "Git command failed: #{args}"
|
93
|
+
end
|
94
|
+
result
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Impure
|
99
|
+
def complain_unless(*args)
|
100
|
+
result = system(*args)
|
101
|
+
unless result
|
102
|
+
puts "Git command errored: #{args}"
|
103
|
+
puts caller
|
104
|
+
end
|
105
|
+
result
|
106
|
+
end
|
107
|
+
|
108
|
+
def silently(*args)
|
109
|
+
system(*args)
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -9,11 +9,11 @@ module HomebrewAutomation
|
|
9
9
|
# Return a macOS version name in a convention recognised by Homebrew, in
|
10
10
|
# particular by the Formula/Bottle DSL.
|
11
11
|
#
|
12
|
-
# @return [String]
|
13
|
-
def self.identify_version
|
12
|
+
# @return [String | NilClass]
|
13
|
+
def self.identify_version!
|
14
14
|
version =
|
15
15
|
begin
|
16
|
-
`sw_vers -productVersion
|
16
|
+
`sw_vers -productVersion`.chomp
|
17
17
|
rescue Errno::ENOENT # if we're not on a Mac
|
18
18
|
nil
|
19
19
|
end
|
@@ -6,27 +6,23 @@ module HomebrewAutomation
|
|
6
6
|
# A representation of a Github repo that acts as a Homebrew Tap.
|
7
7
|
class Tap
|
8
8
|
|
9
|
-
# Assign params to attributes.
|
10
|
-
#
|
11
9
|
# See {#user}, {#repo}, {#token}.
|
12
|
-
|
13
|
-
|
14
|
-
# directory when possible
|
15
|
-
def initialize(user, repo, token, keep_submodule: false)
|
10
|
+
def initialize(user, repo, token)
|
11
|
+
@user = user
|
16
12
|
@repo = repo
|
13
|
+
@token = token
|
17
14
|
@url = "https://#{token}@github.com/#{user}/#{repo}.git"
|
18
|
-
@keep_submodule = keep_submodule
|
19
15
|
end
|
20
16
|
|
21
|
-
# Github
|
17
|
+
# Github username
|
22
18
|
#
|
23
19
|
# @return [String]
|
24
|
-
attr_reader :
|
20
|
+
attr_reader :user
|
25
21
|
|
26
|
-
#
|
22
|
+
# Github repo name, as appears in Github URLs
|
27
23
|
#
|
28
24
|
# @return [String]
|
29
|
-
attr_reader :
|
25
|
+
attr_reader :repo
|
30
26
|
|
31
27
|
# Github OAuth token
|
32
28
|
#
|
@@ -35,37 +31,27 @@ module HomebrewAutomation
|
|
35
31
|
# @return [String]
|
36
32
|
attr_reader :token
|
37
33
|
|
38
|
-
#
|
39
|
-
#
|
40
|
-
# Haskell-y type: +forall a. &Block (() -> a) -> a+
|
34
|
+
# Repo URL, as expected by Git
|
41
35
|
#
|
42
|
-
# @
|
43
|
-
|
44
|
-
def with_git_clone(&block)
|
45
|
-
begin
|
46
|
-
_git_clone
|
47
|
-
Dir.chdir @repo, &block
|
48
|
-
ensure
|
49
|
-
_remove_git_submodule unless @keep_submodule
|
50
|
-
end
|
51
|
-
end
|
36
|
+
# @return [String]
|
37
|
+
attr_reader :url
|
52
38
|
|
53
39
|
# Overwrite the specified Formula file, in-place, on-disk
|
54
40
|
#
|
55
|
-
#
|
41
|
+
# A directory named +Formula+ is assumed to be on +Dir.pwd+.
|
56
42
|
#
|
57
43
|
# If no block is passed, then this tries to find the formula file, but then
|
58
|
-
#
|
44
|
+
# makes no changes to that Formula.
|
59
45
|
#
|
60
46
|
# @param formula [String] Part of the name to the file within the +Formula+
|
61
47
|
# directory inside the Tap repo's directory, excluding the +.rb+ suffix.
|
62
|
-
# @
|
63
|
-
# @
|
64
|
-
#
|
65
|
-
def on_formula(formula, &block)
|
66
|
-
name = "#{formula}.rb"
|
48
|
+
# @yieldparam formula [Formula] existing Formula
|
49
|
+
# @yieldreturn [Formula] after your modifications
|
50
|
+
# @return [Formula] new Formula
|
51
|
+
def on_formula!(formula, &block)
|
52
|
+
name = "#{formula}.rb"
|
67
53
|
block ||= ->(n) { n }
|
68
|
-
Dir.chdir 'Formula' do
|
54
|
+
Dir.chdir 'Formula' do
|
69
55
|
File.open name, 'r' do |old_file|
|
70
56
|
File.open "#{name}.new", 'w' do |new_file|
|
71
57
|
new_file.write(
|
@@ -78,54 +64,6 @@ module HomebrewAutomation
|
|
78
64
|
end
|
79
65
|
end
|
80
66
|
|
81
|
-
# Set Git user's name and email
|
82
|
-
#
|
83
|
-
# Reads environment variables:
|
84
|
-
# - TRAVIS_GIT_USER_NAME
|
85
|
-
# - TRAVIS_GIT_USER_EMAIL
|
86
|
-
#
|
87
|
-
# If either env var is not set, do nothing.
|
88
|
-
def git_config
|
89
|
-
name = ENV['TRAVIS_GIT_USER_NAME']
|
90
|
-
email = ENV['TRAVIS_GIT_USER_EMAIL']
|
91
|
-
if name && email
|
92
|
-
system 'git', 'config', '--global', 'user.name', name
|
93
|
-
system 'git', 'config', '--global', 'user.email', email
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# Just +git commit -am "$msg"+
|
98
|
-
#
|
99
|
-
# @param msg [String] Git commit message
|
100
|
-
# @raise [StandardError]
|
101
|
-
def git_commit_am(msg)
|
102
|
-
complain unless system "git", "commit", "-am", msg
|
103
|
-
end
|
104
|
-
|
105
|
-
# Just +git push+
|
106
|
-
#
|
107
|
-
# @raise [StandardError]
|
108
|
-
def git_push
|
109
|
-
complain unless system "git", "push"
|
110
|
-
end
|
111
|
-
|
112
|
-
# @raise [StandardError]
|
113
|
-
def _git_clone
|
114
|
-
complain unless system "git", "clone", @url
|
115
|
-
end
|
116
|
-
|
117
|
-
# @raise [StandardError]
|
118
|
-
def _remove_git_submodule
|
119
|
-
complain unless system "rm", "-rf", @repo
|
120
|
-
end
|
121
|
-
|
122
|
-
private
|
123
|
-
|
124
|
-
def complain
|
125
|
-
puts "HEY! Something has gone wrong and I need to complain. Stacktrace follows:"
|
126
|
-
puts caller
|
127
|
-
end
|
128
|
-
|
129
67
|
end
|
130
68
|
|
131
69
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
|
2
2
|
require_relative './mac_os.rb'
|
3
|
-
require_relative './
|
4
|
-
require_relative './source_dist.rb'
|
3
|
+
require_relative './bottle.rb'
|
5
4
|
|
6
5
|
module HomebrewAutomation
|
7
6
|
|
@@ -18,25 +17,45 @@ module HomebrewAutomation
|
|
18
17
|
# @param tap [Tap]
|
19
18
|
# @param formula_name [String] the name of the formula in the Tap
|
20
19
|
# @param bversion [Bintray::Version]
|
20
|
+
#
|
21
|
+
# @param mac_os [Class] the MacOS class
|
22
|
+
# @param bottle [Class] the Bottle class
|
23
|
+
# @param keep_homebrew_tmp [Boolean] keep the HOMEBREW_TEMP directory
|
24
|
+
#
|
21
25
|
# @return [Bottle]
|
22
|
-
def build_and_upload_bottle(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
def build_and_upload_bottle!(
|
27
|
+
sdist,
|
28
|
+
tap,
|
29
|
+
git,
|
30
|
+
formula_name,
|
31
|
+
bversion,
|
32
|
+
mac_os: MacOS,
|
33
|
+
bottle: Bottle,
|
34
|
+
keep_tap_repo: false,
|
35
|
+
keep_homebrew_tmp: false)
|
36
|
+
os_name = mac_os.identify_version!
|
37
|
+
git.with_clone!(tap.url, tap.repo, keep_dir: keep_tap_repo) do |cloned_dir|
|
38
|
+
tap.on_formula! formula_name do |formula|
|
26
39
|
formula.put_sdist(sdist.url, sdist.sha256)
|
27
40
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
git.commit_am! "Throwaway commit; just for building bottles"
|
42
|
+
bot = bottle.new(
|
43
|
+
'homebrew-automation/tmp-tap',
|
44
|
+
cloned_dir,
|
45
|
+
formula_name,
|
46
|
+
os_name,
|
47
|
+
keep_tmp: keep_homebrew_tmp)
|
48
|
+
bot.build! do |filename, contents|
|
49
|
+
# Bintray auto-creates Versions on file-upload.
|
50
|
+
# Re-creating an existing Version results in a 409.
|
51
|
+
#bversion.create!
|
52
|
+
begin
|
53
|
+
bversion.upload_file!(filename, contents)
|
54
|
+
rescue Bintray::Version::FileAlreadyExists
|
55
|
+
puts "A file with the same name as the one you're uploading already exits on Bintray"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
bot
|
40
59
|
end
|
41
60
|
end
|
42
61
|
|
@@ -51,10 +70,10 @@ module HomebrewAutomation
|
|
51
70
|
# @param tap [Tap]
|
52
71
|
# @param formula_name [String] the name of the formula in the Tap
|
53
72
|
# @param bversion [Bintray::Version]
|
54
|
-
# @return [
|
55
|
-
def gather_and_publish_bottles(sdist, tap, formula_name, bversion)
|
56
|
-
tap.
|
57
|
-
tap.on_formula
|
73
|
+
# @return [NilClass]
|
74
|
+
def gather_and_publish_bottles!(sdist, tap, formula_name, bversion)
|
75
|
+
git.with_clone!(tap.url, tap.repo) do
|
76
|
+
tap.on_formula! formula_name do |formula|
|
58
77
|
bottles = bversion.gather_bottles
|
59
78
|
bottles.reduce(
|
60
79
|
formula.
|
@@ -64,10 +83,11 @@ module HomebrewAutomation
|
|
64
83
|
f.put_bottle(os, checksum)
|
65
84
|
end
|
66
85
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
86
|
+
git.config!
|
87
|
+
git.commit_am! "Add bottles for #{formula_name}@#{bversion.version_name}"
|
88
|
+
git.push!
|
70
89
|
end
|
90
|
+
nil
|
71
91
|
end
|
72
92
|
|
73
93
|
end
|
data/lib/homebrew_automation.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
require_relative 'homebrew_automation/bintray.rb'
|
5
5
|
require_relative 'homebrew_automation/bottle.rb'
|
6
6
|
require_relative 'homebrew_automation/formula.rb'
|
7
|
+
require_relative 'homebrew_automation/git.rb'
|
7
8
|
require_relative 'homebrew_automation/mac_os.rb'
|
8
9
|
require_relative 'homebrew_automation/source_dist.rb'
|
9
10
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- easoncxz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -149,11 +149,13 @@ files:
|
|
149
149
|
- lib/homebrew_automation/bintray/client.rb
|
150
150
|
- lib/homebrew_automation/bintray/version.rb
|
151
151
|
- lib/homebrew_automation/bottle.rb
|
152
|
+
- lib/homebrew_automation/brew.rb
|
152
153
|
- lib/homebrew_automation/cli.rb
|
153
154
|
- lib/homebrew_automation/cli/cli.rb
|
154
155
|
- lib/homebrew_automation/cli/formula_commands.rb
|
155
156
|
- lib/homebrew_automation/cli/workflow_commands.rb
|
156
157
|
- lib/homebrew_automation/formula.rb
|
158
|
+
- lib/homebrew_automation/git.rb
|
157
159
|
- lib/homebrew_automation/mac_os.rb
|
158
160
|
- lib/homebrew_automation/source_dist.rb
|
159
161
|
- lib/homebrew_automation/tap.rb
|