mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 08:25:20 +08:00
fetch-bundled_gems.rb: Retry git clone and fetch
A single failed connection to github.com aborted the whole build. The candidate tags are retried as a group, so a missing `v` prefixed tag still falls back without waiting. https://github.com/ruby/ruby/actions/runs/37669701848/job/112960320483 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
332fcb9e41
commit
dc420ed4b7
1 file changed
+17
-4
Notes:
git
2026-10-14 03:54:30 +00:00
@@ -16,6 +16,17 @@ BEGIN {
|
||||
ARGF.eof?
|
||||
FileUtils.mkdir_p(dir)
|
||||
Dir.chdir(dir)
|
||||
|
||||
# Retry so that a transient network failure does not abort the build.
|
||||
def with_retry(tries = 3)
|
||||
tries.times do |i|
|
||||
sleep 5 if i > 0
|
||||
if result = yield
|
||||
return result
|
||||
end
|
||||
end
|
||||
nil
|
||||
end
|
||||
}
|
||||
|
||||
n, v, u, r = $F
|
||||
@@ -25,7 +36,7 @@ next if bundled_gems&.all? {|pat| !File.fnmatch?(pat, n)}
|
||||
|
||||
unless File.exist?("#{n}/.git")
|
||||
puts "retrieving #{color.notice(n)} ..."
|
||||
system(*%W"git clone --depth=1 --no-tags #{u} #{n}") or abort
|
||||
with_retry {system(*%W"git clone --depth=1 --no-tags #{u} #{n}")} or abort
|
||||
end
|
||||
|
||||
candidates = r ? [r] : ["v#{v}", v]
|
||||
@@ -36,9 +47,11 @@ c = candidates.find do |c|
|
||||
system("git", "rev-parse", "-q", "--verify", "#{c}^{commit}", out: File::NULL, err: File::NULL, chdir: n)
|
||||
end
|
||||
|
||||
c ||= candidates.find do |c|
|
||||
puts "fetching #{n} #{color.notice(c)} ..."
|
||||
system("git", "fetch", "origin", r || "refs/tags/#{c}:refs/tags/#{c}", chdir: n)
|
||||
c ||= with_retry do
|
||||
candidates.find do |c|
|
||||
puts "fetching #{n} #{color.notice(c)} ..."
|
||||
system("git", "fetch", "origin", r || "refs/tags/#{c}:refs/tags/#{c}", chdir: n)
|
||||
end
|
||||
end or abort
|
||||
|
||||
checkout = %w"git -c advice.detachedHead=false checkout"
|
||||
|
||||
Reference in new issue
Block a user