waylon 0.2.0 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/exe/waylon CHANGED
@@ -7,7 +7,291 @@ logger = Logger.new($stdout)
7
7
  logger.level = Logger::INFO
8
8
  action = ARGV[0]
9
9
 
10
+ def validate_project_name(name)
11
+ name.downcase =~ /^[a-z][a-z0-9_-]+$/
12
+ end
13
+
14
+ def rubocop_template
15
+ <<~TEMPLATE
16
+ AllCops:
17
+ TargetRubyVersion: 3.1
18
+ NewCops: enable
19
+
20
+ Style/StringLiterals:
21
+ Enabled: true
22
+ EnforcedStyle: double_quotes
23
+
24
+ Style/StringLiteralsInInterpolation:
25
+ Enabled: true
26
+ EnforcedStyle: double_quotes
27
+
28
+ Layout/LineLength:
29
+ Max: 120
30
+ TEMPLATE
31
+ end
32
+
33
+ def ruby_version_template
34
+ "3.1.2\n"
35
+ end
36
+
37
+ def dockerfile_template
38
+ <<~TEMPLATE
39
+ FROM ruby:3.1
40
+
41
+ RUN mkdir -p /app
42
+
43
+ COPY config.ru /app/
44
+ COPY Gemfile.lock /app/
45
+ COPY plugins.rb /app/
46
+
47
+ RUN apt update && apt upgrade -y && apt install -y curl libsodium-dev
48
+ RUN useradd waylon -d /app -M -c "Waylon Bot User"
49
+
50
+ USER waylon
51
+ WORKDIR /app
52
+ RUN gem install waylon
53
+
54
+ ENTRYPOINT ["waylon"]
55
+ TEMPLATE
56
+ end
57
+
58
+ def bot_gemfile_template
59
+ <<~TEMPLATE
60
+ # frozen_string_literal: true
61
+
62
+ source "https://rubygems.org"
63
+
64
+ require_relative "plugins"
65
+ gem "waylon"
66
+
67
+ Plugins.plugins.each_key do |gem_name|
68
+ gem gem_name
69
+ end
70
+ TEMPLATE
71
+ end
72
+
73
+ def bot_rakefile_template
74
+ <<~TEMPLATE
75
+ # frozen_string_literal: true
76
+
77
+ require "resque/tasks"
78
+ require "waylon"
79
+
80
+ task "resque:setup" do
81
+ require_relative "plugins"
82
+
83
+ Waylon::Config.instance.load_env
84
+
85
+ Plugins.plugins.each_value do |plugin|
86
+ require plugin
87
+ end
88
+ Resque.redis = ENV.fetch("REDIS", "localhost:6379")
89
+ Resque.logger = Waylon::Logger.logger
90
+ end
91
+ TEMPLATE
92
+ end
93
+
94
+ def skill_rakefile_template
95
+ <<~TEMPLATE
96
+ # frozen_string_literal: true
97
+
98
+ require "bundler/gem_tasks"
99
+ require "rspec/core/rake_task"
100
+ require "rubocop/rake_task"
101
+ require "redis/errors"
102
+ require "resque/tasks"
103
+ require "yard"
104
+ require "waylon/core"
105
+
106
+ RSpec::Core::RakeTask.new(:spec)
107
+ RuboCop::RakeTask.new
108
+ YARD::Rake::YardocTask.new do |y|
109
+ y.options = [
110
+ "--markup", "markdown"
111
+ ]
112
+ end
113
+
114
+ task default: %i[spec rubocop yard]
115
+
116
+ task :demo do
117
+ require "pry"
118
+ require_relative "lib/waylon/skills/#{@project_name}"
119
+ Waylon::Logger.logger = ::Logger.new("/dev/null")
120
+ Waylon::Cache.storage = Moneta.new(:Cookie)
121
+ Waylon::Storage.storage = Moneta.new(:Cookie)
122
+ require "waylon/rspec/test_server"
123
+ end
124
+ TEMPLATE
125
+ end
126
+
127
+ def skill_skeleton_template
128
+ <<~TEMPLATE
129
+ # frozen_string_literal: true
130
+
131
+ module Waylon
132
+ module Skills
133
+ # A Waylon Skill
134
+ class #{@project_name.capitalize} < Waylon::Skill
135
+ route(
136
+ /#{@project_name}/i,
137
+ :do_the_thing,
138
+ help: {
139
+ usage: "FILL IN HOW TO USE THIS",
140
+ description: "EXPLAIN WHAT THIS DOES"
141
+ },
142
+ mention_only: true # this means your message must mention Waylon
143
+ )
144
+
145
+ def do_the_thing
146
+ # TODO: Fill this in...
147
+
148
+ # Some example capabilities:
149
+ #
150
+ # react :wave
151
+ #
152
+ # That will react to a chat message, assuming the Sense supports reactions
153
+
154
+ # If you need access to the message, use this:
155
+ #
156
+ # tokens
157
+ #
158
+ # It provides an Array of captures content
159
+
160
+ # To send a message back, use:
161
+ #
162
+ # reply "some message"
163
+ #
164
+ # You could also reply in a thread:
165
+ #
166
+ # threaded_reply "this is a response in a thread!"
167
+ end
168
+ end
169
+ end
170
+ end
171
+ TEMPLATE
172
+ end
173
+
174
+ def config_ru_template
175
+ <<~TEMPLATE
176
+ # frozen_string_literal: true
177
+
178
+ require_relative "plugins"
179
+
180
+ require "waylon"
181
+ require "waylon/services/ping"
182
+
183
+ Plugins.plugins.each_value do |plugin|
184
+ require plugin
185
+ end
186
+
187
+ use Rack::ShowExceptions
188
+
189
+ Waylon::Config.instance.load_env
190
+
191
+ services = {
192
+ "/ping" => Waylon::Services::Ping.new
193
+ }
194
+ run Rack::URLMap.new(
195
+ services.merge(Waylon::WebhookRegistry.instance.to_hash)
196
+ )
197
+ TEMPLATE
198
+ end
199
+
200
+ def plugins_rb_template
201
+ <<~TEMPLATE
202
+ # frozen_string_literal: true
203
+
204
+ # Used to help package up the plugins you'd like to load for Waylon
205
+ module Plugins
206
+ # Should return a Hash like:
207
+ # { "waylon-plugin-gem" => "waylon/plugin/gem" }
208
+ #
209
+ # Where "waylon-plugin-gem" is the name of the gem to install and
210
+ # "waylon/plugin/gem" is what you `require` to use it
211
+
212
+ def self.plugins
213
+ {
214
+ # Choose a Sense plugin to send messages to your bot
215
+ # Read more about this plugin here: https://github.com/jgnagy/waylon-slack
216
+ "waylon-slack" => "waylon/slack",
217
+
218
+ # Add some Skill plugins to let your bot do things
219
+ # Read more about this plugin here: https://github.com/jgnagy/waylon-dice
220
+ "waylon-dice" => "waylon/dice"
221
+ }
222
+ end
223
+ end
224
+ TEMPLATE
225
+ end
226
+
227
+ def bot_template_mapping
228
+ {
229
+ config_ru_template: "config.ru",
230
+ dockerfile_template: "Dockerfile",
231
+ gemfile_template: "Gemfile",
232
+ plugins_rb_template: "plugins.rb",
233
+ bot_rakefile_template: "Rakefile",
234
+ rubocop_template: ".rubocop.yml",
235
+ ruby_version_template: ".ruby-version"
236
+ }
237
+ end
238
+
239
+ def skill_template_mapping(project_name)
240
+ {
241
+ skill_rakefile_template: "Rakefile",
242
+ rubocop_template: ".rubocop.yml",
243
+ ruby_version_template: ".ruby-version",
244
+ skill_skeleton_template: "lib/waylon/skills/#{project_name}.rb"
245
+ }
246
+ end
247
+
10
248
  case action
