Skip to content

Commit 27f8347

Browse files
committed
ci: enhance version check logic in CI workflow for both releases and prereleases
1 parent 5365924 commit 27f8347

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

.github/workflows/cicd.yml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,46 @@ jobs:
7474
ruby-version: '3.3'
7575
bundler-cache: true
7676

77-
- name: Check if version has changed
77+
- name: Check if version needs publishing
7878
id: check_version
7979
run: |
80-
VERSION=$(ruby -r ./lib/ruby_llm/version.rb -e "puts RubyLLM::VERSION")
81-
echo "Current version: $VERSION"
80+
VERSION_FILE="./lib/ruby_llm/version.rb"
81+
VERSION=$(ruby -r $VERSION_FILE -e "puts RubyLLM::VERSION" 2>/dev/null)
8282
83-
# Fetch all versions including prereleases
84-
ALL_VERSIONS=$(gem list ruby_llm -r --prerelease | grep -oE '[0-9a-zA-Z\.\-]+')
85-
echo "Available versions: $ALL_VERSIONS"
83+
if [ -z "$VERSION" ]; then
84+
echo "Error: Could not extract VERSION from $VERSION_FILE" >&2
85+
exit 1
86+
fi
87+
echo "Local version: $VERSION"
88+
89+
GEM_NAME="ruby_llm"
90+
echo "Fetching published versions for '$GEM_NAME'..."
91+
92+
# Combine results from --all and --prerelease, extract, clean, unique sort
93+
ALL_PUBLISHED_VERSIONS=$(( \
94+
gem list ^${GEM_NAME}$ -r --all 2>/dev/null || true; \
95+
gem list ^${GEM_NAME}$ -r --prerelease 2>/dev/null || true; \
96+
) | sed -n 's/.*(\(.*\)).*/\1/p' \
97+
| tr ',' '\n' \
98+
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \
99+
| grep . \
100+
| sort -u )
101+
102+
echo "Checking against published versions:"
103+
if [ -n "$ALL_PUBLISHED_VERSIONS" ]; then
104+
echo "$ALL_PUBLISHED_VERSIONS" | sed 's/^/ /' # Log found versions nicely
105+
else
106+
echo " (none found)"
107+
fi
86108
87-
# Check if current version is among published versions
88-
if echo "$ALL_VERSIONS" | grep -Fxq "$VERSION"; then
89-
echo "Version $VERSION already published, skipping publish"
109+
if echo "$ALL_PUBLISHED_VERSIONS" | grep -Fxq "$VERSION"; then
110+
echo "Verdict: Version $VERSION already published."
90111
echo "version_changed=false" >> $GITHUB_OUTPUT
91112
else
92-
echo "Version $VERSION is new"
113+
echo "Verdict: Version $VERSION is new."
93114
echo "version_changed=true" >> $GITHUB_OUTPUT
94115
fi
116+
shell: bash
95117

96118
- name: Test with real APIs before publishing
97119
if: steps.check_version.outputs.version_changed == 'true'

0 commit comments

Comments
 (0)