Skip to content

Commit 42355e1

Browse files
committed
Get CI working and auto-publishing to RubyGems
1 parent aef70d1 commit 42355e1

File tree

10 files changed

+292
-55
lines changed

10 files changed

+292
-55
lines changed

.github/workflows/ci.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v5
18+
19+
- name: Set up Ruby
20+
uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: '3.4'
23+
bundler-cache: true
24+
25+
- name: Run linters
26+
run: bundle exec rake ci:lint
27+
28+
test:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v5
33+
34+
- name: Set up Ruby
35+
uses: ruby/setup-ruby@v1
36+
with:
37+
ruby-version: '3.4'
38+
bundler-cache: true
39+
40+
- name: Install Claude Code CLI
41+
run: curl -fsSL https://claude.ai/install.sh | bash
42+
43+
- name: Add Claude to PATH
44+
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
45+
46+
- name: Verify Claude installation
47+
run: claude --version
48+
49+
- name: Run tests
50+
run: bundle exec rake ci:test
51+
env:
52+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
53+
54+
publish:
55+
needs: [lint, test]
56+
name: Publish to RubyGems
57+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
58+
runs-on: ubuntu-latest
59+
permissions:
60+
contents: write
61+
steps:
62+
- name: Checkout code
63+
uses: actions/checkout@v5
64+
65+
- name: Set up Ruby
66+
uses: ruby/setup-ruby@v1
67+
with:
68+
ruby-version: '3.4'
69+
bundler-cache: true
70+
71+
- name: Build gem
72+
run: gem build ruby_agent.gemspec
73+
74+
- name: Publish to RubyGems
75+
run: |
76+
mkdir -p ~/.gem
77+
echo "---" > ~/.gem/credentials
78+
echo ":rubygems_api_key: ${RUBYGEMS_API_KEY}" >> ~/.gem/credentials
79+
chmod 0600 ~/.gem/credentials
80+
gem push ruby_agent-*.gem
81+
env:
82+
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
83+
84+
- name: Create git tag
85+
run: |
86+
VERSION=$(ruby -r ./lib/ruby_agent/version.rb -e "puts RubyAgent::VERSION")
87+
git config user.name "github-actions[bot]"
88+
git config user.email "github-actions[bot]@users.noreply.github.com"
89+
git tag -a "v${VERSION}" -m "Release v${VERSION}" || echo "Tag already exists"
90+
git push origin "v${VERSION}" || echo "Tag already pushed"

.rubocop.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
AllCops:
2+
NewCops: enable
3+
TargetRubyVersion: 3.4
4+
SuggestExtensions: false
5+
Exclude:
6+
- 'vendor/**/*'
7+
- 'tmp/**/*'
8+
- 'bin/**/*'
9+
10+
Style/Documentation:
11+
Enabled: false
12+
13+
Style/StringLiterals:
14+
EnforcedStyle: double_quotes
15+
16+
Style/FrozenStringLiteralComment:
17+
Enabled: false
18+
19+
Layout/LineLength:
20+
Max: 125
21+
22+
Metrics/MethodLength:
23+
Max: 50
24+
25+
Metrics/AbcSize:
26+
Max: 40
27+
28+
Metrics/CyclomaticComplexity:
29+
Max: 25
30+
31+
Metrics/PerceivedComplexity:
32+
Max: 25
33+
34+
Metrics/BlockNesting:
35+
Max: 5
36+
37+
Metrics/BlockLength:
38+
Exclude:
39+
- 'test/**/*'
40+
- 'Rakefile'
41+
42+
Metrics/ClassLength:
43+
Max: 350
44+
45+
Metrics/ParameterLists:
46+
Max: 10
47+
48+
Lint/UnusedMethodArgument:
49+
AllowUnusedKeywordArguments: true
50+
51+
Lint/EmptyBlock:
52+
Enabled: false
53+
54+
Lint/SuppressedException:
55+
AllowComments: true
56+
57+
Gemspec/RequiredRubyVersion:
58+
Enabled: false

Gemfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ source "https://rubygems.org"
22

33
gemspec
44

5-
gem "rake", "~> 13.0"
65
gem "minitest", "~> 5.0"
76
gem "minitest-reporters", "~> 1.6"
7+
gem "rake", "~> 13.0"
8+
9+
group :development do
10+
gem "bundler-audit", "~> 0.9", require: false
11+
gem "rubocop", "~> 1.50", require: false
12+
end

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,64 @@ rescue RubyAgent::AgentError => e
205205
end
206206
```
207207

208+
## Development
209+
210+
### Contributing
211+
212+
1. Fork the repository: https://github.com/AllYourBot/ruby-agent
213+
2. Create a feature branch: `git checkout -b my-new-feature`
214+
3. Make your changes
215+
4. Run the CI suite locally to ensure everything passes:
216+
217+
```bash
218+
# Run all CI tasks (linting + tests)
219+
rake ci
220+
221+
# Or run tasks individually:
222+
rake ci:test # Run test suite
223+
rake ci:lint # Run RuboCop linter
224+
rake ci:scan # Run security audit
225+
```
226+
227+
5. Commit your changes: `git commit -am 'Add some feature'`
228+
6. Push to your fork: `git push origin my-new-feature`
229+
7. Create a Pull Request against the `main` branch
230+
231+
### Running Tests Locally
232+
233+
The test suite includes an integration test that runs Claude Code CLI locally:
234+
235+
```bash
236+
# Run all tests
237+
rake test
238+
239+
# Run a specific test
240+
ruby test/ruby_agent_test.rb --name test_simple_agent_query
241+
```
242+
243+
**Note**: Tests require Claude Code CLI to be installed on your machine (see Prerequisites section).
244+
245+
### Linting
246+
247+
We use RuboCop for code linting:
248+
249+
```bash
250+
# Check for linting issues
251+
rake ci:lint
252+
253+
# Auto-fix linting issues
254+
bundle exec rubocop -a
255+
```
256+
257+
### Publishing
258+
259+
Publishing to RubyGems happens automatically via GitHub Actions when code is merged to `main`. The version number is read from `lib/ruby_agent/version.rb`.
260+
261+
**Before merging a PR**, make sure to bump the version number appropriately:
262+
- Patch version (0.2.1 → 0.2.2) for bug fixes
263+
- Minor version (0.2.1 → 0.3.0) for new features
264+
- Major version (0.2.1 → 1.0.0) for breaking changes
265+
208266
## License
209267

210268
MIT

Rakefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,27 @@ Rake::TestTask.new(:test) do |t|
88
end
99

1010
task default: :test
11+
12+
namespace :ci do
13+
desc "Run tests"
14+
task :test do
15+
sh "bundle exec rake test"
16+
end
17+
18+
desc "Run linter"
19+
task :lint do
20+
sh "bundle exec rubocop"
21+
rescue StandardError
22+
puts "Rubocop not configured yet, skipping..."
23+
end
24+
25+
desc "Run security scan"
26+
task :scan do
27+
sh "bundle exec bundler-audit check --update"
28+
rescue StandardError
29+
puts "Bundler-audit not installed, skipping..."
30+
end
31+
end
32+
33+
desc "Run all CI tasks"
34+
task ci: ["ci:lint", "ci:test"]

0 commit comments

Comments
 (0)