tebako-release 0.5.0 → 0.5.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 +4 -4
- data/README.md +22 -0
- data/lib/tebako_release/convergence.rb +222 -0
- data/lib/tebako_release/signer.rb +159 -38
- data/lib/tebako_release/uploader.rb +134 -152
- data/lib/tebako_release/version.rb +1 -1
- data/lib/tebako_release.rb +1 -0
- metadata +16 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1b53759a657e4e43faf1ba35f8501d96f9d946f2314ecd281c29e126d9bb2922
|
|
4
|
+
data.tar.gz: 34561554830259839c72191cb3b490b34b09a2a4e948103156001a8222f9359f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 56d98f5d26a5b541e6ae44c9806420708a0ec79f7b088d17fa08cd9472b3b4d99e2d073338ad3760971505076bcd41501517f8a17dc2b835a5ddbf8dee1a6eb3
|
|
7
|
+
data.tar.gz: 418c0e58af44255d25563a9ee866a781cbfe4be44d87f96a0394e04bab7f5c3000af95ddf87fb6d9ceaf7a252dce59b381ce356ff5cfb74eeb1f462cb3fb9b1d
|
data/README.md
CHANGED
|
@@ -77,3 +77,25 @@ the 422 wedge; tebako-runtime-ruby#189). A forced republication recreates the
|
|
|
77
77
|
(`gh release delete <tag> --cleanup-tag false` … the first leg's
|
|
78
78
|
race-safe create re-makes it), turning every leg's publish into pure creates.
|
|
79
79
|
Operator-run re-uploads follow the same rule by hand.
|
|
80
|
+
|
|
81
|
+
## Convergence and rate-limit discipline
|
|
82
|
+
|
|
83
|
+
Every GitHub API call in the gem rides one internal wrapper
|
|
84
|
+
(`TebakoRelease::Convergence`), with per-operation-class semantics.
|
|
85
|
+
Unconditional calls (plain reads, idempotent writes) ride quota responses
|
|
86
|
+
out: a 403/429 rate-limit answer is never fatal — the wrapper sleeps to the
|
|
87
|
+
response's named window (`x-ratelimit-reset`, else `Retry-After`), or backs
|
|
88
|
+
off exponentially from 30 s up to a 10-minute cap when the response names no
|
|
89
|
+
window — and transport drops retry with escalating waits. Read-after-create
|
|
90
|
+
calls poll for the fresh release object's visibility on a bounded delay
|
|
91
|
+
list; delete-then-upload replaces poll the single-asset endpoint until the
|
|
92
|
+
deletion is visibly absent (plus a short name-release grace) before
|
|
93
|
+
re-uploading, so the 422 propagation race never wedges a leg. The patience
|
|
94
|
+
is bounded twice — eight absorbed quota responses per call, and a two-window
|
|
95
|
+
(~2 h) wall-clock ceiling per process — and then the leg fails with a named,
|
|
96
|
+
resumable error; the metadata replace loop additionally carries a hard
|
|
97
|
+
15-minute deadline. Convergence polls ride the single-asset endpoint (one
|
|
98
|
+
request per poll, never a re-paginated listing), so a catalog fleet stays
|
|
99
|
+
far inside the token's hourly request window. Every retry logs a stderr line
|
|
100
|
+
with the attempt, the wait, and the call's target, so a ride-out is visible
|
|
101
|
+
in the CI log instead of looking like a hang.
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright (c) 2026 [Ribose Inc](https://www.ribose.com).
|
|
4
|
+
# All rights reserved.
|
|
5
|
+
# This file is a part of tamatebako
|
|
6
|
+
|
|
7
|
+
require "octokit"
|
|
8
|
+
|
|
9
|
+
module TebakoRelease
|
|
10
|
+
# The ONE wrapper every GitHub API call in the gem rides (uploader and
|
|
11
|
+
# signer alike). A catalog run's ~90 publish/sign legs share one token's
|
|
12
|
+
# 5,000-request hourly window, and the release backend's reads are only
|
|
13
|
+
# eventually consistent against its writes — a leg must ride both
|
|
14
|
+
# physics out, bounded, and fail NAMED and resumable when a budget is
|
|
15
|
+
# genuinely spent (the 2026-10-03 catalog publish lost 64 of ~90 legs to
|
|
16
|
+
# terminal 403s; the 0.16.32 smoke wedged two legs for their whole job
|
|
17
|
+
# timeout in an unpropagated-delete cycle).
|
|
18
|
+
#
|
|
19
|
+
# The operation classes (each call site picks its own):
|
|
20
|
+
# * unconditional calls — plain GETs and idempotent writes: quota
|
|
21
|
+
# responses ride the window out, transport drops retry, everything
|
|
22
|
+
# else keeps its semantics (a 404/422 is information for the caller,
|
|
23
|
+
# never retried here).
|
|
24
|
+
# * read-after-create reads — a release object a concurrent leg just
|
|
25
|
+
# created: poll for visibility on RELEASE_VISIBILITY_DELAYS before
|
|
26
|
+
# the named failure (the call sites own the poll loop; the rides
|
|
27
|
+
# below keep a quota storm from burning the polls).
|
|
28
|
+
# * delete-then-upload replaces — poll the SINGLE-ASSET endpoint until
|
|
29
|
+
# the delete is visible, pay the name-release grace, then re-upload;
|
|
30
|
+
# the poll interval/deadline/grace live here so the uploader and the
|
|
31
|
+
# signer share one propagation discipline.
|
|
32
|
+
#
|
|
33
|
+
# Retry lines go to stderr (CI-visible) with the attempt, the wait, and
|
|
34
|
+
# the call's target label; the narrative stream stays on stdout.
|
|
35
|
+
module Convergence
|
|
36
|
+
# A ride-out budget genuinely spent: the named, resumable failure —
|
|
37
|
+
# the leg re-run converges on quota, never on code.
|
|
38
|
+
class RateLimitBudgetExhausted < StandardError; end
|
|
39
|
+
|
|
40
|
+
# GET/DELETE/PUT calls share the same transient network failure modes;
|
|
41
|
+
# retry them (they are idempotent). A quota response is not one of
|
|
42
|
+
# those modes: it rides the window out below and never consumes the
|
|
43
|
+
# transient attempts. Transport-level drops (SSL EOF, TCP reset)
|
|
44
|
+
# belong here too: a stale keep-alive connection answered with an SSL
|
|
45
|
+
# EOF is indistinguishable from a fresh one that works — net-http
|
|
46
|
+
# retries those on EOFError but NOT on OpenSSL::SSL::SSLError, so we
|
|
47
|
+
# do (the 2026-08-30 backfill crashed on exactly that, on the
|
|
48
|
+
# verification GET right after a long upload POST).
|
|
49
|
+
TRANSIENT_ERRORS = [
|
|
50
|
+
Net::WriteTimeout, Net::ReadTimeout,
|
|
51
|
+
Faraday::TimeoutError, Faraday::ConnectionFailed,
|
|
52
|
+
OpenSSL::SSL::SSLError, EOFError, SystemCallError
|
|
53
|
+
].freeze
|
|
54
|
+
TRANSIENT_ATTEMPTS = 4
|
|
55
|
+
|
|
56
|
+
# A quota response (403 with a rate-limit body, or a bare 429) must
|
|
57
|
+
# never kill a leg: the gem is one serialized actor per leg and
|
|
58
|
+
# sleeping until the window resets is the CORRECT behavior (the 0.16.6
|
|
59
|
+
# publish burned the tebako-ci token's hourly window in ~30 minutes
|
|
60
|
+
# and died at the finalize; run 37061404844 lost 64 legs the same
|
|
61
|
+
# way). Two bounds, whichever spends first:
|
|
62
|
+
RATE_LIMIT_SETTLE = 5
|
|
63
|
+
# The response names no window (no reset, no Retry-After — the
|
|
64
|
+
# secondary-limit shape): capped exponential backoff, doubling from
|
|
65
|
+
# 30 s to a 10-minute ceiling.
|
|
66
|
+
RATE_LIMIT_BACKOFF_BASE = 30
|
|
67
|
+
RATE_LIMIT_BACKOFF_CAP = 600
|
|
68
|
+
# Per-call quota patience: eight absorbed responses (~45 minutes of
|
|
69
|
+
# headerless backoff; header-named windows ride their own advice),
|
|
70
|
+
# then the named error — a fast red leg re-run converges for free,
|
|
71
|
+
# while a leg that keeps eating quota starves the fleet.
|
|
72
|
+
RATE_LIMIT_ATTEMPTS = 8
|
|
73
|
+
# …and the wall-clock ceiling: two full hourly windows waited in one
|
|
74
|
+
# process means something is systemically wrong — give up loudly
|
|
75
|
+
# instead of blocking the runner forever.
|
|
76
|
+
RATE_LIMIT_BUDGET = (2 * 3600) + 300
|
|
77
|
+
|
|
78
|
+
# Read-after-create visibility: a release object created by a
|
|
79
|
+
# concurrent leg (the race-safe create's loser, a sign leg ahead of
|
|
80
|
+
# its publisher) is not immediately readable — the 2026-10-02/03
|
|
81
|
+
# force_rebuild fan-out died on exactly this. Bounded polls, stretched
|
|
82
|
+
# past a short secondary-limit window the winner's own create may be
|
|
83
|
+
# riding out; each poll rides the wrapper, so a quota storm stretches
|
|
84
|
+
# the wait INSIDE the call instead of burning polls.
|
|
85
|
+
RELEASE_VISIBILITY_DELAYS = [5, 10, 15, 20, 30, 30, 30].freeze
|
|
86
|
+
|
|
87
|
+
# GitHub asset deletion is only eventually consistent: a same-name
|
|
88
|
+
# re-upload 422s until the delete propagates (the v0.16.1 windows
|
|
89
|
+
# publish lost SHA256SUMS.txt to exactly this — four retries inside
|
|
90
|
+
# ~20 s never saw the absence). Poll for the absence on the
|
|
91
|
+
# single-asset endpoint (the listing and the authoritative store
|
|
92
|
+
# replicate independently — the 0.16.32 smoke night flapped the
|
|
93
|
+
# listing while the store never moved), SLEEPING between polls, under
|
|
94
|
+
# a wall-clock deadline. The deadline matches the OBSERVED propagation
|
|
95
|
+
# window: the 2026-08-29 publish watched a deleted name stay
|
|
96
|
+
# 422-blocked well past the old 60 s. And the listing's truth frees
|
|
97
|
+
# the name BEFORE the upload validator's replica does (0.16.8: ~15 s
|
|
98
|
+
# past the visible absence), so every confirmed absence pays the grace.
|
|
99
|
+
DELETION_PROPAGATION_POLL_INTERVAL = 2
|
|
100
|
+
DELETION_PROPAGATION_DEADLINE = 180
|
|
101
|
+
DELETION_PROPAGATION_GRACE = 15
|
|
102
|
+
|
|
103
|
+
# Class (a): an unconditional call. Rate-limit responses ride out
|
|
104
|
+
# (never consuming the transient attempts); transport drops retry with
|
|
105
|
+
# escalating waits; the gateway trio of 5xx (502/503/504 — GitHub's
|
|
106
|
+
# side failing, the request never wrong) rides the same policy, while
|
|
107
|
+
# every other server error keeps its semantics — a 500 is a bug's
|
|
108
|
+
# signature, not a window's (tebako#1048: a 502 on the audit's asset
|
|
109
|
+
# pagination once failed an otherwise-green publish because ServerError
|
|
110
|
+
# was in no rescue set); every other error propagates to the caller's
|
|
111
|
+
# own semantics untouched.
|
|
112
|
+
def with_transient_retries(target = "GitHub call", attempts: TRANSIENT_ATTEMPTS) # rubocop:disable Metrics/MethodLength
|
|
113
|
+
budget = attempts
|
|
114
|
+
with_rate_limit_rideout(target) do
|
|
115
|
+
yield
|
|
116
|
+
rescue *TRANSIENT_ERRORS, Octokit::ServerError => e
|
|
117
|
+
raise if e.is_a?(Octokit::ServerError) && !transient_server_error?(e)
|
|
118
|
+
|
|
119
|
+
attempts -= 1
|
|
120
|
+
raise if attempts <= 0
|
|
121
|
+
|
|
122
|
+
delay = (5 * (budget - attempts)) + rand(5)
|
|
123
|
+
warn "github #{target}: #{e.class}; retrying in #{delay}s (#{attempts} attempt(s) left)"
|
|
124
|
+
sleep delay
|
|
125
|
+
retry
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# The retryable server class: the gateway trio only. A bare-raised
|
|
130
|
+
# error carries no response — and no claim of transience.
|
|
131
|
+
def transient_server_error?(error)
|
|
132
|
+
return false unless error.is_a?(Octokit::ServerError)
|
|
133
|
+
|
|
134
|
+
[502, 503, 504].include?(error.response_status.to_i)
|
|
135
|
+
rescue NoMethodError
|
|
136
|
+
false
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# The quota ride-out, bounded twice (RATE_LIMIT_ATTEMPTS per call,
|
|
140
|
+
# RATE_LIMIT_BUDGET wall-clock per process). Octokit 7 maps a 403 with
|
|
141
|
+
# a quota body — primary and secondary limits alike — to
|
|
142
|
+
# TooManyRequests, while a bare 429 arrives as a plain ClientError;
|
|
143
|
+
# both are the quota class here, and every other client error keeps
|
|
144
|
+
# its semantics (never swallowed, never retried).
|
|
145
|
+
def with_rate_limit_rideout(target = "GitHub call") # rubocop:disable Metrics/MethodLength
|
|
146
|
+
attempts = 0
|
|
147
|
+
begin
|
|
148
|
+
yield
|
|
149
|
+
rescue Octokit::ClientError => e
|
|
150
|
+
raise unless rate_limit_error?(e)
|
|
151
|
+
|
|
152
|
+
attempts += 1
|
|
153
|
+
wait = rate_limit_wait(e, target, attempts)
|
|
154
|
+
warn "github #{target}: #{e.class} — rate-limited; sleeping #{wait}s " \
|
|
155
|
+
"(quota response #{attempts}/#{RATE_LIMIT_ATTEMPTS})"
|
|
156
|
+
sleep wait
|
|
157
|
+
retry
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def rate_limit_error?(error)
|
|
162
|
+
return true if error.is_a?(Octokit::TooManyRequests)
|
|
163
|
+
return false unless error.is_a?(Octokit::ClientError)
|
|
164
|
+
|
|
165
|
+
error.response_status.to_i == 429
|
|
166
|
+
rescue NoMethodError
|
|
167
|
+
# A bare-raised error carries no response — and no quota status.
|
|
168
|
+
false
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# The seconds to sleep before the next call, budget-checked: one full
|
|
172
|
+
# hourly window is a legitimate wait; a ninth absorbed quota response,
|
|
173
|
+
# or a wait that would push the process past two windows, means
|
|
174
|
+
# something is systemically wrong — give up loudly instead of
|
|
175
|
+
# blocking the runner forever.
|
|
176
|
+
def rate_limit_wait(error, target, attempts) # rubocop:disable Metrics/MethodLength
|
|
177
|
+
if attempts > RATE_LIMIT_ATTEMPTS
|
|
178
|
+
raise RateLimitBudgetExhausted,
|
|
179
|
+
"github #{target}: absorbed #{RATE_LIMIT_ATTEMPTS} rate-limit responses without the window opening — " \
|
|
180
|
+
"the per-call budget is exhausted; re-run the leg (the token's quota resets hourly)"
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
wait = rate_limit_seconds(error, attempts)
|
|
184
|
+
return wait if monotonic_now + wait <= rate_limit_deadline
|
|
185
|
+
|
|
186
|
+
raise RateLimitBudgetExhausted,
|
|
187
|
+
"github #{target}: the next rate-limit window is #{wait}s out but this process has a " \
|
|
188
|
+
"#{RATE_LIMIT_BUDGET}s ride-out budget — two full windows spent; " \
|
|
189
|
+
"giving up loudly instead of blocking forever"
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def rate_limit_deadline
|
|
193
|
+
@rate_limit_deadline ||= monotonic_now + RATE_LIMIT_BUDGET
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# The reset header names the window's end as a wall-clock epoch (plus
|
|
197
|
+
# a small settle); a stale or absent reset falls back to Retry-After,
|
|
198
|
+
# then to the capped exponential backoff. Faraday's real headers are
|
|
199
|
+
# case-insensitive; read both spellings so a plain hash (the spec
|
|
200
|
+
# fake) serves the same values.
|
|
201
|
+
def rate_limit_seconds(error, attempts) # rubocop:disable Metrics/AbcSize
|
|
202
|
+
headers = begin
|
|
203
|
+
error.response_headers || {}
|
|
204
|
+
rescue NoMethodError
|
|
205
|
+
{} # a bare-raised error carries no response headers
|
|
206
|
+
end
|
|
207
|
+
reset = (headers["x-ratelimit-reset"] || headers["X-RateLimit-Reset"]).to_i
|
|
208
|
+
return reset - Time.now.to_i + RATE_LIMIT_SETTLE if reset > Time.now.to_i
|
|
209
|
+
|
|
210
|
+
retry_after = (headers["retry-after"] || headers["Retry-After"]).to_i
|
|
211
|
+
return retry_after + RATE_LIMIT_SETTLE if retry_after.positive?
|
|
212
|
+
|
|
213
|
+
[RATE_LIMIT_BACKOFF_BASE * (2**(attempts - 1)), RATE_LIMIT_BACKOFF_CAP].min
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# Wall-clock reads for the deadline accounting — monotonic, immune to
|
|
217
|
+
# clock smear on the runner.
|
|
218
|
+
def monotonic_now
|
|
219
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
end
|
|
@@ -65,6 +65,12 @@ module TebakoRelease
|
|
|
65
65
|
# declared through TebakoRelease.configure (or TEBAKO_RELEASE_REPO),
|
|
66
66
|
# never by editing a copy.
|
|
67
67
|
class Signer # rubocop:disable Metrics/ClassLength
|
|
68
|
+
# Every GitHub call below rides the shared convergence wrapper (quota
|
|
69
|
+
# ride-outs, transient retries, the release-visibility and
|
|
70
|
+
# deletion-propagation budgets) — tebako-release#14's sign legs died
|
|
71
|
+
# on terminal 403s mid-convergence; no call escapes the wrapper now.
|
|
72
|
+
include Convergence
|
|
73
|
+
|
|
68
74
|
# Armed-but-cannot, provenance, and coverage failures: the pass never
|
|
69
75
|
# ships a partially signed release silently.
|
|
70
76
|
class SigningGateError < StandardError; end
|
|
@@ -97,6 +103,16 @@ module TebakoRelease
|
|
|
97
103
|
# "no assets"); bounded re-asks, then the named failure stands.
|
|
98
104
|
SERVED_BYTES_DELAYS = [5, 10, 20, 40, 80].freeze
|
|
99
105
|
|
|
106
|
+
# The young-release wordings the download re-ask loop retries (the
|
|
107
|
+
# operation class b): the name came FROM the release listing (or the
|
|
108
|
+
# leg just published it), so gh's "no assets to download" — and a fresh
|
|
109
|
+
# release object's own "release not found" (the 2026-10-02/03
|
|
110
|
+
# force_rebuild's sidecar-fetch deaths, tebako-release#13) — are the
|
|
111
|
+
# read path trailing the write, never absence. Every other named
|
|
112
|
+
# failure (auth, usage, a genuinely gone release past the budget)
|
|
113
|
+
# raises at once.
|
|
114
|
+
YOUNG_RELEASE_WORDINGS = ["no assets to download", "release not found"].freeze
|
|
115
|
+
|
|
100
116
|
def initialize(client: nil, executor: nil, env: ENV, config: nil)
|
|
101
117
|
@env = env
|
|
102
118
|
@config = config || TebakoRelease.config
|
|
@@ -123,11 +139,12 @@ module TebakoRelease
|
|
|
123
139
|
work = Pathname.new(dir)
|
|
124
140
|
tool = fetch_verified_tool(work)
|
|
125
141
|
key_file = materialize_key(work)
|
|
126
|
-
assets = @client.release_assets(release.url)
|
|
142
|
+
assets = with_transient_retries("release assets") { @client.release_assets(release.url) }
|
|
127
143
|
targets = signature_targets(assets.map(&:name))
|
|
128
144
|
stale = stale_targets(targets, assets)
|
|
129
145
|
puts "#{@tag}: #{targets.size} signature targets, #{stale.size} need (re)signing"
|
|
130
146
|
by_name = assets.to_h { |asset| [asset.name, asset] }
|
|
147
|
+
converged = []
|
|
131
148
|
stale.each do |name|
|
|
132
149
|
digest = listed_sha(by_name.fetch(name))
|
|
133
150
|
if digest.empty?
|
|
@@ -136,9 +153,10 @@ module TebakoRelease
|
|
|
136
153
|
"signing needs the listing's sha256 to prove the signed bytes are the served bytes"
|
|
137
154
|
end
|
|
138
155
|
|
|
139
|
-
sign_one(work, key_file, tool, release, name, digest)
|
|
156
|
+
sign_one(work, key_file, tool, release, name, digest, by_name["#{name}.asc"])
|
|
157
|
+
converged << name
|
|
140
158
|
end
|
|
141
|
-
assert_coverage!(
|
|
159
|
+
assert_coverage!(targets, stale, converged)
|
|
142
160
|
end
|
|
143
161
|
:signed
|
|
144
162
|
end
|
|
@@ -207,9 +225,30 @@ module TebakoRelease
|
|
|
207
225
|
/\Atebako-pkg-\d+\.\d+\.\d+-#{Regexp.escape(tool_host_id)}#{Regexp.escape(suffix)}\z/
|
|
208
226
|
end
|
|
209
227
|
|
|
228
|
+
# Read-after-create convergence (the operation class b): on a fresh
|
|
229
|
+
# per-line release object a sign leg can schedule AHEAD of the publish
|
|
230
|
+
# leg's create becoming readable — the 2026-10-02/03 force_rebuild
|
|
231
|
+
# fan-out died on exactly this. Poll for visibility on the bounded
|
|
232
|
+
# budget (each poll rides the wrapper, so a quota burst stretches the
|
|
233
|
+
# wait inside the call), then the named failure stands.
|
|
210
234
|
def find_release
|
|
211
|
-
|
|
235
|
+
find_release_once || await_release_visibility
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def find_release_once
|
|
239
|
+
with_transient_retries("release for tag #{@tag}") { @client.release_for_tag(@config.repo, @tag) }
|
|
212
240
|
rescue Octokit::NotFound
|
|
241
|
+
nil
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def await_release_visibility
|
|
245
|
+
RELEASE_VISIBILITY_DELAYS.each do |pause|
|
|
246
|
+
puts "#{@tag}: the release object is not visible yet (a concurrent leg just created it) — " \
|
|
247
|
+
"re-asking in #{pause}s"
|
|
248
|
+
sleep pause
|
|
249
|
+
release = find_release_once
|
|
250
|
+
return release if release
|
|
251
|
+
end
|
|
213
252
|
raise SigningGateError, "NAMED FAILURE: no release found for tag #{@tag} — nothing to sign"
|
|
214
253
|
end
|
|
215
254
|
|
|
@@ -234,8 +273,10 @@ module TebakoRelease
|
|
|
234
273
|
# provenance-pinned: downloaded with its .sha256 sidecar and executed
|
|
235
274
|
# only when the digest matches.
|
|
236
275
|
def fetch_verified_tool(work) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
237
|
-
latest =
|
|
238
|
-
|
|
276
|
+
latest = with_transient_retries("latest #{@config.tool_repo} release") do
|
|
277
|
+
@client.latest_release(@config.tool_repo)
|
|
278
|
+
end
|
|
279
|
+
names = with_transient_retries("tool release assets") { @client.release_assets(latest.url) }.map(&:name)
|
|
239
280
|
tool_name = names.find { |name| name.match?(tool_asset_pattern) }
|
|
240
281
|
unless tool_name
|
|
241
282
|
raise SigningGateError,
|
|
@@ -265,7 +306,7 @@ module TebakoRelease
|
|
|
265
306
|
# verify against the freshly registered key, then converge the .asc onto
|
|
266
307
|
# the release. The digest is the no-fold rule's provenance: the signed
|
|
267
308
|
# bytes are provably the bytes the release serves.
|
|
268
|
-
def sign_one(work, key_file, tool, release, name, digest) # rubocop:disable Metrics/AbcSize, Metrics/ParameterLists
|
|
309
|
+
def sign_one(work, key_file, tool, release, name, digest, existing_asc) # rubocop:disable Metrics/AbcSize, Metrics/ParameterLists
|
|
269
310
|
local = Pathname.new(local_packages_dir).join(name)
|
|
270
311
|
target = if local.exist? && Digest::SHA256.file(local).hexdigest == digest
|
|
271
312
|
local
|
|
@@ -274,7 +315,7 @@ module TebakoRelease
|
|
|
274
315
|
end
|
|
275
316
|
@executor.run(tool, "sign", "--key-file", key_file.to_s, "--no-sums", name, chdir: File.dirname(target.to_s))
|
|
276
317
|
@executor.run(tool, "verify", name, chdir: File.dirname(target.to_s))
|
|
277
|
-
converge_asc(release, Pathname.new(File.join(File.dirname(target.to_s), "#{name}.asc")))
|
|
318
|
+
converge_asc(release, Pathname.new(File.join(File.dirname(target.to_s), "#{name}.asc")), existing_asc)
|
|
278
319
|
puts "#{name}: signed and converged"
|
|
279
320
|
end
|
|
280
321
|
|
|
@@ -293,32 +334,40 @@ module TebakoRelease
|
|
|
293
334
|
"#{name} downloaded with sha256 #{actual}, the listing says #{digest}"
|
|
294
335
|
end
|
|
295
336
|
|
|
296
|
-
# The bounded re-ask for the young-release-object lag: the
|
|
297
|
-
#
|
|
298
|
-
# trailing the listing, never absence — it retries; every other named
|
|
299
|
-
# failure (auth, usage, a genuinely gone release) raises at once.
|
|
337
|
+
# The bounded re-ask for the young-release-object lag: the wordings
|
|
338
|
+
# above retry; everything else raises at once.
|
|
300
339
|
def download_when_served(dir, name)
|
|
301
340
|
pauses = SERVED_BYTES_DELAYS.dup
|
|
302
341
|
begin
|
|
303
342
|
@executor.run("gh", "release", "download", @tag, "--repo", @config.repo,
|
|
304
343
|
"--pattern", name, "--dir", dir.to_s, "--clobber")
|
|
305
344
|
rescue SigningGateError => e
|
|
306
|
-
raise unless
|
|
345
|
+
raise unless young_release_failure?(e) && (pause = pauses.shift)
|
|
307
346
|
|
|
308
|
-
puts "#{name}
|
|
347
|
+
puts "#{name}: the release read path has not converged on the fresh object yet — re-asking in #{pause}s"
|
|
309
348
|
sleep pause
|
|
310
349
|
retry
|
|
311
350
|
end
|
|
312
351
|
end
|
|
313
352
|
|
|
353
|
+
def young_release_failure?(error)
|
|
354
|
+
YOUNG_RELEASE_WORDINGS.any? { |wording| error.message.include?(wording) }
|
|
355
|
+
end
|
|
356
|
+
|
|
314
357
|
# A tiny metadata upload, converged: replace whatever the name serves,
|
|
315
|
-
# then poll until the
|
|
316
|
-
#
|
|
317
|
-
|
|
358
|
+
# then poll until the served record's digest is our bytes. The poll
|
|
359
|
+
# rides the SINGLE-ASSET endpoint (one request per cycle — never a
|
|
360
|
+
# re-paginated listing: at catalog size the full listing is ~5 pages,
|
|
361
|
+
# and ~90 legs polling it every cycle is what drained the shared
|
|
362
|
+
# token's hourly budget mid-fleet, tebako-release#14). The held record
|
|
363
|
+
# flows between cycles: the pass-start listing's stale record first,
|
|
364
|
+
# then each upload's landed record.
|
|
365
|
+
def converge_asc(release, asc_file, existing) # rubocop:disable Metrics/MethodLength
|
|
318
366
|
sha = Digest::SHA256.file(asc_file).hexdigest
|
|
367
|
+
asset = existing
|
|
319
368
|
converged = false
|
|
320
369
|
CONVERGENCE_DELAYS.each do |pause|
|
|
321
|
-
converged =
|
|
370
|
+
converged, asset = converge_asc_cycle(release, asc_file, sha, asset)
|
|
322
371
|
break if converged
|
|
323
372
|
|
|
324
373
|
wait = Signer.jittered(pause)
|
|
@@ -328,31 +377,103 @@ module TebakoRelease
|
|
|
328
377
|
raise SigningGateError, "NAMED FAILURE: #{asc_file.basename} did not converge on #{@tag}" unless converged
|
|
329
378
|
end
|
|
330
379
|
|
|
331
|
-
# One convergence cycle: the
|
|
332
|
-
#
|
|
333
|
-
#
|
|
334
|
-
#
|
|
335
|
-
#
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
380
|
+
# One convergence cycle: the held record already serving our bytes is
|
|
381
|
+
# done; a stale record is deleted — its absence awaited on the same
|
|
382
|
+
# single-asset endpoint before the re-upload (the delete-then-upload
|
|
383
|
+
# class, tebako-release#12's wedge lesson) — and the upload's fresh
|
|
384
|
+
# record feeds the next cycle's poll. A 422 mid-replace carrying
|
|
385
|
+
# already_exists is the deletion-propagation race (or a concurrent
|
|
386
|
+
# leg's landed upload): re-list ONCE to learn the conflicting record,
|
|
387
|
+
# then ride it as not-yet-converged. Any other 422 is a validation
|
|
388
|
+
# error, not the race — fail fast and named, never grind.
|
|
389
|
+
# Returns [converged, record-to-hold].
|
|
390
|
+
def converge_asc_cycle(release, asc_file, sha, asset) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
391
|
+
name = asc_file.basename.to_s
|
|
392
|
+
digest = asset && served_sha(asset, name)
|
|
393
|
+
return [true, asset] if digest == sha
|
|
394
|
+
|
|
395
|
+
asset = nil if asset && digest.nil? # the held record left the store — the name is free
|
|
396
|
+
if asset
|
|
397
|
+
with_transient_retries("delete #{name}") { @client.delete_release_asset(asset.id) }
|
|
398
|
+
await_asc_absence(asset, name)
|
|
399
|
+
end
|
|
400
|
+
asset = with_transient_retries("upload #{name}") do
|
|
401
|
+
@client.upload_asset(release.url, asc_file.to_s,
|
|
402
|
+
content_type: "text/plain",
|
|
403
|
+
name: name)
|
|
404
|
+
end
|
|
405
|
+
[false, asset]
|
|
345
406
|
rescue Octokit::UnprocessableEntity => e
|
|
346
|
-
|
|
407
|
+
unless e.message.include?("already_exists")
|
|
408
|
+
raise SigningGateError,
|
|
409
|
+
"NAMED FAILURE: the #{name} upload was rejected (#{e.message}) — not the deletion-propagation " \
|
|
410
|
+
"race; refusing to grind on a validation error"
|
|
411
|
+
end
|
|
412
|
+
puts "#{name}: replace raced the 422 propagation window (#{e.class}) — cycling"
|
|
413
|
+
[false, find_asc_asset(release, name)]
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
# The record's currently-served digest, read on the single-asset
|
|
417
|
+
# endpoint; nil when the record is gone (our delete propagated, or it
|
|
418
|
+
# never committed).
|
|
419
|
+
def served_sha(asset, name)
|
|
420
|
+
record = with_transient_retries("asset #{name} state") { @client.release_asset(asset.url) }
|
|
421
|
+
listed_sha(record)
|
|
422
|
+
rescue Octokit::NotFound
|
|
423
|
+
nil
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
# The delete is visible only when the single-asset read 404s — the
|
|
427
|
+
# listing flaps independently of the authoritative store (#12's night),
|
|
428
|
+
# so the listing is never probed here. Over the deadline the leg fails
|
|
429
|
+
# fast and named: a resumable red beats a job-timeout wedge.
|
|
430
|
+
def await_asc_absence(asset, name) # rubocop:disable Metrics/MethodLength
|
|
431
|
+
deadline = monotonic_now + DELETION_PROPAGATION_DEADLINE
|
|
432
|
+
until asc_absent?(asset)
|
|
433
|
+
if monotonic_now >= deadline
|
|
434
|
+
raise SigningGateError,
|
|
435
|
+
"NAMED FAILURE: the deletion of #{name} has not propagated within " \
|
|
436
|
+
"#{DELETION_PROPAGATION_DEADLINE}s — the asset name stays 422-blocked server-side; " \
|
|
437
|
+
"re-run the sign leg"
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
puts "Waiting for the deletion of #{name} to propagate..."
|
|
441
|
+
sleep DELETION_PROPAGATION_POLL_INTERVAL
|
|
442
|
+
end
|
|
443
|
+
puts "#{name} left the listing; giving the name #{DELETION_PROPAGATION_GRACE}s to free up server-side"
|
|
444
|
+
sleep DELETION_PROPAGATION_GRACE
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
def asc_absent?(asset)
|
|
448
|
+
with_transient_retries("asset #{asset.id} existence") { @client.release_asset(asset.url) }
|
|
347
449
|
false
|
|
450
|
+
rescue Octokit::NotFound
|
|
451
|
+
true
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
# The recovery read behind a raced 422: ONE re-listing to learn the
|
|
455
|
+
# conflicting record (our own lagging delete or a concurrent leg's
|
|
456
|
+
# landed upload) so the next cycle's poll rides the single-asset
|
|
457
|
+
# endpoint again.
|
|
458
|
+
def find_asc_asset(release, name)
|
|
459
|
+
with_transient_retries("release assets") { @client.release_assets(release.url) }
|
|
460
|
+
.find { |asset| asset.name == name }
|
|
348
461
|
end
|
|
349
462
|
|
|
350
|
-
# The coverage assertion
|
|
351
|
-
#
|
|
463
|
+
# The coverage assertion, without a re-listing (tebako-release#3): a
|
|
464
|
+
# target is covered when its .asc was already fresh at the pass-start
|
|
465
|
+
# listing (not stale) or its upload was converged this pass — and
|
|
466
|
+
# converge_asc proves convergence on the single-asset endpoint with
|
|
467
|
+
# the served digest equal to our bytes, which is exactly the server
|
|
468
|
+
# truth a fresh listing would re-read. The full listing at this point
|
|
469
|
+
# cost ~5 pages per leg at catalog size with nothing to add: legs own
|
|
470
|
+
# disjoint name sets (SIGN_ONLY_STEMS), so no other writer can touch
|
|
471
|
+
# a name this pass covers. The computation stays: a target that is
|
|
472
|
+
# neither fresh-at-start nor converged is a named failure, never a
|
|
352
473
|
# quiet state.
|
|
353
|
-
def assert_coverage!(
|
|
354
|
-
|
|
355
|
-
missing = targets
|
|
474
|
+
def assert_coverage!(targets, stale, converged)
|
|
475
|
+
covered = (targets - stale) | converged
|
|
476
|
+
missing = targets - covered
|
|
356
477
|
return if missing.empty?
|
|
357
478
|
|
|
358
479
|
raise SigningGateError,
|
|
@@ -45,16 +45,17 @@ module TebakoRelease
|
|
|
45
45
|
# language version key/grammar, capability gates, DLL naming — flow
|
|
46
46
|
# through the Config/Adapter.
|
|
47
47
|
class Uploader # rubocop:disable Metrics/ClassLength
|
|
48
|
+
# Every GitHub call below rides the shared convergence wrapper (quota
|
|
49
|
+
# ride-outs, transient retries, the release-visibility and
|
|
50
|
+
# deletion-propagation budgets; RateLimitBudgetExhausted and the
|
|
51
|
+
# RATE_LIMIT_*/DELETION_PROPAGATION_* constants resolve from there).
|
|
52
|
+
include Convergence
|
|
53
|
+
|
|
48
54
|
# Named error (spec 00: named errors, never silent fallbacks): a release
|
|
49
55
|
# asset's deletion did not stop the name from being listed within the
|
|
50
56
|
# propagation deadline — the name stays 422-blocked server-side.
|
|
51
57
|
class DeletionPropagationTimeout < StandardError; end
|
|
52
58
|
|
|
53
|
-
# The rate-limit ride-out has a bound: two full hourly windows waited in
|
|
54
|
-
# one process means something is systemically wrong — give up loudly
|
|
55
|
-
# instead of blocking the runner forever.
|
|
56
|
-
class RateLimitBudgetExhausted < StandardError; end
|
|
57
|
-
|
|
58
59
|
# The era-2 release card (spec 18 C2): every runtime package carries a
|
|
59
60
|
# builder-emitted `<package>.contract.yaml` sidecar (contract_era,
|
|
60
61
|
# image_layout, mount_root, built_from) that manifest_entry folds into
|
|
@@ -232,7 +233,7 @@ module TebakoRelease
|
|
|
232
233
|
def read_previous_manifest
|
|
233
234
|
release = find_release
|
|
234
235
|
asset = release && find_asset(release, "manifest.json")
|
|
235
|
-
asset && with_transient_retries { download_asset_json(asset) }
|
|
236
|
+
asset && with_transient_retries("previous manifest.json") { download_asset_json(asset) }
|
|
236
237
|
end
|
|
237
238
|
|
|
238
239
|
def deep_symbolize(value)
|
|
@@ -244,7 +245,7 @@ module TebakoRelease
|
|
|
244
245
|
end
|
|
245
246
|
|
|
246
247
|
def download_asset_json(asset)
|
|
247
|
-
JSON.parse(with_transient_retries { @client.get(asset.browser_download_url) }.to_s)
|
|
248
|
+
JSON.parse(with_transient_retries("download #{asset.name}") { @client.get(asset.browser_download_url) }.to_s)
|
|
248
249
|
end
|
|
249
250
|
|
|
250
251
|
def expected_package_names # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
@@ -278,28 +279,46 @@ module TebakoRelease
|
|
|
278
279
|
# (422s resolve by content inside perform_upload), then verify what the
|
|
279
280
|
# edge serves. The loop repeats until the edge converges or the budget
|
|
280
281
|
# runs out — a metadata rewrite never dies on the first bad cycle.
|
|
281
|
-
# The convergence cycle sleeps, ~46 min of patience. Tonight's backend
|
|
282
|
-
# (2026-08-03) blocked a deleted name's re-upload for 4.5+ HOURS.
|
|
283
282
|
# Since the de-rendezvous (spec 13 §2a) a leg rewrites only
|
|
284
283
|
# its OWN packages' shards/sidecars — every name it touches is one it
|
|
285
284
|
# owns, so a convergence grind can never rendezvous with another leg;
|
|
286
285
|
# an incident night is an incident night, and the legs run concurrently.
|
|
287
286
|
METADATA_CONVERGENCE_DELAYS = [5, 15, 30, 60, 120, 240, 480, 600, 600, 600].freeze
|
|
288
287
|
|
|
289
|
-
|
|
288
|
+
# The TOTAL wall-clock bound on one replace (tebako-release#12): on a
|
|
289
|
+
# pathological backend night a deleted name never frees and every
|
|
290
|
+
# re-upload 422s — each cycle's delete-wait and backoff re-arm per
|
|
291
|
+
# iteration, so without a deadline the loop grinds into the CI job
|
|
292
|
+
# timeout (the 0.16.32 smoke burned both macos legs' full 60 minutes
|
|
293
|
+
# on one shard). Fifteen minutes covers a healthy night's propagation
|
|
294
|
+
# (the 0.16.8 wedge freed in ~15 s; 2026-08-03 took minutes); past it
|
|
295
|
+
# the replace cannot land tonight and the named error says so — a fast
|
|
296
|
+
# red leg is resumable for free, a job-timeout death is not.
|
|
297
|
+
METADATA_CONVERGENCE_DEADLINE = 900
|
|
298
|
+
|
|
299
|
+
def force_upload(release, file, delays: METADATA_CONVERGENCE_DELAYS) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
290
300
|
filename = file.basename.to_s
|
|
291
301
|
sha = Digest::SHA256.file(file).hexdigest
|
|
302
|
+
deadline = monotonic_now + METADATA_CONVERGENCE_DEADLINE
|
|
292
303
|
converged = false
|
|
293
304
|
delays.each do |pause|
|
|
294
305
|
converged = metadata_converged?(release, file, filename, sha)
|
|
295
306
|
break if converged
|
|
296
307
|
|
|
308
|
+
raise metadata_deadline_error(filename) if monotonic_now >= deadline
|
|
309
|
+
|
|
297
310
|
puts "#{filename} has not converged on the release yet; cycling in #{pause}s"
|
|
298
|
-
sleep pause
|
|
311
|
+
sleep [pause, deadline - monotonic_now].min
|
|
299
312
|
end
|
|
300
313
|
raise "could not converge #{filename} on the release within the metadata budget" unless converged
|
|
301
314
|
end
|
|
302
315
|
|
|
316
|
+
def metadata_deadline_error(filename)
|
|
317
|
+
"could not converge #{filename} on the release within the #{METADATA_CONVERGENCE_DEADLINE}s " \
|
|
318
|
+
"convergence deadline — the release backend is wedged on this name tonight (an unpropagated " \
|
|
319
|
+
"delete holds it 422-blocked); re-run this leg, a healthy backend converges in one cycle"
|
|
320
|
+
end
|
|
321
|
+
|
|
303
322
|
# One convergence cycle: read-first (the edge already serves our bytes
|
|
304
323
|
# → done), replace when listed, upload with the short budget (422s
|
|
305
324
|
# resolve by content inside perform_upload), then verify what the edge
|
|
@@ -353,7 +372,7 @@ module TebakoRelease
|
|
|
353
372
|
# correct accept (content is content); absent/stale bytes only mean
|
|
354
373
|
# "take the mutation path".
|
|
355
374
|
def served_content(filename)
|
|
356
|
-
with_transient_retries { @client.get(download_url(filename)) }.to_s
|
|
375
|
+
with_transient_retries("served bytes #{filename}") { @client.get(download_url(filename)) }.to_s
|
|
357
376
|
rescue Octokit::NotFound
|
|
358
377
|
nil
|
|
359
378
|
end
|
|
@@ -401,27 +420,71 @@ module TebakoRelease
|
|
|
401
420
|
# matrix legs of one publish run race here (spec 13 §2a's
|
|
402
421
|
# de-rendezvous: no leg waits on another). The loser's create 422s on
|
|
403
422
|
# the taken tag; it polls for the winner's release to become visible
|
|
404
|
-
# and rides it
|
|
405
|
-
|
|
406
|
-
|
|
423
|
+
# and rides it (RELEASE_VISIBILITY_DELAYS — each poll rides the
|
|
424
|
+
# wrapper, so a quota burst stretches the wait inside the call instead
|
|
425
|
+
# of burning polls). Creation is write-once, never a wedge.
|
|
407
426
|
def get_or_create_release # rubocop:disable Naming/AccessorMethodName
|
|
408
427
|
puts "Looking for release with tag: #{@tag}"
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
428
|
+
release = find_release
|
|
429
|
+
return release if release
|
|
430
|
+
|
|
431
|
+
canonicalize_created_release(create_release_race_safe)
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
# GitHub does not enforce tag_name uniqueness atomically: two
|
|
435
|
+
# concurrent creates can BOTH commit (200, never the loser's 422), and
|
|
436
|
+
# the tag then resolves to one object while the other — same
|
|
437
|
+
# tag_name, different id — stays API-addressable. A leg holding that
|
|
438
|
+
# ghost uploads to it, reports success, and its bytes are unreachable
|
|
439
|
+
# (tebako-release#19: the v0.17.1 publish's seven arm64 assets, found
|
|
440
|
+
# only because another leg's audit named them missing).
|
|
441
|
+
#
|
|
442
|
+
# So a create is never trusted on its own answer: the tag's own
|
|
443
|
+
# resolution is re-read and adopted. The leg then uploads where
|
|
444
|
+
# consumers look, and a duplicate is named with the remedy — it is
|
|
445
|
+
# never deleted here (a delete is the owner's call, and the ghost can
|
|
446
|
+
# only ever hold orphaned bytes).
|
|
447
|
+
def canonicalize_created_release(created)
|
|
448
|
+
canonical = await_tag_resolution
|
|
449
|
+
return canonical if canonical.id == created.id
|
|
450
|
+
|
|
451
|
+
puts "::warning::#{@tag} resolves to release #{canonical.id}, but this leg created #{created.id} — " \
|
|
452
|
+
"a duplicate release object exists for the tag; uploading to #{canonical.id}. " \
|
|
453
|
+
"Delete #{created.id} (it holds no reachable bytes)."
|
|
454
|
+
canonical
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
# The tag's resolution, polled over the release-visibility budget: a
|
|
458
|
+
# create that lands is not instantly readable by tag.
|
|
459
|
+
def await_tag_resolution
|
|
460
|
+
RELEASE_VISIBILITY_DELAYS.each do |pause|
|
|
461
|
+
release = find_release
|
|
462
|
+
return release if release
|
|
463
|
+
|
|
464
|
+
sleep pause
|
|
465
|
+
end
|
|
466
|
+
raise "the release for #{@tag} was created but the tag does not resolve to any release — " \
|
|
467
|
+
"the create's answer and the tag disagree; delete the stray release object and re-run this leg"
|
|
412
468
|
end
|
|
413
469
|
|
|
414
470
|
# A rescue clause's own exceptions never re-enter the sibling rescues —
|
|
415
|
-
# the create's 422 handling lives in its own method.
|
|
471
|
+
# the create's 422 handling lives in its own method. The POST itself
|
|
472
|
+
# rides the wrapper: a quota response mid-fan-out (the 2026-10-03
|
|
473
|
+
# fleet's terminal `POST /releases: 403`s) sleeps the window out, and
|
|
474
|
+
# a timed-out create that LANDED server-side 422s the retry — the
|
|
475
|
+
# race-safe poll below then rides the landed release, exactly the
|
|
476
|
+
# lost-race shape.
|
|
416
477
|
def create_release_race_safe # rubocop:disable Metrics/MethodLength
|
|
417
478
|
puts "Creating new release for tag: #{@tag}"
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
479
|
+
with_transient_retries("create release #{@tag}") do
|
|
480
|
+
@client.create_release(@config.repo, @tag,
|
|
481
|
+
name: @release_title,
|
|
482
|
+
body: release_notes)
|
|
483
|
+
end
|
|
421
484
|
rescue Octokit::UnprocessableEntity
|
|
422
485
|
# A concurrent leg won the create. Poll for its release to become
|
|
423
486
|
# visible, then ride it — never re-attempt the create.
|
|
424
|
-
|
|
487
|
+
RELEASE_VISIBILITY_DELAYS.each do |pause|
|
|
425
488
|
sleep pause
|
|
426
489
|
release = find_release
|
|
427
490
|
return release if release
|
|
@@ -433,7 +496,7 @@ module TebakoRelease
|
|
|
433
496
|
# The read-only lookup (the previous-entry reads + the audit read the
|
|
434
497
|
# existing release): nil when the tag has no release, never creates one.
|
|
435
498
|
def find_release
|
|
436
|
-
with_transient_retries { @client.release_for_tag(@config.repo, @tag) }
|
|
499
|
+
with_transient_retries("release for tag #{@tag}") { @client.release_for_tag(@config.repo, @tag) }
|
|
437
500
|
rescue Octokit::NotFound
|
|
438
501
|
nil
|
|
439
502
|
end
|
|
@@ -765,7 +828,7 @@ module TebakoRelease
|
|
|
765
828
|
end
|
|
766
829
|
|
|
767
830
|
puts "#{filename}: the landed asset's content disagrees — deleting the partial/stale asset before the retry"
|
|
768
|
-
with_transient_retries { @client.delete_release_asset(asset.id) }
|
|
831
|
+
with_transient_retries("delete #{filename}") { @client.delete_release_asset(asset.id) }
|
|
769
832
|
drop_asset_from_memo(asset.id) # the deleted asset leaves the listing
|
|
770
833
|
# The name stays 422-blocked until the delete propagates — poll for
|
|
771
834
|
# the absence so the retry's POST actually lands (the v0.16.3 gnu
|
|
@@ -813,7 +876,7 @@ module TebakoRelease
|
|
|
813
876
|
|
|
814
877
|
def landed_content(release, filename)
|
|
815
878
|
asset = find_asset(release, filename)
|
|
816
|
-
return with_transient_retries { @client.get(asset.browser_download_url) }.to_s if asset
|
|
879
|
+
return with_transient_retries("download #{filename}") { @client.get(asset.browser_download_url) }.to_s if asset
|
|
817
880
|
|
|
818
881
|
served_content(filename)
|
|
819
882
|
rescue Octokit::NotFound
|
|
@@ -831,7 +894,7 @@ module TebakoRelease
|
|
|
831
894
|
# 2026-08-30) stay with perform_upload (escalating delays, 422-by-content
|
|
832
895
|
# resolution, the per-asset budget) — ONE retry layer, not two.
|
|
833
896
|
def upload_once(release, package, filename)
|
|
834
|
-
asset = with_rate_limit_rideout do
|
|
897
|
+
asset = with_rate_limit_rideout("upload #{filename}") do
|
|
835
898
|
@client.upload_asset(release.url, package.to_s,
|
|
836
899
|
content_type: "application/octet-stream",
|
|
837
900
|
name: filename)
|
|
@@ -1118,7 +1181,8 @@ module TebakoRelease
|
|
|
1118
1181
|
end
|
|
1119
1182
|
|
|
1120
1183
|
def download_shard_entry(asset)
|
|
1121
|
-
|
|
1184
|
+
body = with_transient_retries("shard #{asset.name}") { @client.get(asset.browser_download_url) }.to_s
|
|
1185
|
+
deep_symbolize(JSON.parse(body))
|
|
1122
1186
|
end
|
|
1123
1187
|
|
|
1124
1188
|
# The package stems a set of entries covers (exe + .tfs/.dll facets).
|
|
@@ -1365,13 +1429,31 @@ module TebakoRelease
|
|
|
1365
1429
|
end
|
|
1366
1430
|
|
|
1367
1431
|
# The non-executable artifacts a package is expected to carry: the
|
|
1368
|
-
# filesystem image everywhere, the runtime DLL on windows
|
|
1432
|
+
# filesystem image everywhere, and the runtime DLL on windows WHEN the
|
|
1433
|
+
# factory ships that facet (the ruby/python shape: the exe's imports
|
|
1434
|
+
# resolve against the PE sibling the store materializes). An
|
|
1435
|
+
# exec-cache runtime — the openjdk shape, julia among them — carries
|
|
1436
|
+
# the whole SDK tree (libjulia & co.) in the env image, which the
|
|
1437
|
+
# driver materializes host-side; it declares no DLL install name and
|
|
1438
|
+
# the gate must never demand the facet it never publishes.
|
|
1369
1439
|
def expected_facets(name)
|
|
1370
1440
|
facets = ["#{name}.tfs"]
|
|
1371
|
-
facets << "#{name}.dll" if name.include?("windows")
|
|
1441
|
+
facets << "#{name}.dll" if name.include?("windows") && dll_facet?(name)
|
|
1372
1442
|
facets
|
|
1373
1443
|
end
|
|
1374
1444
|
|
|
1445
|
+
# Whether the package owes a windows runtime-DLL facet, per the
|
|
1446
|
+
# adapter's dll_install_name declaration (nil → the runtime ships no
|
|
1447
|
+
# DLL facet). An unparseable name keeps the expectation — the closed
|
|
1448
|
+
# gate: a drifted name grammar must never silently shrink a release's
|
|
1449
|
+
# expected asset set.
|
|
1450
|
+
def dll_facet?(name)
|
|
1451
|
+
version, host_id = parse_package_filename(name)
|
|
1452
|
+
return true if version.nil?
|
|
1453
|
+
|
|
1454
|
+
!@config.adapter.dll_install_name(version, host_id).nil?
|
|
1455
|
+
end
|
|
1456
|
+
|
|
1375
1457
|
# The metadata a landed package owes: one sidecar per landed asset plus
|
|
1376
1458
|
# its shard — and, when signatures are required (spec 09 §5: no
|
|
1377
1459
|
# artifact is ever "covered by" another's signature), one `.asc` per
|
|
@@ -1382,11 +1464,13 @@ module TebakoRelease
|
|
|
1382
1464
|
expected.reject { |asset| present.include?(asset) }
|
|
1383
1465
|
end
|
|
1384
1466
|
|
|
1385
|
-
# The windows legs
|
|
1386
|
-
#
|
|
1387
|
-
# unowned DLL means a
|
|
1467
|
+
# The windows legs of a DLL-facet factory (ruby/python) ship the
|
|
1468
|
+
# runtime DLL as a third artifact: a windows executable without its
|
|
1469
|
+
# DLL cannot load any native extension, and an unowned DLL means a
|
|
1470
|
+
# leg's upload never landed. Exec-cache runtimes (the openjdk shape)
|
|
1471
|
+
# declare no facet and are never warned about (dll_facet?).
|
|
1388
1472
|
def report_dll_gaps(executables, dlls)
|
|
1389
|
-
windows = executables.select { |name| name.include?("windows") }
|
|
1473
|
+
windows = executables.select { |name| name.include?("windows") && dll_facet?(name) }
|
|
1390
1474
|
(windows - dlls).sort.each do |name|
|
|
1391
1475
|
puts "::warning::Runtime package #{name} has no runtime DLL (#{name}.dll); " \
|
|
1392
1476
|
"the windows runtime cannot load native extensions without it"
|
|
@@ -1413,35 +1497,19 @@ module TebakoRelease
|
|
|
1413
1497
|
existing = find_asset(release, filename)
|
|
1414
1498
|
return unless existing
|
|
1415
1499
|
|
|
1416
|
-
with_transient_retries { @client.delete_release_asset(existing.id) }
|
|
1500
|
+
with_transient_retries("delete #{filename}") { @client.delete_release_asset(existing.id) }
|
|
1417
1501
|
drop_asset_from_memo(existing.id) # the deleted asset leaves the listing
|
|
1418
1502
|
wait_for_absence_best_effort(release, filename, existing)
|
|
1419
1503
|
end
|
|
1420
1504
|
|
|
1421
1505
|
# GitHub asset deletion is only eventually consistent: a same-name
|
|
1422
|
-
# re-upload 422s until the delete propagates
|
|
1423
|
-
#
|
|
1424
|
-
#
|
|
1425
|
-
#
|
|
1426
|
-
#
|
|
1427
|
-
#
|
|
1428
|
-
#
|
|
1429
|
-
# The deadline matches the OBSERVED propagation window: the 2026-08-29
|
|
1430
|
-
# publish watched a deleted name stay 422-blocked well past the old
|
|
1431
|
-
# 60 s — past the per-asset 300 s budget once. Three minutes of polling
|
|
1432
|
-
# (single-asset reads, never a re-listing) covers the incident class; a
|
|
1433
|
-
# name still held after that is wedged, and the caller's
|
|
1434
|
-
# retry/convergence budget rides it out.
|
|
1435
|
-
DELETION_PROPAGATION_POLL_INTERVAL = 2
|
|
1436
|
-
DELETION_PROPAGATION_DEADLINE = 180
|
|
1437
|
-
# The listing's truth frees the name BEFORE the upload validator's
|
|
1438
|
-
# replica does: on the 0.16.8 publish a same-name POST kept 422ing
|
|
1439
|
-
# (Validation Failed / code: already_exists / field: name) ~15 s PAST
|
|
1440
|
-
# the deletion's visible absence — the manual repair that worked was
|
|
1441
|
-
# "gone, grace, then upload". Every confirmed absence pays this grace
|
|
1442
|
-
# before the next POST.
|
|
1443
|
-
DELETION_PROPAGATION_GRACE = 15
|
|
1444
|
-
|
|
1506
|
+
# re-upload 422s until the delete propagates. Poll for the absence,
|
|
1507
|
+
# SLEEPING between polls, under an overall wall-clock deadline; when
|
|
1508
|
+
# propagation outlasts the deadline the named error fires — the wait
|
|
1509
|
+
# never spins and never silently gives up (the 2026-08-20 publish
|
|
1510
|
+
# burned its whole job timeout on a wait whose outcome nobody could
|
|
1511
|
+
# act on). The poll interval, deadline, and grace constants live in
|
|
1512
|
+
# Convergence — the signer shares the discipline.
|
|
1445
1513
|
def wait_for_absence(release, filename, asset, deadline: DELETION_PROPAGATION_DEADLINE) # rubocop:disable Metrics/MethodLength
|
|
1446
1514
|
started = monotonic_now
|
|
1447
1515
|
loop do
|
|
@@ -1474,7 +1542,9 @@ module TebakoRelease
|
|
|
1474
1542
|
# request window mid-publish. The real API always hands listed assets an
|
|
1475
1543
|
# api url; the fallback rebuilds it from the release url.
|
|
1476
1544
|
def asset_deleted?(release, asset)
|
|
1477
|
-
with_transient_retries
|
|
1545
|
+
with_transient_retries("asset #{asset.id} existence") do
|
|
1546
|
+
@client.release_asset(asset.url || "#{release.url}/assets/#{asset.id}")
|
|
1547
|
+
end
|
|
1478
1548
|
false
|
|
1479
1549
|
rescue Octokit::NotFound
|
|
1480
1550
|
true
|
|
@@ -1490,12 +1560,6 @@ module TebakoRelease
|
|
|
1490
1560
|
puts "::warning::#{e.message}"
|
|
1491
1561
|
end
|
|
1492
1562
|
|
|
1493
|
-
# Wall-clock reads for the deadline accounting — monotonic, immune to
|
|
1494
|
-
# clock smear on the runner.
|
|
1495
|
-
def monotonic_now
|
|
1496
|
-
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
1497
|
-
end
|
|
1498
|
-
|
|
1499
1563
|
# release.assets is an embedded array capped at 30 entries, and a raw
|
|
1500
1564
|
# rels[:assets].get is NOT auto-paginated either (auto_paginate covers
|
|
1501
1565
|
# client methods, not Sawyer rel gets) — with 100+ assets most lookups
|
|
@@ -1509,10 +1573,10 @@ module TebakoRelease
|
|
|
1509
1573
|
# exist within a run.
|
|
1510
1574
|
def all_assets(release)
|
|
1511
1575
|
@all_assets ||= begin
|
|
1512
|
-
page = with_transient_retries { release.rels[:assets].get }
|
|
1576
|
+
page = with_transient_retries("asset listing") { release.rels[:assets].get }
|
|
1513
1577
|
assets = page.data
|
|
1514
1578
|
while (nxt = page.rels[:next])
|
|
1515
|
-
page = with_transient_retries { nxt.get }
|
|
1579
|
+
page = with_transient_retries("asset listing page") { nxt.get }
|
|
1516
1580
|
assets += page.data
|
|
1517
1581
|
end
|
|
1518
1582
|
assets
|
|
@@ -1533,89 +1597,6 @@ module TebakoRelease
|
|
|
1533
1597
|
all_assets(release).find { |a| a.name == filename }
|
|
1534
1598
|
end
|
|
1535
1599
|
|
|
1536
|
-
# GET/DELETE/PUT calls other than the asset upload share the same
|
|
1537
|
-
# transient network failure modes; retry them (they are idempotent).
|
|
1538
|
-
# A 403 rate-limit response is not one of those modes: it rides the
|
|
1539
|
-
# window out and never consumes the transient attempts. Transport-level
|
|
1540
|
-
# drops (SSL EOF, TCP reset) belong here too: a stale keep-alive
|
|
1541
|
-
# connection answered with an SSL EOF is indistinguishable from a fresh
|
|
1542
|
-
# one that works — net-http retries those on EOFError but NOT on
|
|
1543
|
-
# OpenSSL::SSL::SSLError, so we do (the 2026-08-30 backfill crashed on
|
|
1544
|
-
# exactly that, on the verification GET right after a long upload POST).
|
|
1545
|
-
TRANSIENT_ERRORS = [
|
|
1546
|
-
Net::WriteTimeout, Net::ReadTimeout,
|
|
1547
|
-
Faraday::TimeoutError, Faraday::ConnectionFailed,
|
|
1548
|
-
OpenSSL::SSL::SSLError, EOFError, SystemCallError
|
|
1549
|
-
].freeze
|
|
1550
|
-
|
|
1551
|
-
def with_transient_retries(attempts: 4)
|
|
1552
|
-
with_rate_limit_rideout do
|
|
1553
|
-
yield
|
|
1554
|
-
rescue *TRANSIENT_ERRORS => e
|
|
1555
|
-
attempts -= 1
|
|
1556
|
-
raise if attempts <= 0
|
|
1557
|
-
|
|
1558
|
-
delay = (5 * (4 - attempts)) + rand(5)
|
|
1559
|
-
puts "#{e.class}; retrying in #{delay}s (#{attempts} attempt(s) left)"
|
|
1560
|
-
sleep delay
|
|
1561
|
-
retry
|
|
1562
|
-
end
|
|
1563
|
-
end
|
|
1564
|
-
|
|
1565
|
-
# A 403 rate-limit response must never kill the publish: the uploader
|
|
1566
|
-
# is one serialized actor, and sleeping until the window resets is the
|
|
1567
|
-
# CORRECT behavior (the 0.16.6 publish burned the tebako-ci token's
|
|
1568
|
-
# 5000-request hourly window in ~30 minutes and died at the finalize —
|
|
1569
|
-
# GET .../assets 403 — after all 334 payload assets had landed). The
|
|
1570
|
-
# upload POST rides this out too; its transient retries (escalating
|
|
1571
|
-
# delays, 422-by-content resolution, the per-asset budget) stay with
|
|
1572
|
-
# perform_upload.
|
|
1573
|
-
RATE_LIMIT_SETTLE = 5
|
|
1574
|
-
RATE_LIMIT_DEFAULT_WAIT = 60
|
|
1575
|
-
RATE_LIMIT_BUDGET = (2 * 3600) + 300
|
|
1576
|
-
|
|
1577
|
-
def with_rate_limit_rideout
|
|
1578
|
-
yield
|
|
1579
|
-
rescue Octokit::TooManyRequests => e
|
|
1580
|
-
wait = rate_limit_wait(e)
|
|
1581
|
-
puts "#{e.class}; rate-limited — sleeping #{wait}s until the window resets"
|
|
1582
|
-
sleep wait
|
|
1583
|
-
retry
|
|
1584
|
-
end
|
|
1585
|
-
|
|
1586
|
-
# The seconds to sleep before the next call, budget-checked: one full
|
|
1587
|
-
# hourly window is a legitimate wait; a wait that would push the process
|
|
1588
|
-
# past two windows means something is systemically wrong — give up
|
|
1589
|
-
# loudly instead of blocking the runner forever.
|
|
1590
|
-
def rate_limit_wait(error)
|
|
1591
|
-
wait = rate_limit_seconds(error)
|
|
1592
|
-
return wait if monotonic_now + wait <= rate_limit_deadline
|
|
1593
|
-
|
|
1594
|
-
raise RateLimitBudgetExhausted,
|
|
1595
|
-
"the next GitHub rate-limit window is #{wait}s out but this publish has a #{RATE_LIMIT_BUDGET}s " \
|
|
1596
|
-
"ride-out budget — two full windows spent; giving up loudly instead of blocking forever"
|
|
1597
|
-
end
|
|
1598
|
-
|
|
1599
|
-
def rate_limit_deadline
|
|
1600
|
-
@rate_limit_deadline ||= monotonic_now + RATE_LIMIT_BUDGET
|
|
1601
|
-
end
|
|
1602
|
-
|
|
1603
|
-
# The reset header names the window's end as a wall-clock epoch (plus a
|
|
1604
|
-
# small settle); a stale or absent reset falls back to Retry-After,
|
|
1605
|
-
# then to a default minute. Faraday's real headers are case-insensitive;
|
|
1606
|
-
# read both spellings so a plain hash (the spec fake) serves the same
|
|
1607
|
-
# values.
|
|
1608
|
-
def rate_limit_seconds(error)
|
|
1609
|
-
headers = error.response_headers || {}
|
|
1610
|
-
reset = (headers["x-ratelimit-reset"] || headers["X-RateLimit-Reset"]).to_i
|
|
1611
|
-
return reset - Time.now.to_i + RATE_LIMIT_SETTLE if reset > Time.now.to_i
|
|
1612
|
-
|
|
1613
|
-
retry_after = (headers["retry-after"] || headers["Retry-After"]).to_i
|
|
1614
|
-
return retry_after + RATE_LIMIT_SETTLE if retry_after.positive?
|
|
1615
|
-
|
|
1616
|
-
RATE_LIMIT_DEFAULT_WAIT
|
|
1617
|
-
end
|
|
1618
|
-
|
|
1619
1600
|
def run
|
|
1620
1601
|
process_release
|
|
1621
1602
|
rescue StandardError => e
|
|
@@ -1745,7 +1726,7 @@ module TebakoRelease
|
|
|
1745
1726
|
raise Error, "the served image #{image_name} is not on the release — cannot derive its blksum sidecar"
|
|
1746
1727
|
end
|
|
1747
1728
|
|
|
1748
|
-
bytes = with_transient_retries { @client.get(asset.browser_download_url) }.to_s
|
|
1729
|
+
bytes = with_transient_retries("download #{image_name}") { @client.get(asset.browser_download_url) }.to_s
|
|
1749
1730
|
Pathname.new(Dir.mktmpdir).join(image_name).tap { |path| path.binwrite(bytes) }
|
|
1750
1731
|
end
|
|
1751
1732
|
|
|
@@ -1790,7 +1771,8 @@ module TebakoRelease
|
|
|
1790
1771
|
end
|
|
1791
1772
|
|
|
1792
1773
|
def extract_bundle(_release, bundle_asset)
|
|
1793
|
-
|
|
1774
|
+
url = bundle_asset.browser_download_url
|
|
1775
|
+
bytes = with_transient_retries("bundle #{bundle_asset.name}") { @client.get(url) }.to_s
|
|
1794
1776
|
dir = Pathname.new(Dir.mktmpdir("tebako-release-bundle-"))
|
|
1795
1777
|
Zlib::GzipReader.wrap(StringIO.new(bytes)) { |gzip| extract_tar_members(bundle_asset, gzip, dir) }
|
|
1796
1778
|
end
|
data/lib/tebako_release.rb
CHANGED
|
@@ -11,6 +11,7 @@ require_relative "tebako_release/config"
|
|
|
11
11
|
require_relative "tebako_release/platform"
|
|
12
12
|
require_relative "tebako_release/bundler"
|
|
13
13
|
require_relative "tebako_release/blksum"
|
|
14
|
+
require_relative "tebako_release/convergence"
|
|
14
15
|
require_relative "tebako_release/uploader"
|
|
15
16
|
require_relative "tebako_release/signer"
|
|
16
17
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tebako-release
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc
|
|
@@ -9,6 +9,20 @@ bindir: exe
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: base64
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
12
26
|
- !ruby/object:Gem::Dependency
|
|
13
27
|
name: octokit
|
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -42,6 +56,7 @@ files:
|
|
|
42
56
|
- lib/tebako_release/blksum.rb
|
|
43
57
|
- lib/tebako_release/bundler.rb
|
|
44
58
|
- lib/tebako_release/config.rb
|
|
59
|
+
- lib/tebako_release/convergence.rb
|
|
45
60
|
- lib/tebako_release/error.rb
|
|
46
61
|
- lib/tebako_release/platform.rb
|
|
47
62
|
- lib/tebako_release/signer.rb
|