Skip to content

Commit 3c4901f

Browse files
tomasr78claude
andcommitted
Version floor: compare against every release tag, pre-releases included, with Gem::Version
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5eb7a9e commit 3c4901f

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,15 @@ jobs:
9090
echo "::error file=lib/convert_api/version.rb::ConvertApi::VERSION '$VERSION' is not {major}.{minor}.{patch} or {major}.{minor}.{patch}.{alpha|beta|rc}.{n}"
9191
exit 1
9292
fi
93-
BASE="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}"
94-
LATEST=$(git tag --list 'v*' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' | sort -V | tail -n1)
95-
if [ -n "$LATEST" ] && [ "$(printf '%s\n%s\n' "$LATEST" "$BASE" | sort -V | tail -n1)" != "$BASE" ]; then
93+
# The highest release so far, pre-releases included (v3.1.0-rc.2 is gem version 3.1.0.rc.2). Gem::Version
94+
# sorts a pre-release below its release, so this also refuses a pre-release of a released version.
95+
LATEST=$(git tag --list 'v*' | ruby -e '
96+
tags = $stdin.read.split.grep(/\Av\d+\.\d+\.\d+(-(alpha|beta|rc)\.\d+)?\z/)
97+
print tags.map { |t| Gem::Version.new(t.delete_prefix("v").tr("-", ".")) }.max')
98+
if [ -n "$LATEST" ] && ! ruby -e 'exit Gem::Version.new(ARGV[0]) >= Gem::Version.new(ARGV[1])' "$VERSION" "$LATEST"; then
9699
echo "::error file=lib/convert_api/version.rb::ConvertApi::VERSION $VERSION is lower than the latest release $LATEST"
97100
exit 1
98101
fi
99-
# A pre-release sorts below its release, so a pre-release of the latest release is a step back.
100-
if [ "$VERSION" != "$BASE" ] && [ "$BASE" = "$LATEST" ]; then
101-
echo "::error file=lib/convert_api/version.rb::ConvertApi::VERSION $VERSION is a pre-release of $LATEST, which is already released"
102-
exit 1
103-
fi
104102
{
105103
echo "version=$VERSION"
106104
echo "latest=$LATEST"
@@ -138,7 +136,7 @@ jobs:
138136
{
139137
echo "| | |"
140138
echo "|---|---|"
141-
echo "| \`ConvertApi::VERSION\` | \`$VERSION\` (latest release: \`v$LATEST\`) |"
139+
echo "| \`ConvertApi::VERSION\` | \`$VERSION\` (latest release: \`$LATEST\`) |"
142140
echo "| Gem | \`convert_api-$VERSION.gem\` (artifact only, not published) |"
143141
echo "| Ruby | 3.2, 3.3, 3.4, 4.0 |"
144142
} >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)