-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve update.sh
to reduce manual steps
#86
base: master
Are you sure you want to change the base?
Changes from all commits
d3a164c
f751abf
82ea22e
836fabf
8b622ee
d2cf5e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,11 @@ ruby="$1" | |
version="$2" | ||
dest="${3:-pkg}" | ||
|
||
version_major="${version%%.*}" # Extract major from version (e.g., 3) | ||
version_family="${version%.*}" # Extract major.minor from version (e.g., 3.3) | ||
|
||
case "$ruby" in | ||
ruby) | ||
version_major="${version:0:1}" | ||
version_family="${version:0:3}" | ||
|
||
if [[ "$version_major" == "2" ]]; then | ||
exts=(tar.bz2 tar.gz tar.xz zip) | ||
else | ||
|
@@ -85,15 +85,49 @@ for ext in "${exts[@]}"; do | |
fi | ||
|
||
for algorithm in md5 sha1 sha256 sha512; do | ||
${algorithm}sum "$archive" >> "$cwd/$ruby/checksums.$algorithm" | ||
# 1) Append the new checksum line | ||
"${algorithm}sum" "$archive" >> "$cwd/$ruby/checksums.$algorithm" | ||
|
||
# 2) Remove duplicates (keeping the first occurrence) without sorting | ||
awk '!seen[$0]++' "$cwd/$ruby/checksums.$algorithm" \ | ||
> "$cwd/$ruby/checksums.$algorithm.tmp" | ||
|
||
mv "$cwd/$ruby/checksums.$algorithm.tmp" "$cwd/$ruby/checksums.$algorithm" | ||
done | ||
0xdevalias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
popd >/dev/null | ||
done | ||
|
||
# This script appends a new version to versions.txt and ensures it remains sorted. | ||
# Steps: | ||
# 1. Append the new version to versions.txt. | ||
# 2. Temporarily transform stable versions (those with no dash, e.g., "3.0.0") | ||
# by appending "-zzzzzz". This ensures they sort *after* any lines containing | ||
# suffixes like "-preview", "-rc", or "-pXYZ". | ||
# 3. Sort the file uniquely (-u) with "-" as the field separator (-t-): | ||
# -k1,1V sorts the main version (e.g., "3.0.0") as a version, | ||
# -k2,2V sorts suffixes (e.g., "preview1", "rc2") as versions, | ||
# so the transformed stable lines appear last in their version group. | ||
# 4. Remove the temporary "-zzzzzz" suffix from stable versions. | ||
# 5. Replace the original file with the sorted result. | ||
echo "$version" >> "$ruby/versions.txt" | ||
sed 's/^\([0-9][^-]*\)$/\1-zzzzzz/' "$ruby/versions.txt" \ | ||
| sort -u -t- -k1,1V -k2,2V \ | ||
| sed 's/-zzzzzz$//' \ | ||
> "$ruby/versions.txt.tmp" | ||
mv "$ruby/versions.txt.tmp" "$ruby/versions.txt" | ||
Comment on lines
+100
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a little obtuse. Is there an easier way to sort versions by length or emulate GNU's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There no doubt is, though this was the best I was able to come up with at the time while trying to stick to using Ideally I would just use ⇒ echo -e "3.0.0-preview\n3.0.0\n3.0.0-rc1" | sort -V
3.0.0
3.0.0-preview
3.0.0-rc1 Iterating with Claude attempting to simplify came up with this: echo "$version" >> "$ruby/versions.txt"
awk '{
# For versions without a suffix, assign a high-value suffix for sorting
# but only for comparison purposes
split($0, parts, "-")
sortkey = (parts[2] == "") ? $0 "~" : $0
print sortkey, $0
}' "$ruby/versions.txt" |
sort -uV | # Sort by the sortkey
cut -d' ' -f2 | # Keep only the original version string
tee "$ruby/versions.txt" ⇒ echo -e "3.0.0\n3.0.0-rc1\n3.0.0-preview1\n3.1.0" |
awk '{ split($0,parts,"-"); sortkey = (parts[2]=="") ? $0"~" : $0; print sortkey, $0 }' |
sort -uV |
cut -d' ' -f2
3.0.0
3.0.0-preview1
3.0.0-rc1
3.1.0 Iterating with ⇒ echo -e "3.0.0-preview\n3.0.0\n3.0.0-rc1" | sort -t- -k1,1V -k2,2r -u
3.0.0-rc1
3.0.0-preview
3.0.0 But when we use a more complete test case, it fails to sort some of the versions correctly still: ⇒ echo -e "3.0.0-p547\n3.0.0-p551\n3.0.0-p550\n3.0.0-preview\n3.0.0\n3.0.0-rc1" | sort -t- -k1,1V -k2,2r -u
3.0.0-rc1
3.0.0-preview
3.0.0-p551
3.0.0-p550
3.0.0-p547
3.0.0 Removing the ⇒ echo -e "3.0.0-p547\n3.0.0-p551\n3.0.0-p550\n3.0.0-preview\n3.0.0\n3.0.0-rc1" | sort -t- -k1,1V -k2,2 -u
3.0.0
3.0.0-p547
3.0.0-p550
3.0.0-p551
3.0.0-preview
3.0.0-rc1 If you have any ideas of paths to explore, or alternative tools you're open to being included here, happy to try and iterate/refine further. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seemingly Gnu sort also has these sorting semantics of the labelled versions coming after the major version with ⇒ echo -e "3.0.0-p547\n3.0.0-p551\n3.0.0-p550\n3.0.0-preview\n3.0.0\n3.0.0-rc1" | gsort -t- -k1,1V -k2,2 -u
3.0.0
3.0.0-p547
3.0.0-p550
3.0.0-p551
3.0.0-preview
3.0.0-rc1 |
||
|
||
if [[ $(wc -l < "$ruby/stable.txt") == "1" ]]; then | ||
echo "$version" > "$ruby/stable.txt" | ||
if [[ -f "$ruby/stable.txt" ]]; then | ||
stable_file="$ruby/stable.txt" | ||
|
||
# Use sed to replace the version for the major.minor family or append it if not found | ||
if grep -qE "^${version_family}\." "$stable_file"; then | ||
sed -i '' -E "s/^(${version_family}\.).*/$version/" "$stable_file" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When I first ran it with just
Valid.. can definitely test without and remove if not needed.
Makes sense 👌🏻
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With With (GNU With (GNU So I think that weird syntax of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because
Maybe try |
||
echo "Updated $stable_file to $version" | ||
else | ||
echo "$version" >> "$stable_file" | ||
echo "Appended $version to $stable_file" | ||
fi | ||
else | ||
echo "Please update $ruby/stable.txt manually" | ||
echo "$version" > "$ruby/stable.txt" | ||
echo "Created $ruby/stable.txt with $version" | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really necessary to remove duplicates from the checksum files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mostly added this with the idea of making running
update.sh
idempotent when the version had already been added.I originally thought about doing a version of
sort
for it instead, but that came with a bunch of extra caveats, as I highlighted in: