bake-test-external 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47a071dbbd5823bf15e24a29988176668f249f0a5449e527ae7ea6353e1e8a93
4
- data.tar.gz: d4fc771066257b210e74233c5456cacea65707f4fe5708685400065cd09bc67f
3
+ metadata.gz: a468b46f1192614e834259be98b4938d9ee453233a4e5f30e80b54690e0a0605
4
+ data.tar.gz: 193a7447f7e4542a26607c04513f0de72a2897d61a15424de4a6c162e8c12c33
5
5
  SHA512:
6
- metadata.gz: ab045efb381fcd9e61f7d00eeb056e634cfd42292122104154908959dc39dd0dd74e27350a550032991deae542cabc7a9975eaa2083e25cf4cf8ba82b105fc14
7
- data.tar.gz: e1d4e308a5e717dd1fd95b58b25dc60ab4606dcb399d1f2d5928f03603d22f1770711bb6c4c8d2a7fc6c7c809e091b959425068aacce6cc582e94b34de1845aa
6
+ metadata.gz: 5f3c50ff877fcfaae28beecedabee21fbec98d4a695353b5904c568d044497fb2196a7b33e8342459586a7ab93a4ac69037d8199c172813d63e088f19d2eeddc
7
+ data.tar.gz: 9183e958d2958c800cc6fa97bb73b78d0b00ecbb01125723ac1762954de467f6eaf086ce2f4de4faad90de250bfeeb8a408461a999babd5147c2fa6d11bd3e9d
checksums.yaml.gz.sig CHANGED
Binary file
@@ -5,144 +5,52 @@
5
5
  # Copyright, 2022, by Akshay Birajdar.
6
6
  # Copyright, 2022, by Hiroaki Osawa.
7
7
 
8
+ def initialize(context)
9
+ super
10
+
11
+ require 'bake/test/external'
12
+ require 'bundler'
13
+ require 'yaml'
14
+ end
15
+
8
16
  DEFAULT_EXTERNALS_PATH = 'config/external.yaml'
9
- DEFAULT_COMMAND = "bake test"
10
17
 
11
18
  # Run external tests.
12
19
  # @parameter gemspec [String] The input gemspec path.
13
- def external(input: nil, gemspec: self.find_gemspec)
14
- require 'bundler'
15
- require 'yaml'
20
+ def external(input: nil, gemspec: nil)
21
+ input ||= default_input
16
22
 
17
- if input.nil? and File.exist?(DEFAULT_EXTERNALS_PATH)
18
- # symbolize_names is unsupported on Ruby 2.7
19
- input = YAML.load_file(DEFAULT_EXTERNALS_PATH) # , symbolize_names: true)
20
- end
23
+ controller = Bake::Test::External::Controller.new
24
+ gemspec ||= controller.find_gemspec
21
25
 
22
26
  input&.each do |key, config|
23
27
  config = config.transform_keys(&:to_sym)
24
28
  config[:env] ||= {}
25
29
 
26
30
  Bundler.with_unbundled_env do
27
- clone_and_test(gemspec.name, key, config)
31
+ controller.clone_and_test(gemspec.name, key, config)
28
32
  end
29
33
  end
30
34
  end
31
35
 
32
- private
33
-
34
- def find_gemspec(glob = "*.gemspec")
35
- paths = Dir.glob(glob, base: @root).sort
36
-
37
- if paths.size > 1
38
- raise "Multiple gemspecs found: #{paths}, please specify one!"
39
- end
40
-
41
- if path = paths.first
42
- return ::Gem::Specification.load(path)
43
- end
44
- end
45
-
46
- def clone_and_test(name, key, config)
47
- path = clone_repository(name, key, config)
36
+ def clone(input: nil, gemspec: nil)
37
+ input ||= default_input
48
38
 
49
- test_repository(path, config) or abort("External tests #{key} failed!")
50
- end
51
-
52
- def clone_repository(name, key, config)
53
- require 'fileutils'
39
+ controller = Bake::Test::External::Controller.new
40
+ gemspec ||= controller.find_gemspec
54
41
 
55
- url = config[:url]
56
-
57
- path = "external/#{key}"
58
-
59
- unless File.directory?(path)
60
- FileUtils.mkdir_p path
61
- command = ["git", "clone", "--depth", "1"]
62
-
63
- if branch = config[:branch]
64
- command << "--branch" << branch
65
- end
66
-
67
- if tag = config[:tag]
68
- command << "--tag" << tag
69
- end
70
-
71
- command << url << path
72
- system(config[:env], *command)
73
-
74
- # I tried using `bundle config --local local.async ../` but it simply doesn't work.
75
- # system("bundle", "config", "--local", "local.async", __dir__, chdir: path)
76
-
77
- gemfile_path = self.gemfile_path(path, config)
42
+ input&.each do |key, config|
43
+ config = config.transform_keys(&:to_sym)
44
+ config[:env] ||= {}
78
45
 
