bard-api 0.6.1 → 0.6.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 563830ec8c572c92d9ccfe0baacef1e2e24746600e7a8d8508a3fe2819c6650e
4
- data.tar.gz: f015d645e8d3bee75b1975b496ae53a93dc7e3bceeb2f21489a954e142862209
3
+ metadata.gz: 4d4da564c789355e60c447afcd4509dab027ae176561da244b95b31787df786b
4
+ data.tar.gz: b6307c6ee310ce199ee18b8760e846272cf7c66276cb3d5d5a64ecf60d580f5e
5
5
  SHA512:
6
- metadata.gz: 9f49e14b5cb6ab5b9a56c7b5f138d17c725ccdea8c995f9e9e811580ff0cb7801a65c77ce3ee7a6bc8e93cbc4dfb5748702c858873488e9551da8bc63356a518
7
- data.tar.gz: ccfa6aec43edc4d1f30b23cb92b837e9535ef46f1e3b997791bcd0d0a25bb38b736682ef5a468d28652297b670cd0b80d6ebb8f30a8c9444bd446589d25b4290
6
+ metadata.gz: d0c3651eaa2dd8ad9ba27693f942d7b9f29acbc72d9104d012d24bfa3b8179ea13531c000bd7c7d9b883a9b70a9d99fcda5235ddeb03773c7b3bd6c57ba5a496
7
+ data.tar.gz: c8e8658f60a5327f7e6770c457501c2b73769b17842ad73830c7ce81159736be48542fda169bf6bd500db6698e5088af772d52cf0c4f6c15c88b722d7ce7170b
data/lib/bard/api/app.rb CHANGED
@@ -43,9 +43,21 @@ module Bard
43
43
 
44
44
  DEPLOY_LOCK = "tmp/bard-deploy.lock"
45
45
  DEPLOYED_SHA = "tmp/bard-deployed.sha"
46
+ FAILED_SHA = "tmp/bard-deploy-failed.sha"
47
+ DEPLOY_LOG = "log/bard-deploy.log"
48
+ # How long a failed sha short-circuits re-deploy: long enough to end the caller's poll loop
49
+ # without a re-spawn, short enough that a fresh `bard deploy` run can retry the same sha.
50
+ FAILED_COOLDOWN = 60
51
+
46
52
  # Record the deployed sha only after bin/setup fully succeeds — a bare `git pull` advances
47
53
  # HEAD before the bundle/migrate/restart run, so HEAD alone would read as "done" too early.
48
- DEPLOY_COMMAND = "flock -n #{DEPLOY_LOCK} -c 'git pull --ff-only origin master && bin/setup && git rev-parse HEAD > #{DEPLOYED_SHA}'"
54
+ # On any failure, stamp the attempted sha so we don't re-spawn (and restart Puma) on every
55
+ # poll; the marker is written inside the flock, so it's on disk before the lock releases.
56
+ DEPLOY_COMMAND =
57
+ "flock -n #{DEPLOY_LOCK} -c '" \
58
+ "rm -f #{FAILED_SHA}; " \
59
+ "git pull --ff-only origin master && bin/setup && git rev-parse HEAD > #{DEPLOYED_SHA} " \
60
+ "|| git rev-parse origin/master > #{FAILED_SHA}'"
49
61
 
50
62
  def call(env)
51
63
  request = Rack::Request.new(env)
@@ -136,6 +148,17 @@ module Bard
136
148
  return json_response(200, { status: "noop", sha: sha }) if target == sha
137
149
  return json_response(409, { status: "deploying", sha: sha }) if deploy_in_progress?
138
150
 
151
+ # A prior attempt at this exact sha just failed. Report it instead of re-spawning the
152
+ # deploy on every poll (which would restart Puma every few seconds and never converge).
153
+ if target == failed_sha && recently_failed?
154
+ return json_response(500, {
155
+ status: "failed",
156
+ sha: sha,
157
+ error: "deploy failed on the server; see #{DEPLOY_LOG}",
158
+ log: deploy_log_tail,
159
+ })
160
+ end
161
+
139
162
  self.class.deploy_runner.call(DEPLOY_COMMAND)
140
163
  json_response(202, { status: "deploying", sha: sha })
141
164
  end
@@ -148,6 +171,21 @@ module Bard
148
171
  File.read(DEPLOYED_SHA).chomp
149
172
  end
150
173
 
174
+ # The sha whose deploy most recently failed (bin/setup or the git pull errored out).
175
+ def failed_sha
176
+ return "" unless File.exist?(FAILED_SHA)
177
+ File.read(FAILED_SHA).chomp
178
+ end
179
+
180
+ def recently_failed?
181
+ File.exist?(FAILED_SHA) && (Time.now - File.mtime(FAILED_SHA)) < FAILED_COOLDOWN
182
+ end
183
+
184
+ def deploy_log_tail(lines = 30)
185
+ return "" unless File.exist?(DEPLOY_LOG)
186
+ File.readlines(DEPLOY_LOG).last(lines).join
187
+ end
188
+
151
189
  def deploy_in_progress?
152
190
  File.open(DEPLOY_LOCK, File::RDWR | File::CREAT, 0o644) do |lock|
153
191
  acquired = lock.flock(File::LOCK_EX | File::LOCK_NB)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bard
4
4
  module Api
5
- VERSION = "0.6.1"
5
+ VERSION = "0.6.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
10
+ date: 2026-07-10 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: jwt
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  requirements: []
134
- rubygems_version: 4.0.6
134
+ rubygems_version: 3.6.2
135
135
  specification_version: 4
136
136
  summary: REST API for BARD-managed Rails projects
137
137
  test_files: []