-
-
Notifications
You must be signed in to change notification settings - Fork 392
191 lines (169 loc) · 5.78 KB
/
cicd.yml
File metadata and controls
191 lines (169 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: CI
on:
push:
branches: [ "main" ]
paths:
- 'lib/**'
- 'spec/**'
- 'gemfiles/**'
- 'Gemfile'
- 'Rakefile'
- 'Appraisals'
- 'ruby_llm.gemspec'
- '.github/workflows/cicd.yml'
pull_request:
branches: [ "main" ]
paths:
- 'lib/**'
- 'spec/**'
- 'gemfiles/**'
- 'Gemfile'
- 'Rakefile'
- 'Appraisals'
- 'ruby_llm.gemspec'
- '.github/workflows/cicd.yml'
workflow_call:
# Define default permissions for this workflow
permissions:
contents: read
packages: write # Needed for publishing to GitHub Packages
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.1', '3.2', '3.3', '3.4', 'jruby-head']
rails-version: ['rails-7.1', 'rails-7.2', 'rails-8.0']
exclude:
# Rails 8 requires Ruby 3.2+
- ruby-version: '3.1'
rails-version: 'rails-8.0'
# JRuby only supports up to 7.1 right now
- ruby-version: 'jruby-head'
rails-version: 'rails-8.0'
- ruby-version: 'jruby-head'
rails-version: 'rails-7.2'
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Install dependencies
run: |
bundle install
bundle exec appraisal ${{ matrix.rails-version }} bundle install
- name: Check code format
run: bundle exec rubocop
- name: Run tests
run: bundle exec appraisal ${{ matrix.rails-version }} rspec
env: # Dummy environment variables for local providers
OLLAMA_API_BASE: http://localhost:11434/v1
GPUSTACK_API_BASE: http://localhost:8080/v1
GPUSTACK_API_KEY: test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: ./coverage/coverage.xml
fail_ci_if_error: false
- name: Run the test suite with Faraday v1
run: |
FARADAY_VERSION=1.10.3 bundle install
bundle exec appraisal ${{ matrix.rails-version }} bundle install
bundle exec appraisal ${{ matrix.rails-version }} rspec
env: # Dummy environment variables for local providers
OLLAMA_API_BASE: http://localhost:11434/v1
GPUSTACK_API_BASE: http://localhost:8080/v1
GPUSTACK_API_KEY: test
publish:
name: Build + Publish
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.4'
bundler-cache: true
- name: Check if version needs publishing
id: check_version
run: |
VERSION_FILE="./lib/ruby_llm/version.rb"
VERSION=$(ruby -r $VERSION_FILE -e "puts RubyLLM::VERSION" 2>/dev/null)
if [ -z "$VERSION" ]; then
echo "Error: Could not extract VERSION from $VERSION_FILE" >&2
exit 1
fi
echo "Local version: $VERSION"
GEM_NAME="ruby_llm"
echo "Fetching published versions for '$GEM_NAME'..."
# Combine results from --all and --prerelease, extract, clean, unique sort
ALL_PUBLISHED_VERSIONS=$(( \
gem list ^${GEM_NAME}$ -r --all 2>/dev/null || true; \
gem list ^${GEM_NAME}$ -r --prerelease 2>/dev/null || true; \
) | sed -n 's/.*(\(.*\)).*/\1/p' \
| tr ',' '\n' \
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \
| grep . \
| sort -u )
echo "Checking against published versions:"
if [ -n "$ALL_PUBLISHED_VERSIONS" ]; then
echo "$ALL_PUBLISHED_VERSIONS" | sed 's/^/ /' # Log found versions nicely
else
echo " (none found)"
fi
if echo "$ALL_PUBLISHED_VERSIONS" | grep -Fxq "$VERSION"; then
echo "Verdict: Version $VERSION already published."
echo "version_changed=false" >> $GITHUB_OUTPUT
else
echo "Verdict: Version $VERSION is new."
echo "version_changed=true" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Verify cassettes are fresh
if: steps.check_version.outputs.version_changed == 'true'
run: bundle exec rake release:verify_cassettes
- name: Publish to GPR
if: steps.check_version.outputs.version_changed == 'true'
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
output=$(gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem 2>&1) || {
echo "$output"
if echo "$output" | grep -q "already been pushed"; then
echo "Version already exists, skipping"
exit 0
else
exit 1
fi
}
env:
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
OWNER: ${{ github.repository_owner }}
- name: Publish to RubyGems
if: steps.check_version.outputs.version_changed == 'true'
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
output=$(gem push *.gem 2>&1) || {
echo "$output"
if echo "$output" | grep -q "Repushing of gem versions is not allowed"; then
echo "Version already exists, skipping"
exit 0
else
exit 1
fi
}
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"