Skip to content

Commit adb4caa

Browse files
authored
Don't wait for www.ruby-lang.org in update.yml (#538)
Instead of polling releases.yml until the release announcement is merged and deployed, wait only for the tarballs on cache.ruby-lang.org and build the releases.yml entry from them (sizes and checksums, plus the announcement's date and URL predicted from when the tarball was published). versions.sh takes it as RUBY_RELEASE_JSON, in preference to releases.yml for that version. This also fixes the 3.3.14 run that found nothing to update: the wait loop saw 3.3.14 in releases.yml, but update.sh's own fetch of it got a stale copy with 3.3.13. Now the entry is resolved once and passed to every versions.sh call (including the push job's replay), and the update fails unless versions.json ends up with the requested version.
1 parent 9f818e8 commit adb4caa

2 files changed

Lines changed: 72 additions & 12 deletions

File tree

‎.github/workflows/update.yml‎

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ name: Update
77
# {"ref": "master", "inputs": {"version": "4.0.9"}}
88
# and does the same thing as the "update.sh" Jenkins job (https://doi-janky.infosiftr.net/job/update.sh/job/ruby/),
99
# just sooner: run "./update.sh", commit, build + test the result on amd64, then push it to master.
10+
# It doesn't wait for the release to show up in www.ruby-lang.org's releases.yml (which "versions.sh" reads, and
11+
# which only lands once the release announcement is merged and deployed): it builds the same entry from the
12+
# tarballs on cache.ruby-lang.org instead, and hands it to "versions.sh" as RUBY_RELEASE_JSON.
1013
# If the Jenkins job gets there first, this finds nothing to do (and vice versa).
1114
#
1215
# Ruby usually releases several versions at once (e.g. 3.3.x, 3.4.x and 4.0.x on the same day), so each
@@ -44,6 +47,7 @@ jobs:
4447
outputs:
4548
key: ${{ steps.targets.outputs.key }}
4649
targets: ${{ steps.targets.outputs.targets }}
50+
release: ${{ steps.release.outputs.release }}
4751
base: ${{ steps.commit.outputs.base }}
4852
commit: ${{ steps.commit.outputs.commit }}
4953
strategy: ${{ steps.generate-jobs.outputs.strategy }}
@@ -77,32 +81,76 @@ jobs:
7781
echo "::error::'$key' is not in versions.json; new release series are added by hand"
7882
exit 1
7983
fi
84+
echo "majorMinor=$majorMinor" >> "$GITHUB_OUTPUT"
8085
echo "key=$key" >> "$GITHUB_OUTPUT"
8186
echo "targets=${targets[*]}" >> "$GITHUB_OUTPUT"
8287
83-
- name: Wait for ${{ inputs.version }} in www.ruby-lang.org releases.yml
88+
- name: Wait for ${{ inputs.version }} on cache.ruby-lang.org
89+
id: release
8490
env:
8591
RUBY_VERSION: ${{ inputs.version }}
86-
KEY: ${{ steps.targets.outputs.key }}
92+
MAJOR_MINOR: ${{ steps.targets.outputs.majorMinor }}
8793
run: |
88-
# "versions.sh" reads https://github.com/ruby/www.ruby-lang.org/raw/master/_data/releases.yml, which can land a while after the release itself
89-
for (( i = 0; i < 240; i++ )); do
90-
# (transient network errors shouldn't end the wait early)
91-
./versions.sh "$KEY" || :
92-
found="$(jq -r --arg key "$KEY" '.[$key].version // empty' versions.json || :)"
93-
git checkout -- versions.json
94-
if [ "$found" = "$RUBY_VERSION" ]; then
95-
exit 0
94+
# publish.yml dispatches this right after it copies the release into /pub, but give the CDN a moment
95+
url="https://cache.ruby-lang.org/pub/ruby/$MAJOR_MINOR/ruby-$RUBY_VERSION"
96+
declare -A exts=( [gz]=tar.gz [zip]=zip [xz]=tar.xz )
97+
for (( i = 0; ; i++ )); do
98+
missing=0
99+
for format in gz zip xz; do
100+
curl -fsSL -o /dev/null --head "$url.${exts[$format]}" || missing=1
101+
done
102+
[ "$missing" = 0 ] && break
103+
if (( i >= 60 )); then
104+
echo "::error::$url.{tar.gz,zip,tar.xz} did not show up"
105+
exit 1
96106
fi
97107
sleep 30
98108
done
99-
echo "::error::$RUBY_VERSION did not show up in releases.yml (latest for $KEY: ${found:-none})"
100-
exit 1
109+
110+
# if releases.yml already has it (a re-run after the announcement went out), that entry is the authoritative one
111+
release="$(
112+
curl -fsSL 'https://github.com/ruby/www.ruby-lang.org/raw/master/_data/releases.yml' \
113+
| yq -r '@json' \
114+
| jq -c '.[] | select(.version == env.RUBY_VERSION)' \
115+
|| :
116+
)"
117+
if [ -z "$release" ]; then
118+
# otherwise, build the same entry releases.yml will get
119+
release="$(jq -nc '{ version: env.RUBY_VERSION, date: null, post: null, url: {}, size: {}, sha1: {}, sha256: {}, sha512: {} }')"
120+
for format in gz zip xz; do
121+
file="$RUNNER_TEMP/ruby-$RUBY_VERSION.${exts[$format]}"
122+
curl -fsSL -o "$file" -D "$file.headers" "$url.${exts[$format]}"
123+
release="$(
124+
jq <<<"$release" -c \
125+
--arg format "$format" \
126+
--arg url "$url.${exts[$format]}" \
127+
--argjson size "$(stat -c %s "$file")" \
128+
--arg sha1 "$(sha1sum "$file" | cut -d' ' -f1)" \
129+
--arg sha256 "$(sha256sum "$file" | cut -d' ' -f1)" \
130+
--arg sha512 "$(sha512sum "$file" | cut -d' ' -f1)" \
131+
'.url[$format] = $url | .size[$format] = $size | .sha1[$format] = $sha1 | .sha256[$format] = $sha256 | .sha512[$format] = $sha512'
132+
)"
133+
done
134+
# the announcement is (almost always) dated the UTC day the release was published (copied into /pub)
135+
lastModified="$(sed -n 's/^last-modified: *//Ip' "$file.headers" | tr -d '\r' | tail -1)"
136+
date="$(date -u -d "$lastModified" +%Y-%m-%d)"
137+
release="$(
138+
jq <<<"$release" -c --arg date "$date" '
139+
.date = $date
140+
| .post = "/en/news/\($date | gsub("-"; "/"))/ruby-\(.version | gsub("\\."; "-"))-released/"
141+
'
142+
)"
143+
fi
144+
jq <<<"$release" .
145+
echo "release=$release" >> "$GITHUB_OUTPUT"
101146
102147
- name: Update and commit
103148
id: commit
104149
env:
150+
RUBY_VERSION: ${{ inputs.version }}
151+
KEY: ${{ steps.targets.outputs.key }}
105152
TARGETS: ${{ steps.targets.outputs.targets }}
153+
RUBY_RELEASE_JSON: ${{ steps.release.outputs.release }}
106154
run: |
107155
git config user.name 'github-actions[bot]'
108156
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
@@ -139,6 +187,13 @@ jobs:
139187
git commit -m "$commitMessage" || :
140188
done
141189
190+
# whether or not that changed anything, the result must have this release
191+
found="$(jq -r --arg key "$KEY" '.[$key].version // empty' versions.json)"
192+
if [ "$found" != "$RUBY_VERSION" ]; then
193+
echo "::error::versions.json has ${found:-no} $KEY after update.sh, not $RUBY_VERSION"
194+
exit 1
195+
fi
196+
142197
commit="$(git rev-parse HEAD)"
143198
if [ "$commit" = "$base" ]; then
144199
echo 'Nothing to update (already up to date)'
@@ -235,6 +290,7 @@ jobs:
235290
TARGETS: ${{ needs.update.outputs.targets }}
236291
BASE: ${{ needs.update.outputs.base }}
237292
COMMIT: ${{ needs.update.outputs.commit }}
293+
RUBY_RELEASE_JSON: ${{ needs.update.outputs.release }}
238294
run: |
239295
git config user.name 'github-actions[bot]'
240296
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'

‎versions.sh‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ releases="$(
3232
wget -qO- 'https://github.com/ruby/www.ruby-lang.org/raw/master/_data/releases.yml' \
3333
| "$yq" -r '@json' # this *should* work on both the Go-based "yq" we download and the Python-based "yq" available from Debian's APT repo
3434
)"
35+
if [ -n "${RUBY_RELEASE_JSON:-}" ]; then
36+
# a release entry (same shape as releases.yml's) that takes precedence over releases.yml for its version, so a release can be picked up before (or regardless of whether) www.ruby-lang.org lists it (see ".github/workflows/update.yml")
37+
releases="$(jq <<<"$releases" -c --argjson release "$RUBY_RELEASE_JSON" '[ $release ] + map(select(.version != $release.version))')"
38+
fi
3539

3640
for version in "${versions[@]}"; do
3741
rcGrepV='-v'

0 commit comments

Comments
 (0)