Skip to content

Commit c7170c4

Browse files
hsbtclaude
andcommitted
Use S3 ListObjects API instead of CDN for rake sync
The CDN (cache.ruby-lang.org) may not have new release files available when the update workflow runs. Switch to querying the S3 bucket (ftp.r-l.o) directly via the ListObjects API, which reflects uploads immediately. This also removes the 3-minute sleep from the workflow. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a42a03f commit c7170c4

2 files changed

Lines changed: 24 additions & 26 deletions

File tree

.github/workflows/update.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
13-
- run: sleep 180 # wait for the release to be available
1413
- run: rake sync
1514
- name: commit and push
1615
run: |

Rakefile

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ require 'fileutils'
4242
require 'json'
4343
require 'pp'
4444
require 'rbconfig'
45+
require 'rexml/document'
4546

4647
require_relative 'lib/ruby_version'
4748

@@ -53,6 +54,8 @@ def show_help_message
5354
end
5455

5556
URI_BASE = 'https://cache.ruby-lang.org/pub/ruby/'
57+
S3_BUCKET_BASE = 'https://s3.amazonaws.com/ftp.r-l.o/'
58+
S3_PREFIX = 'pub/ruby/'
5659

5760
# 'rake sync' checks the tarballs in the directories after RUBY_EOL_VERSION.
5861
# https://www.ruby-lang.org/en/downloads/branches/
@@ -108,33 +111,27 @@ class RubySource
108111
result = RubySource::TABLE.map {|h|
109112
h[:dir]
110113
}.uniq
111-
case URI_BASE
112-
when /\A(http:|https:)/
113-
index = URI(URI_BASE).read
114-
lst = []
115-
index.scan(%r{href="(?:/pub/ruby/)?(\d\.\d)/"}) {
114+
uri = "#{S3_BUCKET_BASE}?list-type=2&prefix=#{S3_PREFIX}&delimiter=/"
115+
xml = URI(uri).read
116+
doc = REXML::Document.new(xml)
117+
lst = []
118+
doc.elements.each('ListBucketResult/CommonPrefixes/Prefix') {|e|
119+
prefix = e.text # e.g. "pub/ruby/3.4/"
120+
if %r{\Apub/ruby/(\d\.\d)/\z} =~ prefix
116121
lst << $1
117-
}
118-
else
119-
raise "unexpected URI_BASE scheme: #{URI_BASE} (http/https required)"
120-
end
122+
end
123+
}
121124
lst.each {|n|
122125
next if result.include? n
123-
#puts "New directory found: #{n}"
124126
result << n
125127
}
126-
#result.map! {|n| uri = URI_BASE + n + "/" }
127-
#puts result
128128
result
129129
end
130130

131131
def self.reldirs_after_eol
132132
reldirs.reject {|n| (vercmp_key(n) <=> vercmp_key(RUBY_EOL_VERSION)) <= 0 }
133133
end
134134

135-
def self.uris_after_eol
136-
reldirs_after_eol.map {|n| URI_BASE + n + "/" }
137-
end
138135

139136
def self.version_lookup(version)
140137
TABLE.each {|h|
@@ -623,12 +620,15 @@ RubySource::TABLE.each {|h|
623620
end
624621
}
625622

626-
def extract_entries(index_html)
623+
def extract_entries_from_s3(reldir)
627624
hs = []
628-
index_html.scan(/<a href="(.*?)">/) {
629-
uri = (index_html.base_uri + $1).to_s
630-
next unless uri.start_with? URI_BASE
631-
relpath = uri[URI_BASE.length..-1]
625+
prefix = "#{S3_PREFIX}#{reldir}/"
626+
uri = "#{S3_BUCKET_BASE}?list-type=2&prefix=#{prefix}"
627+
xml = URI(uri).read
628+
doc = REXML::Document.new(xml)
629+
doc.elements.each('ListBucketResult/Contents/Key') {|e|
630+
key = e.text # e.g. "pub/ruby/3.4/ruby-3.4.9.tar.xz"
631+
relpath = key.sub(/\Apub\/ruby\//, '')
632632
next if relpath.empty?
633633
h = make_entry(relpath)
634634
next if h[:suffix].empty?
@@ -669,11 +669,10 @@ def update_versions(relpath_list)
669669
end
670670

671671
task 'sync' do
672-
uris = RubySource.uris_after_eol
673-
uris.reverse_each {|uri|
674-
puts uri
675-
index_html = URI(uri).read
676-
hs = extract_entries(index_html)
672+
reldirs = RubySource.reldirs_after_eol
673+
reldirs.reverse_each {|reldir|
674+
puts "#{S3_BUCKET_BASE}?list-type=2&prefix=#{S3_PREFIX}#{reldir}/"
675+
hs = extract_entries_from_s3(reldir)
677676
hs = filter_suffix(hs)
678677
relpath_list = hs.map {|h| h[:relpath] }
679678
update_versions relpath_list

0 commit comments

Comments
 (0)