bard 0.63.0 → 0.64.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: 3d7d5a0ea2e8612375c2cdff91db9018db99cbebd5c7b261eac8bd8cd759c56d
4
- data.tar.gz: b92bf6109d27d6266ea4d5c600814fcc27c0cede6620a7cac3d2a1f829dc9604
3
+ metadata.gz: f618df3bbb634f25fcb5f03f81a68b733e2fd70d5a654b8e8f9e0733ce180849
4
+ data.tar.gz: 155060b90c13a3365bf3cd768642966bbc4926643b92d9f18378f69a9516df01
5
5
  SHA512:
6
- metadata.gz: 78f9952dad75d7cd3b2bc3320b94101e184173edc10fab5c8d12a7c8ed1e87db17852715879fc18d446a1fa077ac9fae34b85c13ddce626ffd54bd87cc013476
7
- data.tar.gz: 639bb68fe3c42d18d9c5709f4fae18707578496423c4982b37c97e00e981458a7dc3eee4bf7eae596c99c18efd39f0bee714c0fb47d2d721fad1b5acb0b7caa5
6
+ metadata.gz: f4e42669d831bdf57dc6749ca7443690a307d9abf048f1a1e0eecbfd33a7f53e0a94a4aa1bf78f3724054407f7e679f49fcac029cc1fa00199c7584e68c5301b
7
+ data.tar.gz: 7193a3c7324ee1da26262f18516f3a672299ccc29b1f1737eee7ad121c7cb992e7609fd271cc963b5f673285f9ec31f5c44074ae869f738264ba6ecd8b6749c8
@@ -1,7 +1,6 @@
1
1
  require "thor"
2
2
  require "time"
3
- require "json"
4
- require "net/http"
3
+ require "bard/github"
5
4
 
6
5
  class Bard::CLI < Thor
7
6
  class CI
@@ -53,31 +52,31 @@ class Bard::CLI < Thor
53
52
 
54
53
  class API < Struct.new(:project_name)
55
54
  def last_run
56
- response = client.get("runs", event: "workflow_dispatch", per_page: 1)
55
+ response = client.get("actions/runs", event: "workflow_dispatch", per_page: 1)
57
56
  if json = response["workflow_runs"][0]
58
57
  Run.new(self, json)
59
58
  end
60
59
  end
61
60
 
62
61
  def last_successful_run
63
- successful_runs = client.get("runs", event: "workflow_dispatch", status: "success", per_page: 1)
62
+ successful_runs = client.get("actions/runs", event: "workflow_dispatch", status: "success", per_page: 1)
64
63
  if json = successful_runs["workflow_runs"][0]
65
64
  Run.new(self, json)
66
65
  end
67
66
  end
68
67
 
69
68
  def find_run id
70
- json = client.get("runs/#{id}")
69
+ json = client.get("actions/runs/#{id}")
71
70
  Run.new(self, json)
72
71
  end
73
72
 
74
73
  def create_run! branch
75
74
  start_time = Time.now
76
- client.post("workflows/ci.yml/dispatches", ref: branch, inputs: { "git-ref": branch })
75
+ client.post("actions/workflows/ci.yml/dispatches", ref: branch, inputs: { "git-ref": branch })
77
76
  sha = `git rev-parse #{branch}`.chomp
78
77
 
79
78
  loop do
80
- runs = client.get("runs", head_sha: sha, created: ">#{start_time.iso8601}")
79
+ runs = client.get("actions/runs", head_sha: sha, created: ">#{start_time.iso8601}")
81
80
  if json = runs["workflow_runs"].first
82
81
  return Run.new(self, json)
83
82
  end
@@ -86,19 +85,19 @@ class Bard::CLI < Thor
86
85
  end
87
86
 
88
87
  def find_job_by_run_id run_id
89
- jobs = client.get("runs/#{run_id}/jobs", filter: "latest", per_page: 1)
88
+ jobs = client.get("actions/runs/#{run_id}/jobs", filter: "latest", per_page: 1)
90
89
  job_json = jobs["jobs"][0]
91
90
  Job.new(self, job_json)
92
91
  end
93
92
 
94
93
  def download_logs_by_job_id job_id
