gembrew 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +48 -14
- data/bin/gembrew +2 -0
- data/lib/gembrew/adder.rb +39 -0
- data/lib/gembrew/cli.rb +2 -0
- data/lib/gembrew/commands/add.rb +20 -0
- data/lib/gembrew/commands/build.rb +15 -4
- data/lib/gembrew/commands/check.rb +16 -5
- data/lib/gembrew/commands/init.rb +6 -4
- data/lib/gembrew/commands/shell.rb +4 -2
- data/lib/gembrew/config.rb +28 -7
- data/lib/gembrew/docker_check.rb +22 -24
- data/lib/gembrew/docker_runner.rb +67 -0
- data/lib/gembrew/docker_shell.rb +6 -24
- data/lib/gembrew/generator.rb +1 -1
- data/lib/gembrew/initializer.rb +19 -25
- data/lib/gembrew/templates/README.md.erb +55 -0
- data/lib/gembrew/templates/formula.rb.erb +1 -1
- data/lib/gembrew/templates/gembrew.yml.erb +0 -1
- data/lib/gembrew/version.rb +1 -1
- data/lib/gembrew.rb +2 -0
- metadata +5 -2
- data/lib/gembrew/templates/compose.yaml.erb +0 -29
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cea714943b01c87fdc8175f290093cb509dc6df00eb84fb5081cda8db9714e8c
|
|
4
|
+
data.tar.gz: 3255bb06ae22d87e2a6f81e7cab6484cf6ac2fe832e881b53bde0b9c95e4be78
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fc656e03acea77d7b449b4985cdf18a6f8fea25bce6c3f14df19c145a6d38e86059c02dc43e572ce776fcda64d6f2154bcc8c23d9de791b42aed87ed775e1795
|
|
7
|
+
data.tar.gz: 981ce3693cced89e212da3ab775ffef24875b8128a63e32ef9d32be123bbf9d24fe6d20c4648df8f50543c27b548bf8f6e0ad451cbe76032ea3b886730a1b2d8
|
data/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Gembrew
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
3
5
|
Generate conventional Homebrew formulae for published Ruby command-line gems.
|
|
4
6
|
|
|
5
7
|
## Install
|
|
@@ -18,35 +20,56 @@ gembrew build
|
|
|
18
20
|
gembrew check
|
|
19
21
|
```
|
|
20
22
|
|
|
21
|
-
`init`
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
The configuration filename is always `gembrew.yml`.
|
|
23
|
+
`init` creates a tap repository containing `README.md`, `gembrew/`, and
|
|
24
|
+
`Formula/`. It accepts an empty directory or an existing tap containing
|
|
25
|
+
`Formula/`. Supplying a gem name also creates its first configuration. The gem
|
|
26
|
+
name is optional, so `gembrew init` can prepare an empty tap or add Gembrew to
|
|
27
|
+
an existing one. An existing `README.md` is never overwritten.
|
|
27
28
|
|
|
28
29
|
For example, `gembrew init example` generates:
|
|
29
30
|
|
|
31
|
+
```text
|
|
32
|
+
README.md
|
|
33
|
+
gembrew/
|
|
34
|
+
example.yml
|
|
35
|
+
Formula/
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`gembrew/example.yml` contains:
|
|
39
|
+
|
|
30
40
|
```yaml
|
|
31
41
|
gem: example
|
|
32
|
-
output: Formula/example.rb
|
|
33
42
|
|
|
34
43
|
test: |-
|
|
35
44
|
system bin/"example", "--version"
|
|
36
45
|
```
|
|
37
46
|
|
|
38
|
-
Edit
|
|
47
|
+
Edit the configuration as needed, then generate `Formula/example.rb`:
|
|
39
48
|
|
|
40
49
|
```shell
|
|
41
50
|
gembrew build
|
|
42
51
|
```
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
Each YAML file under `gembrew/` describes one formula. Add more published gems
|
|
54
|
+
with:
|
|
55
|
+
|
|
56
|
+
```shell
|
|
57
|
+
gembrew add another-gem
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Plain `build` generates every configured formula. Pass a configuration name to
|
|
61
|
+
generate just one:
|
|
62
|
+
|
|
63
|
+
```shell
|
|
64
|
+
gembrew build example
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The required settings are `gem` and exactly one of `test` or `test_from_file`.
|
|
68
|
+
The output defaults to `Formula/NAME.rb`, where `NAME` is the configuration
|
|
69
|
+
filename. Relative paths are resolved from the tap root.
|
|
46
70
|
|
|
47
71
|
```yaml
|
|
48
72
|
gem: example
|
|
49
|
-
output: Formula/example.rb
|
|
50
73
|
|
|
51
74
|
# Optional published gem version. The latest stable version is used by default.
|
|
52
75
|
version: "1.2.3"
|
|
@@ -57,6 +80,9 @@ homepage: https://example.com
|
|
|
57
80
|
license: MIT
|
|
58
81
|
executable: example
|
|
59
82
|
|
|
83
|
+
# Optional output override. The default for gembrew/example.yml is shown here.
|
|
84
|
+
output: Formula/example.rb
|
|
85
|
+
|
|
60
86
|
test: |-
|
|
61
87
|
system bin/"example", "--version"
|
|
62
88
|
|
|
@@ -85,15 +111,23 @@ brew install --build-from-source example
|
|
|
85
111
|
brew test example
|
|
86
112
|
```
|
|
87
113
|
|
|
114
|
+
To test a published tap without mounting the local repository, open a pristine
|
|
115
|
+
Homebrew shell:
|
|
116
|
+
|
|
117
|
+
```shell
|
|
118
|
+
gembrew shell --pristine
|
|
119
|
+
```
|
|
120
|
+
|
|
88
121
|
Run the complete workflow non-interactively in one clean container:
|
|
89
122
|
|
|
90
123
|
```shell
|
|
91
124
|
gembrew check
|
|
92
125
|
```
|
|
93
126
|
|
|
94
|
-
This rebuilds
|
|
95
|
-
installation, and the formula test
|
|
96
|
-
|
|
127
|
+
This rebuilds every configured formula, then runs Homebrew style, online audit,
|
|
128
|
+
source installation, and the formula test in disposable Homebrew containers.
|
|
129
|
+
Use `gembrew check example` to check only one formula. Gembrew invokes Docker
|
|
130
|
+
directly; the tap does not need generated container support files.
|
|
97
131
|
|
|
98
132
|
## Contributing / Support
|
|
99
133
|
|
data/bin/gembrew
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'erb'
|
|
2
|
+
require 'pathname'
|
|
3
|
+
require 'gembrew/config'
|
|
4
|
+
require 'gembrew/error'
|
|
5
|
+
|
|
6
|
+
module Gembrew
|
|
7
|
+
class Adder
|
|
8
|
+
attr_reader :gem_name, :project_path
|
|
9
|
+
|
|
10
|
+
def initialize(gem_name, project_path: Pathname.pwd)
|
|
11
|
+
@gem_name = gem_name
|
|
12
|
+
@project_path = Pathname(project_path).expand_path
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def call
|
|
16
|
+
Config.validate_name! gem_name
|
|
17
|
+
unless formula_path.directory?
|
|
18
|
+
raise Error, "Directory is not a Homebrew tap: #{project_path} (Formula/ does not exist)"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
config_directory.mkpath
|
|
22
|
+
raise Error, "Gem configuration already exists: #{config_path}" if config_path.exist?
|
|
23
|
+
|
|
24
|
+
config_path.write render
|
|
25
|
+
config_path
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def formula_path = project_path/'Formula'
|
|
31
|
+
def config_directory = project_path/'gembrew'
|
|
32
|
+
def config_path = config_directory/"#{gem_name}.yml"
|
|
33
|
+
|
|
34
|
+
def render
|
|
35
|
+
template = Pathname(__dir__)/'templates/gembrew.yml.erb'
|
|
36
|
+
ERB.new(template.read, trim_mode: '-').result(binding)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/lib/gembrew/cli.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'mister_bin'
|
|
2
2
|
require 'gembrew/commands/build'
|
|
3
|
+
require 'gembrew/commands/add'
|
|
3
4
|
require 'gembrew/commands/check'
|
|
4
5
|
require 'gembrew/commands/init'
|
|
5
6
|
require 'gembrew/commands/shell'
|
|
@@ -13,6 +14,7 @@ module Gembrew
|
|
|
13
14
|
footer: 'Run m`gembrew COMMAND --help` for more information'
|
|
14
15
|
|
|
15
16
|
runner.route 'init', to: Commands::Init
|
|
17
|
+
runner.route 'add', to: Commands::Add
|
|
16
18
|
runner.route 'build', to: Commands::Build
|
|
17
19
|
runner.route 'check', to: Commands::Check
|
|
18
20
|
runner.route 'shell', to: Commands::Shell
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'mister_bin'
|
|
2
|
+
require 'gembrew/adder'
|
|
3
|
+
|
|
4
|
+
module Gembrew
|
|
5
|
+
module Commands
|
|
6
|
+
class Add < MisterBin::Command
|
|
7
|
+
help 'Add a Ruby gem to this tap repository'
|
|
8
|
+
|
|
9
|
+
usage 'gembrew add GEM'
|
|
10
|
+
usage 'gembrew add (-h|--help)'
|
|
11
|
+
|
|
12
|
+
param 'GEM', 'Published Ruby gem name'
|
|
13
|
+
|
|
14
|
+
def run
|
|
15
|
+
path = Adder.new(args['GEM']).call
|
|
16
|
+
say "Added m`#{path}`"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -4,14 +4,25 @@ require 'gembrew/generator'
|
|
|
4
4
|
module Gembrew
|
|
5
5
|
module Commands
|
|
6
6
|
class Build < MisterBin::Command
|
|
7
|
-
help 'Generate
|
|
7
|
+
help 'Generate Homebrew formulae from gembrew/*.yml'
|
|
8
8
|
|
|
9
|
-
usage 'gembrew build'
|
|
9
|
+
usage 'gembrew build [GEM]'
|
|
10
10
|
usage 'gembrew build (-h|--help)'
|
|
11
11
|
|
|
12
|
+
param 'GEM', 'Optional gem configuration name'
|
|
13
|
+
|
|
12
14
|
def run
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
configs.each do |config|
|
|
16
|
+
say "bb`==> gembrew: building #{config.name}`"
|
|
17
|
+
output_path = Generator.new(config: config).call
|
|
18
|
+
say "Generated m`#{output_path}`"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def configs
|
|
25
|
+
args['GEM'] ? [Config.find(args['GEM'])] : Config.all
|
|
15
26
|
end
|
|
16
27
|
end
|
|
17
28
|
end
|
|
@@ -5,17 +5,28 @@ require 'gembrew/generator'
|
|
|
5
5
|
module Gembrew
|
|
6
6
|
module Commands
|
|
7
7
|
class Check < MisterBin::Command
|
|
8
|
-
help 'Build and test
|
|
8
|
+
help 'Build and test formulae in clean Homebrew environments'
|
|
9
9
|
|
|
10
|
-
usage 'gembrew check'
|
|
10
|
+
usage 'gembrew check [GEM]'
|
|
11
11
|
usage 'gembrew check (-h|--help)'
|
|
12
12
|
|
|
13
|
+
param 'GEM', 'Optional gem configuration name'
|
|
14
|
+
|
|
13
15
|
def run
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
configs.each do |config|
|
|
17
|
+
say "bb`==> gembrew: building #{config.name}`"
|
|
18
|
+
output_path = Generator.new(config: config).call
|
|
19
|
+
say "Generated m`#{output_path}`"
|
|
20
|
+
DockerCheck.new.call output_path.basename('.rb').to_s
|
|
21
|
+
end
|
|
17
22
|
say 'g`All checks passed`'
|
|
18
23
|
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def configs
|
|
28
|
+
args['GEM'] ? [Config.find(args['GEM'])] : Config.all
|
|
29
|
+
end
|
|
19
30
|
end
|
|
20
31
|
end
|
|
21
32
|
end
|
|
@@ -4,16 +4,18 @@ require 'gembrew/initializer'
|
|
|
4
4
|
module Gembrew
|
|
5
5
|
module Commands
|
|
6
6
|
class Init < MisterBin::Command
|
|
7
|
-
help 'Initialize a Homebrew tap repository
|
|
7
|
+
help 'Initialize a Homebrew tap repository'
|
|
8
8
|
|
|
9
|
-
usage 'gembrew init GEM'
|
|
9
|
+
usage 'gembrew init [GEM]'
|
|
10
10
|
usage 'gembrew init (-h|--help)'
|
|
11
11
|
|
|
12
|
-
param 'GEM', '
|
|
12
|
+
param 'GEM', 'Optional published Ruby gem name'
|
|
13
13
|
|
|
14
14
|
def run
|
|
15
15
|
Initializer.new(args['GEM']).call
|
|
16
|
-
|
|
16
|
+
message = "Initialized m`#{Dir.pwd}`"
|
|
17
|
+
message += " for bb`#{args['GEM']}`" if args['GEM']
|
|
18
|
+
say message
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
end
|
|
@@ -6,11 +6,13 @@ module Gembrew
|
|
|
6
6
|
class Shell < MisterBin::Command
|
|
7
7
|
help 'Open a Homebrew shell for this tap repository'
|
|
8
8
|
|
|
9
|
-
usage 'gembrew shell'
|
|
9
|
+
usage 'gembrew shell [--pristine]'
|
|
10
10
|
usage 'gembrew shell (-h|--help)'
|
|
11
11
|
|
|
12
|
+
option '-p --pristine', 'Open without mounting the local tap'
|
|
13
|
+
|
|
12
14
|
def run
|
|
13
|
-
DockerShell.new.call
|
|
15
|
+
DockerShell.new.call pristine: args['--pristine']
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
18
|
end
|
data/lib/gembrew/config.rb
CHANGED
|
@@ -4,22 +4,44 @@ require 'gembrew/error'
|
|
|
4
4
|
|
|
5
5
|
module Gembrew
|
|
6
6
|
class Config
|
|
7
|
-
|
|
7
|
+
DIRECTORY = 'gembrew'
|
|
8
8
|
ALLOWED_KEYS = %w[
|
|
9
9
|
gem version output desc homepage license executable test test_from_file
|
|
10
10
|
].freeze
|
|
11
11
|
|
|
12
|
-
attr_reader :path
|
|
12
|
+
attr_reader :path, :project_path
|
|
13
13
|
|
|
14
|
-
def
|
|
15
|
-
|
|
14
|
+
def self.all(project_path = Pathname.pwd)
|
|
15
|
+
project_path = Pathname(project_path).expand_path
|
|
16
|
+
paths = (project_path/DIRECTORY).glob('*.yml').sort
|
|
17
|
+
raise Error, "No gem configurations found in #{project_path/DIRECTORY}" if paths.empty?
|
|
18
|
+
|
|
19
|
+
paths.map { |path| new path, project_path: project_path }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.find(name, project_path = Pathname.pwd)
|
|
23
|
+
validate_name! name
|
|
24
|
+
project_path = Pathname(project_path).expand_path
|
|
25
|
+
new project_path/DIRECTORY/"#{name}.yml", project_path: project_path
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.validate_name!(name)
|
|
29
|
+
return name if name&.match?(/\A[a-zA-Z0-9._-]+\z/)
|
|
30
|
+
|
|
31
|
+
raise Error, "Invalid gem name: #{name.inspect}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def initialize(path, project_path: nil)
|
|
35
|
+
@path = Pathname(path).expand_path
|
|
36
|
+
@project_path = project_path ? Pathname(project_path).expand_path : @path.dirname.parent
|
|
16
37
|
@data = load_data
|
|
17
38
|
validate
|
|
18
39
|
end
|
|
19
40
|
|
|
41
|
+
def name = path.basename('.yml').to_s
|
|
20
42
|
def gem_name = data.fetch('gem').to_s
|
|
21
43
|
def version = data['version']&.to_s
|
|
22
|
-
def output_path = (
|
|
44
|
+
def output_path = (project_path/(data['output'] || "Formula/#{name}.rb")).expand_path
|
|
23
45
|
def description = data['desc']
|
|
24
46
|
def homepage = data['homepage']
|
|
25
47
|
def license = data['license']
|
|
@@ -29,7 +51,7 @@ module Gembrew
|
|
|
29
51
|
@test_body ||= if data.has_key?('test')
|
|
30
52
|
data.fetch('test').to_s
|
|
31
53
|
else
|
|
32
|
-
test_path =
|
|
54
|
+
test_path = project_path/data.fetch('test_from_file')
|
|
33
55
|
raise Error, "Test file does not exist: #{test_path}" unless test_path.file?
|
|
34
56
|
|
|
35
57
|
test_path.read
|
|
@@ -55,7 +77,6 @@ module Gembrew
|
|
|
55
77
|
raise Error, "Unknown configuration keys: #{unknown_keys.join(', ')}" if unknown_keys.any?
|
|
56
78
|
|
|
57
79
|
require_value 'gem'
|
|
58
|
-
require_value 'output'
|
|
59
80
|
|
|
60
81
|
return unless data.has_key?('test') == data.has_key?('test_from_file')
|
|
61
82
|
|
data/lib/gembrew/docker_check.rb
CHANGED
|
@@ -1,25 +1,15 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'shellwords'
|
|
2
|
+
require 'gembrew/docker_runner'
|
|
2
3
|
require 'gembrew/error'
|
|
3
4
|
|
|
4
5
|
module Gembrew
|
|
5
6
|
class DockerCheck
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
attr_reader :project_path
|
|
9
|
-
|
|
10
|
-
def initialize(project_path: Pathname.pwd, command_runner: nil)
|
|
11
|
-
@project_path = Pathname(project_path).expand_path
|
|
12
|
-
@command_runner = command_runner || method(:run_command)
|
|
7
|
+
def initialize(runner: DockerRunner.new)
|
|
8
|
+
@runner = runner
|
|
13
9
|
end
|
|
14
10
|
|
|
15
|
-
def call
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
success = command_runner.call(
|
|
19
|
-
'docker', 'compose', '-f', COMPOSE_PATH.to_s,
|
|
20
|
-
'run', '--rm', '--no-TTY', 'check',
|
|
21
|
-
chdir: project_path
|
|
22
|
-
)
|
|
11
|
+
def call(formula)
|
|
12
|
+
success = runner.call 'bash', '-euc', script(formula)
|
|
23
13
|
raise Error, 'Homebrew checks failed' unless success
|
|
24
14
|
|
|
25
15
|
true
|
|
@@ -27,14 +17,22 @@ module Gembrew
|
|
|
27
17
|
|
|
28
18
|
private
|
|
29
19
|
|
|
30
|
-
attr_reader :
|
|
31
|
-
|
|
32
|
-
def
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
20
|
+
attr_reader :runner
|
|
21
|
+
|
|
22
|
+
def script(formula)
|
|
23
|
+
formula = Shellwords.escape formula
|
|
24
|
+
<<~BASH
|
|
25
|
+
caption() { printf '\\n\\033[1;34m==> gembrew: %s\\033[0m\\n' "$1"; }
|
|
26
|
+
formula=#{formula}
|
|
27
|
+
caption "styling $formula"
|
|
28
|
+
brew style "$formula"
|
|
29
|
+
caption "auditing $formula"
|
|
30
|
+
brew audit --new --online "$formula"
|
|
31
|
+
caption "installing $formula"
|
|
32
|
+
brew install --build-from-source "$formula"
|
|
33
|
+
caption "testing $formula"
|
|
34
|
+
brew test "$formula"
|
|
35
|
+
BASH
|
|
38
36
|
end
|
|
39
37
|
end
|
|
40
38
|
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'pathname'
|
|
2
|
+
|
|
3
|
+
module Gembrew
|
|
4
|
+
class DockerRunner
|
|
5
|
+
IMAGE = 'homebrew/brew:main'
|
|
6
|
+
TAP_PATH = '/home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/gembrew/homebrew-tap'
|
|
7
|
+
|
|
8
|
+
attr_reader :project_path
|
|
9
|
+
|
|
10
|
+
def initialize(project_path: Pathname.pwd, command_runner: nil)
|
|
11
|
+
@project_path = Pathname(project_path).expand_path
|
|
12
|
+
@command_runner = command_runner || method(:run_command)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def call(*command, interactive: false, pristine: false)
|
|
16
|
+
docker_command = ['docker', 'run', '--rm', '--init', '--name', container_name]
|
|
17
|
+
docker_command << '-it' if interactive
|
|
18
|
+
docker_command.concat environment(interactive: interactive, pristine: pristine)
|
|
19
|
+
unless pristine
|
|
20
|
+
docker_command.push '--workdir', '/work'
|
|
21
|
+
docker_command.push '--volume', "#{project_path}:/work"
|
|
22
|
+
docker_command.push '--volume', "#{project_path}:#{TAP_PATH}"
|
|
23
|
+
end
|
|
24
|
+
docker_command << IMAGE
|
|
25
|
+
docker_command.concat command
|
|
26
|
+
command_runner.call(*docker_command, chdir: project_path)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
attr_reader :command_runner
|
|
32
|
+
|
|
33
|
+
def environment(interactive:, pristine:)
|
|
34
|
+
result = %w[
|
|
35
|
+
--env HOMEBREW_NO_AUTO_UPDATE=1
|
|
36
|
+
--env HOMEBREW_NO_INSTALL_CLEANUP=1
|
|
37
|
+
--env HOMEBREW_NO_INSTALL_FROM_API=1
|
|
38
|
+
]
|
|
39
|
+
prompt = pristine ? 'homebrew' : 'gembrew'
|
|
40
|
+
result.push '--env', "PS1=\\n\\n#{prompt} $ " if interactive
|
|
41
|
+
result
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def run_command(*command, chdir:)
|
|
45
|
+
success = system(*command, chdir: chdir.to_s)
|
|
46
|
+
cleanup_container command unless success
|
|
47
|
+
success
|
|
48
|
+
rescue Interrupt
|
|
49
|
+
previous_handler = Signal.trap 'INT', 'IGNORE'
|
|
50
|
+
begin
|
|
51
|
+
cleanup_container command
|
|
52
|
+
ensure
|
|
53
|
+
Signal.trap 'INT', previous_handler
|
|
54
|
+
end
|
|
55
|
+
raise
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def container_name
|
|
59
|
+
"gembrew-#{Process.pid}"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def cleanup_container(command)
|
|
63
|
+
name = command.fetch(command.index('--name') + 1)
|
|
64
|
+
system 'docker', 'rm', '--force', name, out: File::NULL, err: File::NULL
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
data/lib/gembrew/docker_shell.rb
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'gembrew/docker_runner'
|
|
2
2
|
require 'gembrew/error'
|
|
3
3
|
|
|
4
4
|
module Gembrew
|
|
5
5
|
class DockerShell
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
attr_reader :project_path
|
|
9
|
-
|
|
10
|
-
def initialize(project_path: Pathname.pwd, command_runner: nil)
|
|
11
|
-
@project_path = Pathname(project_path).expand_path
|
|
12
|
-
@command_runner = command_runner || method(:run_command)
|
|
6
|
+
def initialize(runner: DockerRunner.new)
|
|
7
|
+
@runner = runner
|
|
13
8
|
end
|
|
14
9
|
|
|
15
|
-
def call
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
success = command_runner.call(
|
|
19
|
-
'docker', 'compose', '-f', COMPOSE_PATH.to_s, 'run', '--rm', 'brew',
|
|
20
|
-
chdir: project_path
|
|
21
|
-
)
|
|
10
|
+
def call(pristine: false)
|
|
11
|
+
success = runner.call 'bash', '--norc', interactive: true, pristine: pristine
|
|
22
12
|
raise Error, 'Homebrew shell exited with an error' unless success
|
|
23
13
|
|
|
24
14
|
true
|
|
@@ -26,14 +16,6 @@ module Gembrew
|
|
|
26
16
|
|
|
27
17
|
private
|
|
28
18
|
|
|
29
|
-
attr_reader :
|
|
30
|
-
|
|
31
|
-
def compose_path
|
|
32
|
-
project_path/COMPOSE_PATH
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def run_command(*command, chdir:)
|
|
36
|
-
system(*command, chdir: chdir.to_s)
|
|
37
|
-
end
|
|
19
|
+
attr_reader :runner
|
|
38
20
|
end
|
|
39
21
|
end
|
data/lib/gembrew/generator.rb
CHANGED
|
@@ -4,7 +4,7 @@ require 'gembrew/resolver'
|
|
|
4
4
|
|
|
5
5
|
module Gembrew
|
|
6
6
|
class Generator
|
|
7
|
-
def initialize(config
|
|
7
|
+
def initialize(config:, resolver: Resolver.new, renderer: Renderer.new)
|
|
8
8
|
@config = config
|
|
9
9
|
@resolver = resolver
|
|
10
10
|
@renderer = renderer
|
data/lib/gembrew/initializer.rb
CHANGED
|
@@ -1,63 +1,57 @@
|
|
|
1
1
|
require 'erb'
|
|
2
2
|
require 'fileutils'
|
|
3
3
|
require 'pathname'
|
|
4
|
+
require 'gembrew/adder'
|
|
4
5
|
require 'gembrew/error'
|
|
5
6
|
|
|
6
7
|
module Gembrew
|
|
7
8
|
class Initializer
|
|
8
|
-
CONFIG_FILENAME = 'gembrew.yml'
|
|
9
|
-
|
|
10
9
|
attr_reader :gem_name, :project_path
|
|
11
10
|
|
|
12
|
-
def initialize(gem_name, project_path: Pathname.pwd)
|
|
11
|
+
def initialize(gem_name = nil, project_path: Pathname.pwd)
|
|
13
12
|
@gem_name = gem_name
|
|
14
13
|
@project_path = Pathname(project_path).expand_path
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
def call
|
|
18
|
-
|
|
17
|
+
Config.validate_name! gem_name if gem_name
|
|
18
|
+
validate_project
|
|
19
19
|
|
|
20
20
|
formula_path.mkpath
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
config_directory.mkpath
|
|
22
|
+
readme_path.write render_readme unless readme_path.exist?
|
|
23
|
+
Adder.new(gem_name, project_path: project_path).call if gem_name
|
|
24
24
|
|
|
25
25
|
project_path
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
private
|
|
29
29
|
|
|
30
|
-
def config_path
|
|
31
|
-
project_path/CONFIG_FILENAME
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def compose_path
|
|
35
|
-
support_path/'compose.yaml'
|
|
36
|
-
end
|
|
37
|
-
|
|
38
30
|
def formula_path
|
|
39
31
|
project_path/'Formula'
|
|
40
32
|
end
|
|
41
33
|
|
|
42
|
-
def
|
|
43
|
-
project_path/'
|
|
34
|
+
def config_directory
|
|
35
|
+
project_path/'gembrew'
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def readme_path
|
|
39
|
+
project_path/'README.md'
|
|
44
40
|
end
|
|
45
41
|
|
|
46
42
|
def entries
|
|
47
43
|
@entries ||= project_path.children.reject { |path| path.basename.to_s == '.git' }
|
|
48
44
|
end
|
|
49
45
|
|
|
50
|
-
def
|
|
51
|
-
entries.
|
|
52
|
-
end
|
|
46
|
+
def validate_project
|
|
47
|
+
return if entries.empty? || formula_path.directory?
|
|
53
48
|
|
|
54
|
-
|
|
55
|
-
template = asset_path filename
|
|
56
|
-
ERB.new(template.read, trim_mode: '-').result(binding)
|
|
49
|
+
raise Error, "Directory is not a Homebrew tap: #{project_path} (Formula/ does not exist)"
|
|
57
50
|
end
|
|
58
51
|
|
|
59
|
-
def
|
|
60
|
-
Pathname(__dir__)/'templates'
|
|
52
|
+
def render_readme
|
|
53
|
+
template = Pathname(__dir__)/'templates/README.md.erb'
|
|
54
|
+
ERB.new(template.read, trim_mode: '-').result(binding)
|
|
61
55
|
end
|
|
62
56
|
end
|
|
63
57
|
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Homebrew Tap
|
|
2
|
+
|
|
3
|
+
<!-- Replace OWNER/TAP with your Homebrew tap name, for example dannyben/tools. -->
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
brew tap OWNER/TAP
|
|
9
|
+
brew install <%= gem_name || 'FORMULA' %>
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Or install the formula directly:
|
|
13
|
+
|
|
14
|
+
```shell
|
|
15
|
+
brew install OWNER/TAP/<%= gem_name || 'FORMULA' %>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Development
|
|
19
|
+
|
|
20
|
+
Install [Gembrew](https://github.com/DannyBen/gembrew):
|
|
21
|
+
|
|
22
|
+
```shell
|
|
23
|
+
gem install gembrew
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Generate all formulae:
|
|
27
|
+
|
|
28
|
+
```shell
|
|
29
|
+
gembrew build
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Generate or check one formula:
|
|
33
|
+
|
|
34
|
+
```shell
|
|
35
|
+
gembrew build <%= gem_name || 'FORMULA' %>
|
|
36
|
+
gembrew check <%= gem_name || 'FORMULA' %>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Check every formula:
|
|
40
|
+
|
|
41
|
+
```shell
|
|
42
|
+
gembrew check
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Add another Ruby gem:
|
|
46
|
+
|
|
47
|
+
```shell
|
|
48
|
+
gembrew add another-gem
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Open an interactive Homebrew environment:
|
|
52
|
+
|
|
53
|
+
```shell
|
|
54
|
+
gembrew shell
|
|
55
|
+
```
|
data/lib/gembrew/version.rb
CHANGED
data/lib/gembrew.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
require 'gembrew/archive_store'
|
|
2
|
+
require 'gembrew/adder'
|
|
2
3
|
require 'gembrew/config'
|
|
3
4
|
require 'gembrew/docker_check'
|
|
4
5
|
require 'gembrew/docker_shell'
|
|
6
|
+
require 'gembrew/docker_runner'
|
|
5
7
|
require 'gembrew/error'
|
|
6
8
|
require 'gembrew/generator'
|
|
7
9
|
require 'gembrew/initializer'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gembrew
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Danny Ben Shitrit
|
|
@@ -63,14 +63,17 @@ files:
|
|
|
63
63
|
- README.md
|
|
64
64
|
- bin/gembrew
|
|
65
65
|
- lib/gembrew.rb
|
|
66
|
+
- lib/gembrew/adder.rb
|
|
66
67
|
- lib/gembrew/archive_store.rb
|
|
67
68
|
- lib/gembrew/cli.rb
|
|
69
|
+
- lib/gembrew/commands/add.rb
|
|
68
70
|
- lib/gembrew/commands/build.rb
|
|
69
71
|
- lib/gembrew/commands/check.rb
|
|
70
72
|
- lib/gembrew/commands/init.rb
|
|
71
73
|
- lib/gembrew/commands/shell.rb
|
|
72
74
|
- lib/gembrew/config.rb
|
|
73
75
|
- lib/gembrew/docker_check.rb
|
|
76
|
+
- lib/gembrew/docker_runner.rb
|
|
74
77
|
- lib/gembrew/docker_shell.rb
|
|
75
78
|
- lib/gembrew/error.rb
|
|
76
79
|
- lib/gembrew/generator.rb
|
|
@@ -78,7 +81,7 @@ files:
|
|
|
78
81
|
- lib/gembrew/renderer.rb
|
|
79
82
|
- lib/gembrew/reporter.rb
|
|
80
83
|
- lib/gembrew/resolver.rb
|
|
81
|
-
- lib/gembrew/templates/
|
|
84
|
+
- lib/gembrew/templates/README.md.erb
|
|
82
85
|
- lib/gembrew/templates/formula.rb.erb
|
|
83
86
|
- lib/gembrew/templates/gembrew.yml.erb
|
|
84
87
|
- lib/gembrew/version.rb
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
services:
|
|
2
|
-
brew: &base
|
|
3
|
-
image: homebrew/brew:main
|
|
4
|
-
working_dir: /work
|
|
5
|
-
environment:
|
|
6
|
-
HOMEBREW_NO_AUTO_UPDATE: "1"
|
|
7
|
-
HOMEBREW_NO_INSTALL_CLEANUP: "1"
|
|
8
|
-
HOMEBREW_NO_INSTALL_FROM_API: "1"
|
|
9
|
-
GEMBREW_GEM: <%= gem_name %>
|
|
10
|
-
PS1: "\n\nbrew $ "
|
|
11
|
-
volumes:
|
|
12
|
-
- ..:/work
|
|
13
|
-
- ..:/home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/gembrew/homebrew-tap
|
|
14
|
-
command: ["bash", "--norc"]
|
|
15
|
-
stdin_open: true
|
|
16
|
-
tty: true
|
|
17
|
-
|
|
18
|
-
check:
|
|
19
|
-
<<: *base
|
|
20
|
-
command:
|
|
21
|
-
- bash
|
|
22
|
-
- -euc
|
|
23
|
-
- |
|
|
24
|
-
brew style "$${GEMBREW_GEM}"
|
|
25
|
-
brew audit --new --online "$${GEMBREW_GEM}"
|
|
26
|
-
brew install --build-from-source "$${GEMBREW_GEM}"
|
|
27
|
-
brew test "$${GEMBREW_GEM}"
|
|
28
|
-
stdin_open: false
|
|
29
|
-
tty: false
|