bard-api 0.7.1 → 0.7.3

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: '079e1d8cd0c0dce4b230289d239e1fa66ec8f83579de882f8fe52bad2e2247e5'
4
- data.tar.gz: baf8c4e974bb28d30e074e9fd1a7e89fcbf97d51bcae30093818602ce94a4c1a
3
+ metadata.gz: a6b391d16edbcce354471c8ca97896071724fe02b6cf23c3ff4386da3e305880
4
+ data.tar.gz: ca918166c464060c2e5b29e578a1d424709e06e61f29fcde1afa21fe316302e1
5
5
  SHA512:
6
- metadata.gz: e08d9a6e2c204f28fc7f5c489565675464ec37b305d6441cc0b166296fb1b3a34482a3255f82827251fe67d688e4c1dc7ea5e4543c820afeac2ea5dfc7518000
7
- data.tar.gz: db5019904bb2dcecd03f3fa12582f6fb1f1725df4f44c97774786a62e5ed7a139d60f2ac7532d520a5da2d8485dd6be29670afa6fbad63950b3027049df1f29e
6
+ metadata.gz: 2771c33c1027e6943818ea8f88b79da892f3ff6e908e83dd708e212ecbd09f2b64c673f6029f164d3cf54cce05e23963d3f062941af12a7d2611226b10d51ebd
7
+ data.tar.gz: edc9bd911a5ab36d666d3a88594662ee0d784e31c4792533c6a5ec7dc27a7f0ca01f6358bb2c69a61dff2e308ba946e6e4226327ce69f2fae102c3f01eaba84b
data/lib/bard/api/app.rb CHANGED
@@ -31,10 +31,11 @@ module Bard
31
31
  # git pull lands a lockfile with not-yet-installed gems.
32
32
  def spawn_detached_deploy(command)
33
33
  Bundler.with_unbundled_env do
34
+ # After a Puma hot restart its listener survives exec; held here, it'd block the deploy's own restart.
34
35
  pid = Process.spawn(
35
36
  deploy_env,
36
37
  "systemd-run", "--user", "--scope", "--collect", "--quiet", "bash", "-lc", command,
37
- :in => "/dev/null", %i[out err] => ["log/bard-deploy.log", "a"],
38
+ :in => "/dev/null", %i[out err] => ["log/bard-deploy.log", "a"], close_others: true,
38
39
  )
39
40
  Process.detach(pid)
40
41
  end
@@ -72,7 +73,9 @@ module Bard
72
73
  "flock -n #{DEPLOY_LOCK} -c '" \
73
74
  "rm -f #{FAILED_SHA}; " \
74
75
  "before=$(git rev-parse HEAD); " \
75
- "git pull --ff-only origin master && bin/setup && git rev-parse HEAD > #{DEPLOYED_SHA} " \
76
+ "git pull --ff-only origin master && " \
77
+ "{ [ \"$(git rev-parse HEAD)\" = \"$(cat #{DEPLOYED_SHA})\" ] || " \
78
+ "{ bin/setup && git rev-parse HEAD > #{DEPLOYED_SHA}; }; } " \
76
79
  "|| { git rev-parse origin/master > #{FAILED_SHA}; git reset --hard \"$before\"; }'"
77
80
 
78
81
  def call(env)
@@ -161,16 +164,16 @@ module Bard
161
164
  # bin/setup restarts Puma, so we can't run the deploy in this worker thread — the restart
162
165
  # would kill it mid-flight. We hand off to an out-of-band process (its own systemd scope,
163
166
  # see .deploy_runner), serialize concurrent deploys with an flock, and return 202
164
- # immediately. The caller polls until HEAD == sha.
167
+ # immediately. The caller polls until the deployed sha includes the requested one.
165
168
  def create_deploy(request)
166
169
  target = JSON.parse(request.body.read)["sha"]
167
170
  sha = current_sha
168
- return json_response(200, { status: "noop", sha: sha }) if target == sha
171
+ return json_response(200, { status: "noop", sha: sha }) if includes_commit?(sha, target)
169
172
  return json_response(409, { status: "deploying", sha: sha }) if deploy_in_progress?
170
173
 
171
- # A prior attempt at this exact sha just failed. Report it instead of re-spawning the
174
+ # A prior attempt that included this sha just failed. Report it instead of re-spawning the
172
175
  # deploy on every poll (which would restart Puma every few seconds and never converge).
173
- if target == failed_sha && recently_failed?
176
+ if includes_commit?(failed_sha, target) && recently_failed?
174
177
  return json_response(500, {
175
178
  status: "failed",
176
179
  sha: sha,
@@ -183,6 +186,13 @@ module Bard
183
186
  json_response(202, { status: "deploying", sha: sha })
184
187
  end
185
188
 
189
+ # Master can advance past the requested sha mid-poll, so an exact match might never come.
190
+ def includes_commit?(sha, target)
191
+ return true if target == sha
192
+ return false unless [sha, target].all? { |commit| commit.to_s.match?(/\A\h{40}\z/) }
193
+ system("git", "merge-base", "--is-ancestor", target, sha, err: File::NULL)
194
+ end
195
+
186
196
  # The last FULLY deployed sha (bin/setup succeeded), not merely where git HEAD points.
187
197
  # Absent marker => nothing has completed yet, so it can never match the requested sha and
188
198
  # the caller keeps polling until bin/setup writes it — or times out on a real failure.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bard
4
4
  module Api
5
- VERSION = "0.7.1"
5
+ VERSION = "0.7.3"
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.7.1
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-10-05 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: jwt
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.6.2
120
+ rubygems_version: 4.0.20
121
121
  specification_version: 4
122
122
  summary: REST API for BARD-managed Rails projects
123
123
  test_files: []