249
+ when "init"
250
+ project_name = ARGV[1]
251
+ unless project_name
252
+ logger.fatal "Missing Project Name for new bot!"
253
+ exit 1
254
+ end
255
+
256
+ unless validate_project_name(project_name)
257
+ logger.fatal "Invalid Project Name: #{project_name}"
258
+ exit 2
259
+ end
260
+
261
+ logger.info "Initializing new Waylon bot project '#{project_name}'..."
262
+ system("git init #{project_name}")
263
+ Dir.chdir(project_name) do
264
+ bot_template_mapping.each do |func, file|
265
+ logger.info "Rendering #{File.expand_path(File.join(project_name, file))}"
266
+ File.write(file, send(func))
267
+ end
268
+ end
269
+ logger.info "Done!"
270
+ when "skill"
271
+ project_name = ARGV[1]
272
+ unless project_name
273
+ logger.fatal "Missing Project Name for new Skill plugin!"
274
+ exit 1
275
+ end
276
+
277
+ unless validate_project_name(project_name)
278
+ logger.fatal "Invalid Skill Name: #{project_name}"
279
+ exit 2
280
+ end
281
+
282
+ gem_name = project_name.start_with?("waylon-") ? project_name : "waylon-#{project_name}"
283
+ @project_name = project_name # for rendering templates
284
+
285
+ logger.info "Initializing new Waylon Skill plugin '#{gem_name}'..."
286
+ system("bundle gem --test=rspec --no-exe #{gem_name}")
287
+ Dir.chdir(gem_name) do
288
+ FileUtils.mkdir_p("lib/waylon/skills")
289
+ skill_template_mapping(project_name).each do |func, file|
290
+ logger.info "Rendering #{File.expand_path(File.join(gem_name, file))}"
291
+ File.write(file, send(func))
292
+ end
293
+ end
294
+ logger.info "Done!"
11
295
  when "worker"