95
- client.get("jobs/#{job_id}/logs")
94
+ client.get("actions/jobs/#{job_id}/logs")
96
95
  end
97
96
 
98
97
  private
99
98
 
100
99
  def client
101
- @client ||= Client.new(project_name)
100
+ @client ||= Bard::Github.new(project_name)
102
101
  end
103
102
  end
104
103
 
@@ -171,62 +170,6 @@ class Bard::CLI < Thor
171
170
  @logs ||= api.download_logs_by_job_id(id)
172
171
  end
173
172
  end
174
-
175
- class Client < Struct.new(:project_name)
176
- def get path, params={}
177
- request(path) do |uri|
178
- uri.query = URI.encode_www_form(params)
179
- Net::HTTP::Get.new(uri)
180
- end
181
- end
182
-
183
- def post path, params={}
184
- request(path) do |uri|
185
- Net::HTTP::Post.new(uri).tap do |r|
186
- r.body = JSON.dump(params)
187
- end
188
- end
189
- end
190
-
191
- private
192
-
193
- def github_apikey
194
- @github_apikey ||= begin
195
- raw = `git ls-remote -t git@github.com:botandrose/bard`
196
- raw[/github-apikey\|(.+)$/, 1]
197
- end
198
- end
199
-
200
- def request path, &block
201
- uri = if path =~ /^http/
202
- URI(path)
203
- else
204
- URI("https://api.github.com/repos/botandrosedesign/#{project_name}/actions/#{path}")
205
- end
206
-
207
- req = nil
208
- response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
209
- req = block.call(uri)
210
- req["Accept"] = "application/vnd.github+json"
211
- req["Authorization"] = "Bearer #{github_apikey}"
212
- req["X-GitHub-Api-Version"] = "2022-11-28"
213
- http.request(req)
214
- end
215
-
216
- case response
217
- when Net::HTTPRedirection then
218
- Net::HTTP.get(URI(response["Location"]))
219
- when Net::HTTPSuccess then
220
- if response["Content-Type"].to_s.include?("/json")
221
- JSON.load(response.body)
222
- else
223
- response.body
224
- end
225
- else
226
- raise [req.method, req.uri, req.to_hash, response].inspect
227
- end
228
- end
229
- end
230
173
  end
231
174
  end
232
175
  end
data/lib/bard/config.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require "uri"
2
2
 
3
- class Bard::CLI < Thor
3
+ module Bard
4
4
  class Config
5
- def initialize project_name, path
5
+ def initialize project_name, path: nil, source: nil
6
6
  @project_name = project_name
7
7
  @servers = {
8
8
  local: Server.new(
@@ -39,7 +39,10 @@ class Bard::CLI < Thor
39
39
  "www@#{project_name}.botandrose.com:22022",
40
40
  ),
41
41
  }
42
- load_local_config! path
42
+ if path && File.exist?(path)
43
+ source = File.read(File.expand_path(path))
44
+ end
45
+ instance_eval source
43
46
  end
44
47
 
45
48
  attr_reader :servers
@@ -60,10 +63,6 @@ class Bard::CLI < Thor
60
63
 
61
64
  private
62
65
 
63
- def load_local_config! path
64
- instance_eval File.read(File.expand_path(path)) if File.exist?(path)
65
- end
66
-
67
66
  class Server < Struct.new(:project_name, :key, :ssh, :path, :ping, :gateway, :ssh_key, :env)
68
67
  def self.setting *fields
69
68
  fields.each do |field|