79
- File.open(gemfile_path, 'r+') do |file|
80
- pattern = /gem.*?['"]#{name}['"]/
81
- lines = file.grep_v(pattern)
82
-
83
- file.seek(0)
84
- file.truncate(0)
85
- file.puts(lines)
86
- file.puts nil, "# Added by external testing:"
87
- file.puts("gem #{name.to_s.dump}, path: '../../'")
88
-
89
- config[:extra]&.each do |line|
90
- file.puts(line)
91
- end
92
- end
93
-
94
- system(config[:env], "bundle", "install", chdir: path)
95
- end
96
-
97
- return path
98
- end
99
-
100
- def test_repository(path, config)
101
- command = config.fetch(:command, DEFAULT_COMMAND)
102
-
103
- Array(command).each do |line|
104
- system(config[:env], *line, chdir: path)
46
+ controller.clone_repository(gemspec.name, key, config)
105
47
  end
106
48
  end
107
49
 
108
- GEMFILE_NAMES = ["Gemfile", "gems.rb"]
109
-
110
- def resolve_gemfile_path(root, config)
111
- if config_path = config[:gemfile]
112
- path = File.join(root, config_path)
113
-
114
- unless File.exist?(path)
115
- raise ArgumentError, "Specified gemfile path does not exist: #{config_path.inspect}!"
116
- end
117
-
118
- # We consider this to be a custom gemfile path:
119
- return false, path
120
- end
121
-
122
- GEMFILE_NAMES.each do |name|
123
- path = File.join(root, name)
124
-
125
- if File.exist?(path)
126
- # We consider this to be a default gemfile path:
127
- return true, path
128
- end
129
- end
130
-
131
- raise ArgumentError, "Could not find gem file in #{root.inspect}!"
132
- end
50
+ private
133
51
 
134
- def gemfile_path(root, config)
135
- config.fetch(:cached_gemfile_path) do
136
- root = File.expand_path(root, @root)
137
- default, path = self.resolve_gemfile_path(root, config)
138
-
139
- config[:cached_gemfile_path] = path
140
-
141
- # Custom gemfile paths should be set explicitly:
142
- unless default
143
- config[:env]['BUNDLE_GEMFILE'] = path
144
- end
145
-
146
- return path
52
+ def default_input
53
+ if File.exist?(DEFAULT_EXTERNALS_PATH)
54
+ YAML.load_file(DEFAULT_EXTERNALS_PATH)
147
55
  end
148
56
  end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2022, by Samuel Williams.
5
+
6
+ require 'fileutils'
7
+ require 'pathname'
8
+
9
+ module Bake
10
+ module Test
11
+ module External
12
+ class Controller
13
+ DEFAULT_COMMAND = "bake test"
14
+
15
+ def initialize(root = nil)
16
+ @root = Pathname.new(root || Dir.pwd)
17
+ end
18
+
19
+ def find_gemspec(pattern = "*.gemspec")
20
+ paths = @root.glob(pattern)
21
+
22
+ if paths.size > 1
23
+ raise "Multiple gemspecs found: #{paths}, please specify one!"
24
+ end
25
+
26
+ if path = paths.first
27
+ return ::Gem::Specification.load(path.to_s)
28
+ end
29
+ end
30
+
31
+ def clone_and_test(name, key, config)
32
+ path = clone_repository(name, key, config)
33
+
34
+ test_repository(path, config) or abort("External tests #{key} failed!")
35
+ end
36
+
37
+ def clone_repository(name, key, config)
38
+ url = config[:url]
39
+
40
+ path = File.join(@root, "external", key)
41
+
42
+ unless File.directory?(path)
43
+ FileUtils.mkdir_p path
44
+ command = ["git", "clone", "--depth", "1"]
45
+
46
+ if branch = config[:branch]
47
+ command << "--branch" << branch
48
+ end
49
+
50
+ if tag = config[:tag]
51
+ command << "--tag" << tag
52
+ end
53
+
54
+ command << url << path
55
+ system(config[:env], *command)
56
+
57
+ # I tried using `bundle config --local local.async ../` but it simply doesn't work.
58
+ # system("bundle", "config", "--local", "local.async", __dir__, chdir: path)
59
+
60
+ gemfile_path = self.gemfile_path(path, config)
61
+ relative_root = @root.relative_path_from(gemfile_path.dirname)
62
+
63
+ File.open(gemfile_path, 'r+') do |file|
64
+ pattern = /gem.*?['"]#{name}['"]/
65
+ lines = file.grep_v(pattern)
66
+
67
+ file.seek(0)
68
+ file.truncate(0)
69
+ file.puts(lines)
70
+ file.puts nil, "# Added by external testing:"
71
+ file.puts("gem #{name.to_s.dump}, path: #{relative_root.to_s.dump}")
72
+
73
+ config[:extra]&.each do |line|
74
+ file.puts(line)
75
+ end
76
+ end
77
+
78
+ system(config[:env], "bundle", "install", chdir: path)
79
+ end
80
+
81
+ return path
82
+ end
83
+
84
+ def test_repository(path, config)
85
+ command = config.fetch(:command, DEFAULT_COMMAND)
86
+
87
+ Array(command).each do |line|
88
+ system(config[:env], *line, chdir: path)
89
+ end
90
+ end
91
+
92
+ GEMFILE_NAMES = ["Gemfile", "gems.rb"]
93
+
94
+ def resolve_gemfile_path(root, config)
95
+ if config_path = config[:gemfile]
96
+ path = File.join(root, config_path)
97
+
98
+ unless File.exist?(path)
99
+ raise ArgumentError, "Specified gemfile path does not exist: #{config_path.inspect}!"
100
+ end
101
+
102
+ # We consider this to be a custom gemfile path:
103
+ return false, path
104
+ end
105
+
106
+ GEMFILE_NAMES.each do |name|
107
+ path = File.join(root, name)
108
+
109
+ if File.exist?(path)
110
+ # We consider this to be a default gemfile path:
111
+ return true, path
112
+ end
113
+ end
114
+
115
+ raise ArgumentError, "Could not find gem file in #{root.inspect}!"
116
+ end
117
+
118
+ def gemfile_path(root, config)
119
+ config.fetch(:cached_gemfile_path) do
120
+ root = File.expand_path(root, @root)
121
+ default, path = self.resolve_gemfile_path(root, config)
122
+
123
+ # Custom gemfile paths should be set explicitly:
124
+ unless default
125
+ config[:env]['BUNDLE_GEMFILE'] = path
126
+ end
127
+
128
+ path = Pathname.new(path)
129
+
130
+ config[:cached_gemfile_path] = path
131
+
132
+ return path
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -6,7 +6,7 @@
6
6
  module Bake
7
7
  module Test
8
8
  module External
9
- VERSION = "0.4.0"
9
+ VERSION = "0.5.0"
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2022, by Samuel Williams.
5
+
6
+ require_relative 'external/version'
7
+ require_relative 'external/controller'
data/readme.md CHANGED
@@ -6,20 +6,9 @@ A gem for executing external (downstream) tests.
6
6
 
7
7
  ## Usage
8
8
 
9
- Add a file `config/external.yaml` to your project, and add entries like:
9
+ Please see the [project documentation](https://ioquatix.github.io/bake-test-external/) for more details.
10
10
 
11
- ``` yaml
12
- bake:
13
- url: https://github.com/ioquatix/bake.git
14
- command: bundle exec rspec
15
- # branch: optional-branch-name
16
- ```
17
-
18
- ``` bash
19
- $ bake test:external
20
- ```
21
-
22
- It will clone the listed repositories, inject your current gem into the fetched gemfile, and run the given command. This has the effect of running their test suite with your latest code. You can use this as part of your test suite to receive feedback that a downstream dependent codebase is okay or broken because of a change you've made.
11
+ - [Getting Started](https://ioquatix.github.io/bake-test-external/guides/getting-started/index) - This guide will help you get started with `bake-test-external` and show you how to use it in your project.
23
12
 
24
13
  ## Contributing
25
14
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bake-test-external
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -39,7 +39,7 @@ cert_chain:
39
39
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
40
40
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
41
41
  -----END CERTIFICATE-----
42
- date: 2024-06-13 00:00:00.000000000 Z
42
+ date: 2024-06-17 00:00:00.000000000 Z
43
43
  dependencies:
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: bake
@@ -62,6 +62,8 @@ extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
64
  - bake/test/external.rb
65
+ - lib/bake/test/external.rb
66
+ - lib/bake/test/external/controller.rb
65
67
  - lib/bake/test/external/version.rb
66
68
  - license.md
67
69
  - readme.md
@@ -69,6 +71,7 @@ homepage: https://github.com/ioquatix/bake-test-external
69
71
  licenses:
70
72
  - MIT
71
73
  metadata:
74
+ documentation_uri: https://ioquatix.github.io/bake-test-external/
72
75
  funding_uri: https://github.com/sponsors/ioquatix/
73
76
  source_code_uri: https://github.com/ioquatix/bake-test-external.git
74
77
  post_install_message:
metadata.gz.sig CHANGED
Binary file