From 50f04fb0968cfa7e96b397271aa043b33fe68fe0 Mon Sep 17 00:00:00 2001 From: Florian Kinder Date: Thu, 3 Jul 2025 19:45:29 +0900 Subject: [PATCH] Fix README tag pollution from update script (#573) * fix: Improve README tag generation to reduce clutter - Modified update.sh to only show the latest and stable versions - Removed duplicate major.minor version tags - Changed from listing all versions to showing only the most relevant tags - Fixed jq query to properly detect stable version using index() instead of contains() This significantly reduces README pollution by showing only: - The latest experimental version with its tags - The current stable version with its tags - One entry per major.minor version for older releases (removed from this commit) Before: 60+ lines of tags with many duplicates After: 2 lines showing only latest and stable versions * fix: Address shellcheck warnings about subshell variable modifications - Changed from pipeline to process substitution to avoid SC2030/SC2031 warnings - Variables modified in the while loop are now properly preserved - This ensures readme_tags modifications are not lost in subshells --- README.md | 56 +++---------------------------------------------- update.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 671bd8a..19557b6 100644 --- a/README.md +++ b/README.md @@ -6,59 +6,9 @@ [中文](./README_zh_CN.md) -* `2.0.58`, `latest` -* `2.0.57` -* `2`, `2.0`, `2.0.55`, `stable`, `stable-2.0.55` -* `2.0.54` -* `2.0.53` -* `2.0.52` -* `2.0.51` -* `2.0.50` -* `2.0.49` -* `2.0.48` -* `2.0`, `2.0.47`, `stable-2.0.47` -* `2.0.46` -* `2.0.45` -* `2.0.44` -* `2.0`, `2.0.43`, `stable-2.0.43` -* `2.0`, `2.0.42`, `stable-2.0.42` -* `2.0`, `2.0.41`, `stable-2.0.41` -* `2.0.40` -* `2.0`, `2.0.39`, `stable-2.0.39` -* `2.0.38` -* `2.0.37` -* `2.0.36` -* `2.0.35` -* `2.0.34` -* `2.0.33` -* `2.0`, `2.0.32`, `stable-2.0.32` -* `2.0.31` -* `2.0`, `2.0.30`, `stable-2.0.30` -* `2.0.29` -* `2.0`, `2.0.28`, `stable-2.0.28` -* `2.0.27` -* `2.0.26` -* `2.0.25` -* `2.0.24` -* `2.0`, `2.0.23`, `stable-2.0.23` -* `2.0.22` -* `2.0`, `2.0.21`, `stable-2.0.21` -* `2.0`, `2.0.20`, `stable-2.0.20` -* `2.0.19` -* `2.0.18` -* `2.0.17` -* `2.0.16` -* `2.0`, `2.0.15`, `stable-2.0.15` -* `2.0`, `2.0.14`, `stable-2.0.14` -* `2.0`, `2.0.13`, `stable-2.0.13` -* `1`, `1.1`, `1.1.110`, `stable-1.1.110` -* `1.0`, `1.0.0` -* `0.17`, `0.17.79` -* `0.16`, `0.16.51` -* `0.15`, `0.15.40` -* `0.14`, `0.14.23` -* `0.13`, `0.13.20` -* `0.12`, `0.12.35` +* `latest, 2.0.58` +* `2, 2.0, 2.0.55, stable, stable-2.0.55` + ## Tag descriptions diff --git a/update.sh b/update.sh index 78f0536..aee637d 100755 --- a/update.sh +++ b/update.sh @@ -91,10 +91,64 @@ if [[ $experimental_online_version != "$stable_online_version" ]]; then fi rm -f -- "$tmpfile" -readme_tags=$(jq --sort-keys 'keys[]' buildinfo.json | tac | (while read -r line -do - tags="$tags\n* "$(jq --sort-keys ".$line.tags | sort | .[]" buildinfo.json | sed 's/"/`/g' | sed ':a; /$/N; s/\n/, /; ta') -done && printf "%s\n\n" "$tags")) +# Generate README tags with logical sorting and de-duplication +# First, collect all unique tags with their versions +declare -A tag_versions +while IFS= read -r version; do + while IFS= read -r tag; do + # If this tag is already seen, compare versions to keep the latest + if [[ -n "${tag_versions[$tag]}" ]]; then + # Compare version strings - keep the higher one + if [[ "$version" > "${tag_versions[$tag]}" ]]; then + tag_versions[$tag]="$version" + fi + else + tag_versions[$tag]="$version" + fi + done < <(jq -r ".\"$version\".tags[]" buildinfo.json) +done < <(jq -r 'keys[]' buildinfo.json | sort -V -r) + +# Build the tags list for README +readme_tags="" +# First add the current latest and stable tags +latest_version=$(jq -r 'to_entries | map(select(.value.tags | contains(["latest"]))) | .[0].key' buildinfo.json) +stable_version=$(jq -r 'to_entries | map(select(.value.tags | index("stable"))) | .[0].key' buildinfo.json) + +if [[ -n "$latest_version" ]]; then + latest_tags=$(jq -r ".\"$latest_version\".tags | map(select(. == \"latest\" or . == \"$latest_version\")) | join(\", \")" buildinfo.json | sed 's/"/`/g') + readme_tags="${readme_tags}\n* \`${latest_tags}\`" +fi + +if [[ -n "$stable_version" ]] && [[ "$stable_version" != "$latest_version" ]]; then + stable_tags=$(jq -r ".\"$stable_version\".tags | sort | join(\", \")" buildinfo.json | sed 's/"/`/g') + readme_tags="${readme_tags}\n* \`${stable_tags}\`" +fi + +# Add major.minor tags (e.g., 2.0, 1.1) - only the latest version for each +declare -A major_minor_seen +while IFS= read -r version; do + if [[ "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then + major="${BASH_REMATCH[1]}" + minor="${BASH_REMATCH[2]}" + major_minor="$major.$minor" + + # Skip if this is the latest or stable version (already added above) + if [[ "$version" == "$latest_version" ]] || [[ "$version" == "$stable_version" ]]; then + continue + fi + + # Only add if we haven't seen this major.minor yet + if [[ -z "${major_minor_seen[$major_minor]}" ]]; then + major_minor_seen[$major_minor]=1 + tags=$(jq -r ".\"$version\".tags | join(\", \")" buildinfo.json | sed 's/"/`/g') + if [[ -n "$tags" ]]; then + readme_tags="${readme_tags}\n* \`${tags}\`" + fi + fi + fi +done < <(jq -r 'keys[]' buildinfo.json | sort -V -r) + +readme_tags="${readme_tags}\n" perl -i -0777 -pe "s/.+/$readme_tags/s" README.md