bard-api 0.7.2 → 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: fb3c291a8c804638f9772066f06931da361325929c1e1d83b4e05f96129402ea
4
- data.tar.gz: 70bdf967ed1b328854bef3a96e10f55d4b4233c3f9152f3f1288e4fc91be5c14
3
+ metadata.gz: a6b391d16edbcce354471c8ca97896071724fe02b6cf23c3ff4386da3e305880
4
+ data.tar.gz: ca918166c464060c2e5b29e578a1d424709e06e61f29fcde1afa21fe316302e1
5
5
  SHA512:
6
- metadata.gz: 6dfc5296a1c8304c9d3a4a2ead2c460b3192ecfb4e230b679708674e4a4fd04ed5bd7d1f955379a6fde4817c69df1e93a4a16e271c4d788ad85a06d74e23e186
7
- data.tar.gz: 51613fc4e1cb69a2e4ca9eb38bc5486ef71fe6fc89cce3ddf32e1f5f93db8afc6c865254705bcd671804b91e2c66a66485d2b8b457b3d8604397bde8249da318
6
+ metadata.gz: 2771c33c1027e6943818ea8f88b79da892f3ff6e908e83dd708e212ecbd09f2b64c673f6029f164d3cf54cce05e23963d3f062941af12a7d2611226b10d51ebd
7
+ data.tar.gz: edc9bd911a5ab36d666d3a88594662ee0d784e31c4792533c6a5ec7dc27a7f0ca01f6358bb2c69a61dff2e308ba946e6e4226327ce69f2fae102c3f01eaba84b
data/lib/bard/api/app.rb CHANGED
@@ -73,7 +73,9 @@ module Bard
73
73
  "flock -n #{DEPLOY_LOCK} -c '" \
74
74
  "rm -f #{FAILED_SHA}; " \
75
75
  "before=$(git rev-parse HEAD); " \
76
- "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}; }; } " \
77
79
  "|| { git rev-parse origin/master > #{FAILED_SHA}; git reset --hard \"$before\"; }'"
78
80
 
79
81
  def call(env)
@@ -162,16 +164,16 @@ module Bard
162
164
  # bin/setup restarts Puma, so we can't run the deploy in this worker thread — the restart
163
165
  # would kill it mid-flight. We hand off to an out-of-band process (its own systemd scope,
164
166
  # see .deploy_runner), serialize concurrent deploys with an flock, and return 202
165
- # immediately. The caller polls until HEAD == sha.
167
+ # immediately. The caller polls until the deployed sha includes the requested one.
166
168
  def create_deploy(request)
167
169
  target = JSON.parse(request.body.read)["sha"]
168
170
  sha = current_sha
169
- 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)
170
172
  return json_response(409, { status: "deploying", sha: sha }) if deploy_in_progress?
171
173
 
172
- # 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
173
175
  # deploy on every poll (which would restart Puma every few seconds and never converge).
174
- if target == failed_sha && recently_failed?
176
+ if includes_commit?(failed_sha, target) && recently_failed?
175
177
  return json_response(500, {
176
178
  status: "failed",
177
179
  sha: sha,
@@ -184,6 +186,13 @@ module Bard
184
186
  json_response(202, { status: "deploying", sha: sha })
185
187
  end
186
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
+
187
196
  # The last FULLY deployed sha (bin/setup succeeded), not merely where git HEAD points.
188
197
  # Absent marker => nothing has completed yet, so it can never match the requested sha and
189
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.2"
5
+ VERSION = "0.7.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
@@ -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: 4.0.6
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: []