12
296
  logger.info "Starting Worker..."
13
297
  ENV["INTERVAL"] ||= "0.5"
data/scripts/test.sh CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
+ apt-get update && apt-get install -y libsodium-dev
4
+
3
5
  gem install bundler -v '~> 2.3'
4
6
  bundle install
5
7
  bundle exec rake
data/waylon.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Waylon
4
4
  # Update this to match the desired Waylon::Core::VERSION to release
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.5"
6
6
  end
7
7
 
8
8
  Gem::Specification.new do |spec|
@@ -39,5 +39,6 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency "rubocop-rake", "~> 0.6"
40
40
  spec.add_development_dependency "rubocop-rspec", "~> 2.6"
41
41
  spec.add_development_dependency "simplecov", "~> 0.21"
42
+ spec.add_development_dependency "solargraph", "~> 0.45"
42
43
  spec.add_development_dependency "yard", "~> 0.9", ">= 0.9.27"
43
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waylon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Gnagy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-19 00:00:00.000000000 Z
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.21'
125
+ - !ruby/object:Gem::Dependency
126
+ name: solargraph
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.45'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.45'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: yard
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -162,6 +176,24 @@ files:
162
176
  - README.md
163
177
  - Rakefile
164
178
  - bin/setup
179
+ - examples/deploying/helm/waylon/.helmignore
180
+ - examples/deploying/helm/waylon/Chart.yaml
181
+ - examples/deploying/helm/waylon/README.md
182
+ - examples/deploying/helm/waylon/templates/_helpers.tpl
183
+ - examples/deploying/helm/waylon/templates/redis-pv.yaml
184
+ - examples/deploying/helm/waylon/templates/redis-pvc.yaml
185
+ - examples/deploying/helm/waylon/templates/redis-statefulset.yaml
186
+ - examples/deploying/helm/waylon/templates/web-deployment.yaml
187
+ - examples/deploying/helm/waylon/templates/web-ingress.yaml
188
+ - examples/deploying/helm/waylon/templates/web-service.yaml
189
+ - examples/deploying/helm/waylon/templates/worker-deployment.yaml
190
+ - examples/deploying/helm/waylon/values.yaml
191
+ - examples/deploying/k8s/README.md
192
+ - examples/deploying/k8s/redis-statefulset.yaml
193
+ - examples/deploying/k8s/web-deployment.yaml
194
+ - examples/deploying/k8s/web-ingress.yaml
195
+ - examples/deploying/k8s/web-service.yaml
196
+ - examples/deploying/k8s/worker-deployment.yaml
165
197
  - exe/waylon
166
198
  - lib/waylon.rb
167
199
  - scripts/release.sh