wayfarer 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yaml +25 -0
- data/.github/workflows/release.yaml +29 -0
- data/.github/workflows/tests.yaml +30 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +5 -0
- data/.vale.ini +5 -0
- data/.yardopts +1 -3
- data/Dockerfile +5 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +107 -102
- data/Rakefile +5 -56
- data/bin/wayfarer +1 -1
- data/docker-compose.yml +20 -9
- data/docs/cookbook/consent_screen.md +2 -2
- data/docs/cookbook/executing_javascript.md +3 -3
- data/docs/cookbook/navigation.md +12 -12
- data/docs/cookbook/querying_html.md +3 -3
- data/docs/cookbook/screenshots.md +2 -2
- data/docs/cookbook/user_agent.md +1 -1
- data/docs/design.md +36 -0
- data/docs/guides/callbacks.md +24 -126
- data/docs/guides/configuration.md +8 -8
- data/docs/guides/handlers.md +60 -0
- data/docs/guides/index.md +1 -0
- data/docs/guides/jobs/error_handling.md +40 -0
- data/docs/guides/jobs.md +99 -31
- data/docs/guides/navigation.md +1 -1
- data/docs/guides/networking/capybara.md +13 -22
- data/docs/guides/networking/custom_adapters.md +82 -41
- data/docs/guides/networking/ferrum.md +4 -4
- data/docs/guides/networking/http.md +9 -13
- data/docs/guides/networking/selenium.md +10 -11
- data/docs/guides/pages.md +76 -10
- data/docs/guides/redis.md +10 -0
- data/docs/guides/routing.md +74 -0
- data/docs/guides/tasks.md +33 -9
- data/docs/guides/tutorial.md +60 -0
- data/docs/guides/user_agents.md +113 -0
- data/docs/index.md +17 -40
- data/docs/reference/cli.md +35 -25
- data/docs/reference/configuration.md +36 -0
- data/lib/wayfarer/base.rb +124 -46
- data/lib/wayfarer/batch_completion.rb +56 -0
- data/lib/wayfarer/callbacks.rb +22 -48
- data/lib/wayfarer/cli/route_printer.rb +71 -57
- data/lib/wayfarer/cli.rb +121 -0
- data/lib/wayfarer/gc.rb +13 -6
- data/lib/wayfarer/handler.rb +15 -7
- data/lib/wayfarer/logging.rb +38 -0
- data/lib/wayfarer/middleware/base.rb +2 -0
- data/lib/wayfarer/middleware/batch_completion.rb +19 -0
- data/lib/wayfarer/middleware/content_type.rb +54 -0
- data/lib/wayfarer/middleware/controller.rb +19 -15
- data/lib/wayfarer/middleware/dedup.rb +16 -13
- data/lib/wayfarer/middleware/dispatch.rb +12 -4
- data/lib/wayfarer/middleware/normalize.rb +12 -11
- data/lib/wayfarer/middleware/redis.rb +15 -0
- data/lib/wayfarer/middleware/router.rb +33 -35
- data/lib/wayfarer/middleware/stage.rb +5 -5
- data/lib/wayfarer/middleware/uri_parser.rb +30 -0
- data/lib/wayfarer/middleware/user_agent.rb +49 -0
- data/lib/wayfarer/networking/capybara.rb +1 -1
- data/lib/wayfarer/networking/context.rb +2 -2
- data/lib/wayfarer/networking/ferrum.rb +2 -2
- data/lib/wayfarer/networking/follow.rb +12 -6
- data/lib/wayfarer/networking/http.rb +1 -1
- data/lib/wayfarer/networking/pool.rb +17 -12
- data/lib/wayfarer/networking/selenium.rb +3 -3
- data/lib/wayfarer/networking/strategy.rb +2 -2
- data/lib/wayfarer/page.rb +36 -14
- data/lib/wayfarer/parsing/xml.rb +6 -6
- data/lib/wayfarer/parsing.rb +24 -0
- data/lib/wayfarer/redis/barrier.rb +13 -21
- data/lib/wayfarer/redis/counter.rb +19 -9
- data/lib/wayfarer/redis/pool.rb +1 -1
- data/lib/wayfarer/redis/resettable.rb +19 -0
- data/lib/wayfarer/routing/dsl.rb +1 -0
- data/lib/wayfarer/routing/matchers/path.rb +4 -2
- data/lib/wayfarer/routing/root_route.rb +5 -1
- data/lib/wayfarer/routing/route.rb +4 -14
- data/lib/wayfarer/stringify.rb +22 -30
- data/lib/wayfarer/task.rb +12 -18
- data/lib/wayfarer.rb +28 -1
- data/mkdocs.yml +52 -7
- data/rake/docs.rake +26 -0
- data/rake/lint.rake +105 -0
- data/rake/release.rake +29 -0
- data/rake/tests.rake +28 -0
- data/requirements.txt +1 -1
- data/spec/base_spec.rb +140 -160
- data/spec/batch_completion_spec.rb +104 -0
- data/spec/cli/job_spec.rb +19 -23
- data/spec/cli/routing_spec.rb +101 -0
- data/spec/cli/version_spec.rb +1 -1
- data/spec/factories/task.rb +7 -1
- data/spec/fixtures/dummy_job.rb +5 -3
- data/spec/gc_spec.rb +8 -50
- data/spec/handler_spec.rb +1 -1
- data/spec/integration/callbacks_spec.rb +157 -45
- data/spec/integration/content_type_spec.rb +145 -0
- data/spec/integration/gc_spec.rb +44 -0
- data/spec/integration/handler_spec.rb +66 -0
- data/spec/integration/page_spec.rb +44 -29
- data/spec/integration/params_spec.rb +33 -25
- data/spec/integration/parsing_spec.rb +125 -0
- data/spec/integration/routing_spec.rb +18 -0
- data/spec/integration/stage_spec.rb +27 -20
- data/spec/middleware/batch_completion_spec.rb +34 -0
- data/spec/middleware/chain_spec.rb +8 -8
- data/spec/middleware/content_type_spec.rb +86 -0
- data/spec/middleware/controller_spec.rb +5 -5
- data/spec/middleware/dedup_spec.rb +38 -55
- data/spec/middleware/dispatch_spec.rb +23 -7
- data/spec/middleware/normalize_spec.rb +44 -13
- data/spec/middleware/router_spec.rb +29 -30
- data/spec/middleware/stage_spec.rb +8 -8
- data/spec/middleware/uri_parser_spec.rb +53 -0
- data/spec/middleware/{fetch_spec.rb → user_agent_spec.rb} +28 -27
- data/spec/networking/context_spec.rb +1 -1
- data/spec/networking/follow_spec.rb +2 -2
- data/spec/networking/pool_spec.rb +5 -5
- data/spec/networking/strategy.rb +2 -2
- data/spec/page_spec.rb +42 -20
- data/spec/parsing/xml_spec.rb +11 -12
- data/spec/redis/barrier_spec.rb +8 -48
- data/spec/redis/counter_spec.rb +13 -1
- data/spec/redis/pool_spec.rb +1 -1
- data/spec/spec_helpers.rb +27 -16
- data/spec/support/test_app.rb +8 -0
- data/spec/task_spec.rb +3 -24
- data/spec/wayfarer_spec.rb +1 -1
- data/wayfarer.gemspec +4 -3
- metadata +61 -51
- data/.github/workflows/ci.yaml +0 -32
- data/docs/guides/error_handling.md +0 -53
- data/docs/guides/networking.md +0 -94
- data/docs/guides/performance.md +0 -130
- data/docs/guides/reliability.md +0 -41
- data/docs/guides/routing/steering.md +0 -30
- data/docs/reference/api/base.md +0 -48
- data/docs/reference/configuration_keys.md +0 -43
- data/docs/reference/environment_variables.md +0 -83
- data/lib/wayfarer/cli/base.rb +0 -45
- data/lib/wayfarer/cli/generate.rb +0 -17
- data/lib/wayfarer/cli/job.rb +0 -56
- data/lib/wayfarer/cli/route.rb +0 -29
- data/lib/wayfarer/cli/runner.rb +0 -34
- data/lib/wayfarer/cli/templates/Gemfile.tt +0 -5
- data/lib/wayfarer/cli/templates/job.rb.tt +0 -10
- data/lib/wayfarer/config/capybara.rb +0 -10
- data/lib/wayfarer/config/ferrum.rb +0 -11
- data/lib/wayfarer/config/networking.rb +0 -29
- data/lib/wayfarer/config/redis.rb +0 -14
- data/lib/wayfarer/config/root.rb +0 -11
- data/lib/wayfarer/config/selenium.rb +0 -21
- data/lib/wayfarer/config/strconv.rb +0 -45
- data/lib/wayfarer/config/struct.rb +0 -72
- data/lib/wayfarer/middleware/fetch.rb +0 -56
- data/lib/wayfarer/redis/connection.rb +0 -13
- data/lib/wayfarer/redis/version.rb +0 -19
- data/lib/wayfarer/routing/router.rb +0 -28
- data/spec/callbacks_spec.rb +0 -102
- data/spec/cli/generate_spec.rb +0 -39
- data/spec/config/capybara_spec.rb +0 -18
- data/spec/config/ferrum_spec.rb +0 -24
- data/spec/config/networking_spec.rb +0 -73
- data/spec/config/redis_spec.rb +0 -32
- data/spec/config/root_spec.rb +0 -31
- data/spec/config/selenium_spec.rb +0 -56
- data/spec/config/strconv_spec.rb +0 -58
- data/spec/config/struct_spec.rb +0 -66
- data/spec/integration/steering_spec.rb +0 -57
- data/spec/redis/version_spec.rb +0 -13
- data/spec/routing/router_spec.rb +0 -24
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wayfarer
|
4
|
+
module Redis
|
5
|
+
module Resettable
|
6
|
+
def reset!
|
7
|
+
redis_pool.with { |conn| conn.del(redis_key) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def redis_pool
|
11
|
+
raise NotImplementedError
|
12
|
+
end
|
13
|
+
|
14
|
+
def redis_key
|
15
|
+
raise NotImplementedError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/wayfarer/routing/dsl.rb
CHANGED
@@ -17,10 +17,12 @@ module Wayfarer
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def match(url)
|
20
|
-
|
21
|
-
|
20
|
+
# TODO: Ditch this and add a parameter to the path DSL#path
|
21
|
+
#
|
22
22
|
# If the route's branch contains other path matchers in child routes,
|
23
23
|
# match the beginning of the path (peeking), instead of the whole path.
|
24
|
+
route.accept(self)
|
25
|
+
|
24
26
|
!!(if peeking
|
25
27
|
matcher.peek(url.path)
|
26
28
|
else
|
@@ -5,6 +5,7 @@ module Wayfarer
|
|
5
5
|
class Route
|
6
6
|
include DSL
|
7
7
|
include Stringify
|
8
|
+
extend Forwardable
|
8
9
|
|
9
10
|
attr_reader :children
|
10
11
|
|
@@ -15,8 +16,7 @@ module Wayfarer
|
|
15
16
|
|
16
17
|
stringify :matcher,
|
17
18
|
:action,
|
18
|
-
:path_offset
|
19
|
-
:children
|
19
|
+
:path_offset
|
20
20
|
|
21
21
|
def initialize(matcher = Matchers::Custom.new { children.any? }, path_offset = "/")
|
22
22
|
@matcher = matcher
|
@@ -24,24 +24,14 @@ module Wayfarer
|
|
24
24
|
@path_offset = path_offset
|
25
25
|
end
|
26
26
|
|
27
|
-
def match(url)
|
28
|
-
matcher.match(url)
|
29
|
-
end
|
30
|
-
|
31
|
-
def matches?(url)
|
32
|
-
invoke(url).is_a?(Result::Match)
|
33
|
-
end
|
34
|
-
|
35
|
-
def invoke(url)
|
36
|
-
PathFinder.result(self, url)
|
37
|
-
end
|
38
|
-
|
39
27
|
# Accepts a visitor for in-order traversal.
|
40
28
|
def accept(visitor)
|
41
29
|
return unless visitor.visit(self)
|
42
30
|
|
43
31
|
children.each { |child| child.accept(visitor) }
|
44
32
|
end
|
33
|
+
|
34
|
+
delegate match: :matcher
|
45
35
|
end
|
46
36
|
end
|
47
37
|
end
|
data/lib/wayfarer/stringify.rb
CHANGED
@@ -1,46 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# 346325
|
4
|
-
|
5
3
|
module Wayfarer
|
6
4
|
module Stringify
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
class_attribute :stringified_attributes,
|
9
|
+
default: [],
|
10
|
+
instance_accessor: false,
|
11
|
+
instance_predicate: false
|
12
|
+
|
13
|
+
alias_method :inspect, :to_s
|
15
14
|
end
|
16
15
|
|
17
|
-
|
16
|
+
class_methods do
|
18
17
|
def stringify(*variables)
|
19
18
|
stringified_attributes.concat(variables)
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
if self.class.stringified_attributes.any?
|
26
|
-
"#<#{class_name} #{attributes.join(', ')}>"
|
27
|
-
else
|
28
|
-
"#<#{class_name}>"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
alias inspect to_s
|
22
|
+
def to_s
|
23
|
+
class_name = self.class.name
|
33
24
|
|
34
|
-
|
35
|
-
self.class
|
36
|
-
|
25
|
+
if self.class.stringified_attributes.any?
|
26
|
+
attrs = self.class
|
27
|
+
.stringified_attributes
|
28
|
+
.map { |attr| [attr, public_send(attr)] }
|
29
|
+
.to_h
|
30
|
+
.map { |k, v| "#{k}=#{v.inspect}" }
|
31
|
+
.join(", ")
|
37
32
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
.map { |attr| [attr, public_send(attr)] }
|
42
|
-
.to_h
|
43
|
-
.map { |k, v| [k, "=", v.inspect].join }
|
33
|
+
"#<#{class_name} #{attrs}>"
|
34
|
+
else
|
35
|
+
"#<#{class_name}>"
|
44
36
|
end
|
45
37
|
end
|
46
38
|
end
|
data/lib/wayfarer/task.rb
CHANGED
@@ -1,36 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Wayfarer
|
4
|
+
# @!attribute [r] url
|
5
|
+
# @return [String] the URL to process
|
6
|
+
# @!attribute [r] batch
|
7
|
+
# @return [String] the batch the task belongs to
|
4
8
|
class Task
|
9
|
+
extend Forwardable
|
5
10
|
include Stringify
|
6
11
|
|
7
|
-
attr_reader :url,
|
8
|
-
:batch,
|
9
|
-
:metadata
|
12
|
+
attr_reader :url, :batch
|
10
13
|
|
11
|
-
stringify :url,
|
12
|
-
:batch
|
14
|
+
stringify :url, :batch
|
13
15
|
|
16
|
+
delegate %i([] []=) => :@ephemeral
|
17
|
+
|
18
|
+
# @!visibility private
|
14
19
|
def initialize(url, batch)
|
15
20
|
@url = url
|
16
21
|
@batch = batch
|
17
|
-
@
|
22
|
+
@ephemeral = {}
|
18
23
|
end
|
19
24
|
|
25
|
+
# @!visibility private
|
20
26
|
def ==(other)
|
21
27
|
[url, batch] == [other.url, other.batch]
|
22
28
|
end
|
23
|
-
|
24
|
-
def barrier
|
25
|
-
@barrier ||= Wayfarer::Redis::Barrier.new(batch)
|
26
|
-
end
|
27
|
-
|
28
|
-
def counter
|
29
|
-
@counter ||= Wayfarer::Redis::Counter.new(batch)
|
30
|
-
end
|
31
|
-
|
32
|
-
def gc
|
33
|
-
@gc ||= Wayfarer::GC.new(self)
|
34
|
-
end
|
35
29
|
end
|
36
30
|
end
|
data/lib/wayfarer.rb
CHANGED
@@ -42,7 +42,32 @@ module Wayfarer
|
|
42
42
|
STRING = [MAJOR, MINOR, TINY].join(".")
|
43
43
|
end
|
44
44
|
|
45
|
-
|
45
|
+
DEFAULT_CONFIG = {
|
46
|
+
redis: {
|
47
|
+
url: "redis://localhost:6379/0",
|
48
|
+
factory: ->(redis) { ::Redis.new(url: redis[:url]) }
|
49
|
+
},
|
50
|
+
network: {
|
51
|
+
agent: :http,
|
52
|
+
pool_size: 1,
|
53
|
+
pool_timeout: 10,
|
54
|
+
http_headers: {},
|
55
|
+
renew_on: []
|
56
|
+
},
|
57
|
+
capybara: {
|
58
|
+
driver: nil
|
59
|
+
},
|
60
|
+
ferrum: {
|
61
|
+
options: {}
|
62
|
+
},
|
63
|
+
selenium: {
|
64
|
+
driver: :chrome,
|
65
|
+
options: {},
|
66
|
+
client_timeout: 60
|
67
|
+
}
|
68
|
+
}.freeze
|
69
|
+
|
70
|
+
mattr_accessor :config, default: DEFAULT_CONFIG.clone
|
46
71
|
|
47
72
|
UserAgentTimeoutError = Class.new(StandardError) # TODO: Move to Networking namespace
|
48
73
|
end
|
@@ -50,3 +75,5 @@ end
|
|
50
75
|
loader.eager_load
|
51
76
|
|
52
77
|
ActiveJob::Serializers.serializers << Wayfarer::Serializer
|
78
|
+
|
79
|
+
Wayfarer::BatchCompletion.subscribe!
|
data/mkdocs.yml
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
repo_url: https://github.com/bauerd/wayfarer
|
2
2
|
edit_uri: edit/develop/docs/
|
3
|
-
repo_name:
|
3
|
+
repo_name: Code
|
4
4
|
site_name: Wayfarer
|
5
5
|
markdown_extensions:
|
6
6
|
- admonition
|
7
|
+
- attr_list
|
7
8
|
- meta
|
8
9
|
- def_list
|
9
10
|
- pymdownx.details
|
10
11
|
- pymdownx.highlight
|
11
|
-
- pymdownx.
|
12
|
+
- pymdownx.inlinehilite
|
13
|
+
- pymdownx.superfences:
|
14
|
+
custom_fences:
|
15
|
+
- name: mermaid
|
16
|
+
class: mermaid
|
17
|
+
format: !!python/name:pymdownx.superfences.fence_code_format
|
12
18
|
- pymdownx.critic
|
13
19
|
- pymdownx.caret
|
14
20
|
- pymdownx.mark
|
@@ -18,11 +24,15 @@ markdown_extensions:
|
|
18
24
|
custom_checkbox: true
|
19
25
|
|
20
26
|
theme:
|
27
|
+
icon:
|
28
|
+
logo: material/sign-direction
|
29
|
+
repo: fontawesome/brands/git
|
21
30
|
name: material
|
22
31
|
features:
|
23
32
|
- navigation.tabs
|
24
|
-
- navigation.sections
|
25
|
-
- navigation.expand
|
33
|
+
# - navigation.sections
|
34
|
+
# - navigation.expand
|
35
|
+
- navigation.indexes
|
26
36
|
font:
|
27
37
|
text: IBM Plex Sans
|
28
38
|
code: IBM Plex Sans Mono
|
@@ -41,7 +51,42 @@ theme:
|
|
41
51
|
toggle:
|
42
52
|
icon: material/lightbulb
|
43
53
|
name: Switch to light mode
|
44
|
-
icon:
|
45
|
-
repo: fontawesome/brands/git
|
46
|
-
|
47
54
|
|
55
|
+
nav:
|
56
|
+
- Home: index.md
|
57
|
+
- Guides:
|
58
|
+
- Tutorial: guides/tutorial.md
|
59
|
+
- Jobs:
|
60
|
+
- Overview: guides/jobs.md
|
61
|
+
- Error handling: guides/jobs/error_handling.md
|
62
|
+
- Tasks: guides/tasks.md
|
63
|
+
- Pages: guides/pages.md
|
64
|
+
- Routing:
|
65
|
+
- Overview: guides/routing.md
|
66
|
+
- Matchers:
|
67
|
+
- URL: todo
|
68
|
+
- Host: todo
|
69
|
+
- Path: todo
|
70
|
+
- Query: todo
|
71
|
+
- Custom matchers: todo
|
72
|
+
- Callbacks: guides/callbacks.md
|
73
|
+
- Handlers: guides/handlers.md
|
74
|
+
- Networking:
|
75
|
+
- Introduction: guides/user_agents.md
|
76
|
+
- User agent API: guides/networking/custom_adapters.md
|
77
|
+
- Built-in user agents:
|
78
|
+
- Plain HTTP: guides/networking/http.md
|
79
|
+
- Ferrum: guides/networking/ferrum.md
|
80
|
+
- Selenium: guides/networking/selenium.md
|
81
|
+
- Capybara: guides/networking/capybara.md
|
82
|
+
- Redis: guides/redis.md
|
83
|
+
- Design decisions: design.md
|
84
|
+
- Reference:
|
85
|
+
- Configuration: reference/configuration.md
|
86
|
+
- Command-line interface: reference/cli.md
|
87
|
+
- Cookbook:
|
88
|
+
- Browser navigation: cookbook/navigation.md
|
89
|
+
- Executing JavaScript: cookbook/executing_javascript.md
|
90
|
+
- Screenhots: cookbook/screenshots.md
|
91
|
+
- Setting the User-Agent: cookbook/user_agent.md
|
92
|
+
- API documentation: "https://www.rubydoc.info"
|
data/rake/docs.rake
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yard"
|
4
|
+
|
5
|
+
namespace :yard do
|
6
|
+
desc "Generate documentation"
|
7
|
+
YARD::Rake::YardocTask.new(:generate) do |t|
|
8
|
+
require_relative "../lib/wayfarer"
|
9
|
+
|
10
|
+
t.options = %w[--readme docs/index.md --no-private --markup markdown]
|
11
|
+
t.files = [
|
12
|
+
Wayfarer::Base,
|
13
|
+
Wayfarer::Task,
|
14
|
+
Wayfarer::Page,
|
15
|
+
Wayfarer::Handler,
|
16
|
+
Wayfarer::Routing::DSL,
|
17
|
+
Wayfarer::Parsing
|
18
|
+
].freeze.map { |klass| Object.const_source_location(klass.name).first }
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Regenerate documentation on change"
|
22
|
+
task :watch do
|
23
|
+
# The output of `yard server` differs for some reason
|
24
|
+
sh "rerun --wait 0.5 --dir lib bundle exec rake yard:generate"
|
25
|
+
end
|
26
|
+
end
|
data/rake/lint.rake
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "open-uri"
|
4
|
+
require "fileutils"
|
5
|
+
require "rubygems/package"
|
6
|
+
require "zlib"
|
7
|
+
require "zip"
|
8
|
+
require "rubocop/rake_task"
|
9
|
+
require "net/http"
|
10
|
+
require "uri"
|
11
|
+
|
12
|
+
VALE_URL_ROOT = "https://github.com/errata-ai"
|
13
|
+
VALE_VERSION = "2.15.4"
|
14
|
+
VALE_STYLE_GUIDE_VERSION = "v0.3.3"
|
15
|
+
VALE_PREFIX = File.expand_path(File.join(".github", "bin"))
|
16
|
+
VALE_STYLE_GUIDE_PREFIX = File.expand_path(File.join(".github", "share"))
|
17
|
+
|
18
|
+
namespace :lint do
|
19
|
+
RuboCop::RakeTask.new do |task|
|
20
|
+
task.formatters = %w[simple]
|
21
|
+
end
|
22
|
+
|
23
|
+
vale_command = File.join(VALE_PREFIX, "vale")
|
24
|
+
style_guide_directory = File.join(VALE_STYLE_GUIDE_PREFIX, "vale")
|
25
|
+
|
26
|
+
desc "Lint documentation"
|
27
|
+
task vale: [:"lint:vale:clean", vale_command, style_guide_directory] do
|
28
|
+
sh "#{vale_command} docs/**/*.md"
|
29
|
+
end
|
30
|
+
|
31
|
+
namespace :vale do
|
32
|
+
directory VALE_PREFIX
|
33
|
+
|
34
|
+
desc "Install Vale to #{vale_command}"
|
35
|
+
file vale_command => VALE_PREFIX do
|
36
|
+
unless (local_command = `which vale`.strip).empty?
|
37
|
+
next File.symlink(local_command, vale_command)
|
38
|
+
end
|
39
|
+
|
40
|
+
filename = "vale_#{VALE_VERSION}_Linux_64-bit.tar.gz"
|
41
|
+
url = File.join(VALE_URL_ROOT, "/vale/releases/download/v#{VALE_VERSION}/#{filename}")
|
42
|
+
|
43
|
+
extract_tar_gz(url, vale_command)
|
44
|
+
|
45
|
+
FileUtils.chmod("+x", vale_command)
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Deletes Vale"
|
49
|
+
task clean: :"lint:vale:style_guide:clean" do
|
50
|
+
File.delete(vale_command) if File.exist?(vale_command)
|
51
|
+
end
|
52
|
+
|
53
|
+
namespace :style_guide do
|
54
|
+
directory VALE_STYLE_GUIDE_PREFIX
|
55
|
+
|
56
|
+
desc "Retrieve Vale Google style guide #{VALE_STYLE_GUIDE_VERSION}"
|
57
|
+
directory style_guide_directory => VALE_STYLE_GUIDE_PREFIX do
|
58
|
+
FileUtils.mkdir_p(style_guide_directory)
|
59
|
+
url = "https://github.com/errata-ai/Google/releases/download/#{VALE_STYLE_GUIDE_VERSION}/Google.zip"
|
60
|
+
extract_zip(url, style_guide_directory)
|
61
|
+
end
|
62
|
+
|
63
|
+
desc "Deletes the Vale Google style guide"
|
64
|
+
task :clean do
|
65
|
+
FileUtils.rm_rf([style_guide_directory])
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def extract_zip(url, destination)
|
71
|
+
content = URI.open(url)
|
72
|
+
|
73
|
+
Zip::File.open_buffer(content) do |zip|
|
74
|
+
zip.each do |entry|
|
75
|
+
path = File.join(destination, entry.name)
|
76
|
+
|
77
|
+
if entry.directory?
|
78
|
+
FileUtils.mkdir_p(path)
|
79
|
+
else
|
80
|
+
entry.extract(path)
|
81
|
+
File.chmod(0o755, path)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def extract_tar_gz(url, destination)
|
91
|
+
URI.open(url) do |file|
|
92
|
+
Zlib::GzipReader.open(file) do |gz|
|
93
|
+
Gem::Package::TarReader.new(gz) do |tar|
|
94
|
+
tar.each do |entry|
|
95
|
+
next unless entry.file?
|
96
|
+
|
97
|
+
binary = entry.read
|
98
|
+
File.write(destination, binary)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/rake/release.rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "fileutils"
|
4
|
+
require "yaml"
|
5
|
+
require "bundler/gem_tasks"
|
6
|
+
|
7
|
+
namespace :release do
|
8
|
+
task :guard_versions do
|
9
|
+
gem_spec = Gem::Specification.load("wayfarer.gemspec")
|
10
|
+
gem_version = gem_spec.version.version
|
11
|
+
lib_version = Wayfarer::VERSION::STRING
|
12
|
+
|
13
|
+
raise "Gem version #{gem_version} deviates from library version #{lib_version}" unless gem_version == lib_version
|
14
|
+
end
|
15
|
+
|
16
|
+
# TODO: `GEM_HOST_API_KEY` is only supported for RubyGems 3+
|
17
|
+
task :write_credentials do
|
18
|
+
raise "RubyGems 3+ supports `GEM_HOST_API_KEY`" unless RUBY_VERSION.split(".").first.to_i == 2
|
19
|
+
|
20
|
+
key = ENV.fetch("GEM_HOST_API_KEY") { raise "`GEM_HOST_API_KEY` is unset" }
|
21
|
+
contents = YAML.dump(rubygems_api_key: "Basic #{key}")
|
22
|
+
gem_path = File.join(Dir.home, ".gem")
|
23
|
+
FileUtils.mkdir_p(gem_path)
|
24
|
+
File.write(File.join(gem_path, "credentials"), contents)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::Task[:release].enhance(%i[release:guard_versions])
|
29
|
+
Rake::Task[:"release:rubygem_push"].enhance(%i[release:write_credentials])
|
data/rake/tests.rake
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
|
5
|
+
desc "Run all tests"
|
6
|
+
RSpec::Core::RakeTask.new(:test)
|
7
|
+
|
8
|
+
namespace :test do
|
9
|
+
desc "Run only isolated tests"
|
10
|
+
RSpec::Core::RakeTask.new :isolated do |task|
|
11
|
+
task.rspec_opts = ["--tag ~selenium --tag ~ferrum --tag ~cli"]
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Run only Selenium tests"
|
15
|
+
RSpec::Core::RakeTask.new :selenium do |task|
|
16
|
+
task.rspec_opts = ["--tag selenium"]
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Run only Ferrum tests"
|
20
|
+
RSpec::Core::RakeTask.new :ferrum do |task|
|
21
|
+
task.rspec_opts = ["--tag ferrum"]
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Run only CLI tests"
|
25
|
+
RSpec::Core::RakeTask.new :cli do |task|
|
26
|
+
task.rspec_opts = ["--tag cli"]
|
27
|
+
end
|
28
|
+
end
|
data/requirements.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
mkdocs-material ==
|
1
|
+
mkdocs-material == 9.5.9
|