@@ -0,0 +1,67 @@
1
+ require "net/http"
2
+ require "json"
3
+ require "base64"
4
+
5
+ module Bard
6
+ class Github < Struct.new(:project_name)
7
+ def get path, params={}
8
+ request(path) do |uri|
9
+ uri.query = URI.encode_www_form(params)
10
+ Net::HTTP::Get.new(uri)
11
+ end
12
+ end
13
+
14
+ def post path, params={}
15
+ request(path) do |uri|
16
+ Net::HTTP::Post.new(uri).tap do |r|
17
+ r.body = JSON.dump(params)
18
+ end
19
+ end
20
+ end
21
+
22
+ def read_file path, branch: "master"
23
+ metadata = get("contents/#{path}", ref: branch)
24
+ Base64.decode64(metadata["content"])
25
+ end
26
+
27
+ private
28
+
29
+ def github_apikey
30
+ @github_apikey ||= begin
31
+ raw = `git ls-remote -t git@github.com:botandrose/bard`
32
+ raw[/github-apikey\|(.+)$/, 1]
33
+ end
34
+ end
35
+
36
+ def request path, &block
37
+ uri = if path =~ /^http/
38
+ URI(path)
39
+ else
40
+ URI("https://api.github.com/repos/botandrosedesign/#{project_name}/#{path}")
41
+ end
42
+
43
+ req = nil
44
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
45
+ req = block.call(uri)
46
+ req["Accept"] = "application/vnd.github+json"
47
+ req["Authorization"] = "Bearer #{github_apikey}"
48
+ req["X-GitHub-Api-Version"] = "2022-11-28"
49
+ http.request(req)
50
+ end
51
+
52
+ case response
53
+ when Net::HTTPRedirection then
54
+ Net::HTTP.get(URI(response["Location"]))
55
+ when Net::HTTPSuccess then
56
+ if response["Content-Type"].to_s.include?("/json")
57
+ JSON.load(response.body)
58
+ else
59
+ response.body
60
+ end
61
+ else
62
+ raise [req.method, req.uri, req.to_hash, response].inspect
63
+ end
64
+ end
65
+ end
66
+ end
67
+
data/lib/bard/ping.rb ADDED
@@ -0,0 +1,21 @@
1
+ module Bard
2
+ class Ping < Struct.new(:server)
3
+ def self.call server
4
+ new(server).call
5
+ end
6
+
7
+ def call
8
+ return true if server.ping == false
9
+
10
+ url = server.default_ping
11
+ if server.ping =~ %r{^/}
12
+ url += server.ping
13
+ elsif server.ping.to_s.length > 0
14
+ url = server.ping
15
+ end
16
+
17
+ command = "curl -sfL #{url} 2>&1 1>/dev/null"
18
+ system command
19
+ end
20
+ end
21
+ end
data/lib/bard/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Bard
2
- VERSION = "0.63.0"
2
+ VERSION = "0.64.0"
3
3
  end
4
4
 
data/lib/bard.rb CHANGED
@@ -4,7 +4,8 @@ require "bard/base"
4
4
  require "bard/git"
5
5
  require "bard/ci"
6
6
  require "bard/data"
7
-
7
+ require "bard/github"
8
+ require "bard/ping"
8
9
  require "bard/config"
9
10
 
10
11
  class Bard::CLI < Thor
@@ -12,7 +13,7 @@ class Bard::CLI < Thor
12
13
 
13
14
  def initialize(*args, **kwargs, &block)
14
15
  super
15
- @config = Config.new(project_name, "bard.rb")
16
+ @config = Bard::Config.new(project_name, path: "bard.rb")
16
17
  end
17
18
 
18
19
  desc "data --from=production --to=local", "copy database and assets from from to to"
@@ -207,17 +208,7 @@ class Bard::CLI < Thor
207
208
  desc "ping [SERVER=production]", "hits the server over http to verify that its up."
208
209
  def ping server=:production
209
210
  server = @config.servers[server.to_sym]
210
- return false if server.ping == false
211
-
212
- url = server.default_ping
213
- if server.ping =~ %r{^/}
214
- url += server.ping
215
- elsif server.ping.to_s.length > 0
216
- url = server.ping
217
- end
218
-
219
- command = "curl -sfL #{url} 2>&1 1>/dev/null"
220
- unless system command
211
+ unless Bard::Ping.call(server)
221
212
  puts "#{server.key.to_s.capitalize} is down!"
222
213
  exit 1
223
214
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.63.0
4
+ version: 0.64.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-12 00:00:00.000000000 Z
11
+ date: 2024-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -155,6 +155,8 @@ files:
155
155
  - lib/bard/config.rb
156
156
  - lib/bard/data.rb
157
157
  - lib/bard/git.rb
158
+ - lib/bard/github.rb
159
+ - lib/bard/ping.rb
158
160
  - lib/bard/version.rb
159
161
  - spec/bard/ci/github_actions_spec.rb
160
162
  - spec/bard_spec.rb