-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: improve GitHub Actions workflow and add code quality checks
- Remove dependency on real API tokens in tests - Add multi-Ruby version testing (3.0, 3.1, 3.2) - Implement test coverage reporting with SimpleCov - Add RuboCop for code style enforcement - Add Brakeman for security analysis - Add bundle-audit for dependency security checks - Add Dependabot configuration for automated updates - Configure caching for faster CI builds Breaking Changes: - Tests now use WebMock instead of real API calls - Require Ruby >= 3.0 Testing: - Use dummy API key for all test runs - All API calls are now mocked with WebMock - Coverage reporting through CodeClimate Configuration: - Add .rubocop.yml for code style - Add dependabot.yml for dependency management - Update gemspec with new development dependencies
- Loading branch information
Showing
19 changed files
with
265 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# .github/dependabot.yml | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "bundler" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
open-pull-requests-limit: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,76 @@ | ||
name: CI | ||
on: [push] | ||
env: | ||
CI: true | ||
API_KEY: ${{ secrets.API_KEY }} | ||
CHATGPT_API_KEY: ${{ secrets.CHATGPT_API_KEY }} | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
ruby-version: [3.1.3] | ||
ruby-version: ['3.0', '3.1', '3.2'] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Ruby ${{ matrix.ruby-version }} | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby-version }} | ||
bundler-cache: true # This will cache installed gems | ||
|
||
- name: Install dependencies | ||
run: | | ||
gem install bundler | ||
bundle install --jobs 4 --retry 3 | ||
- name: Run tests with code coverage | ||
run: COVERAGE=true bundle exec rake test | ||
- name: Install Code Climate Test Reporter | ||
run: | | ||
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter | ||
chmod +x ./cc-test-reporter | ||
working-directory: ${{ github.workspace }} | ||
- name: Push coverage data to Code Climate | ||
run: bundle install | ||
|
||
- name: Run tests | ||
run: bundle exec rake test | ||
env: | ||
COVERAGE: true | ||
# Using a dummy API key since all API calls are mocked | ||
CHATGPT_API_KEY: 'test-key' | ||
|
||
- name: Publish code coverage | ||
uses: paambaati/codeclimate-action@v3.2.0 | ||
if: github.ref == 'refs/heads/main' # Only run on main branch | ||
env: | ||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | ||
run: | | ||
./cc-test-reporter before-build | ||
./cc-test-reporter after-build --exit-code $? | ||
working-directory: ${{ github.workspace }} | ||
with: | ||
coverageCommand: bundle exec rake test | ||
coverageLocations: ${{github.workspace}}/coverage/.resultset.json:simplecov | ||
|
||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: '3.2' | ||
bundler-cache: true | ||
|
||
- name: Run RuboCop | ||
run: bundle exec rubocop | ||
|
||
security: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: '3.2' | ||
bundler-cache: true | ||
|
||
- name: Install Brakeman | ||
run: gem install brakeman | ||
|
||
- name: Run Brakeman | ||
run: brakeman -A -q -w2 | ||
|
||
- name: Check for vulnerable dependencies | ||
run: bundle exec bundle-audit check --update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
# .rubocop.yml | ||
AllCops: | ||
TargetRubyVersion: 2.6 | ||
TargetRubyVersion: 3.0 | ||
NewCops: enable | ||
SuggestExtensions: false | ||
|
||
Style/StringLiterals: | ||
Enabled: true | ||
EnforcedStyle: double_quotes | ||
EnforcedStyle: single_quotes | ||
|
||
Style/StringLiteralsInInterpolation: | ||
Enabled: true | ||
EnforcedStyle: double_quotes | ||
Style/Documentation: | ||
Enabled: false | ||
|
||
Metrics/MethodLength: | ||
Max: 20 | ||
|
||
Metrics/AbcSize: | ||
Max: 30 | ||
|
||
Layout/LineLength: | ||
Max: 120 | ||
Metrics/BlockLength: | ||
Exclude: | ||
- 'test/**/*' | ||
- '*.gemspec' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in chatgpt-ruby.gemspec | ||
gemspec | ||
|
||
gem "rake", "~> 13.0" | ||
gem 'rake', '~> 13.0' | ||
|
||
gem "minitest", "~> 5.0" | ||
gem 'minitest', '~> 5.0' | ||
|
||
gem "rubocop", "~> 1.21" | ||
gem 'rubocop', '~> 1.21' | ||
|
||
gem "rest-client" | ||
gem 'rest-client' | ||
|
||
# Gemfile | ||
group :test do | ||
gem "simplecov" | ||
gem "simplecov_json_formatter" | ||
gem "webmock" | ||
gem 'simplecov' | ||
gem 'simplecov_json_formatter' | ||
gem 'webmock' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
# chatgpt-ruby.gemspec | ||
# frozen_string_literal: true | ||
|
||
require_relative "lib/chatgpt/version" | ||
require_relative 'lib/chatgpt/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "chatgpt-ruby" | ||
spec.name = 'chatgpt-ruby' | ||
spec.version = Chatgpt::Ruby::VERSION | ||
spec.authors = ["Nagendra Dhanakeerthi"] | ||
spec.email = ["nagendra.dhanakeerthi@gmail.com"] | ||
spec.authors = ['Nagendra Dhanakeerthi'] | ||
spec.email = ['nagendra.dhanakeerthi@gmail.com'] | ||
|
||
spec.summary = "Ruby client for OpenAI's ChatGPT API" | ||
spec.description = "A Ruby SDK for OpenAI's ChatGPT API" | ||
spec.homepage = "https://github.com/nagstler/chatgpt-ruby" | ||
spec.license = "MIT" | ||
spec.required_ruby_version = ">= 2.6.0" | ||
spec.homepage = 'https://github.com/nagstler/chatgpt-ruby' | ||
spec.license = 'MIT' | ||
spec.required_ruby_version = '>= 2.6.0' | ||
|
||
spec.metadata["homepage_uri"] = spec.homepage | ||
spec.metadata["source_code_uri"] = "https://github.com/nagstler/chatgpt-ruby" | ||
spec.metadata["changelog_uri"] = "https://github.com/nagstler/chatgpt-ruby/blob/main/CHANGELOG.md" | ||
spec.metadata['homepage_uri'] = spec.homepage | ||
spec.metadata['source_code_uri'] = 'https://github.com/nagstler/chatgpt-ruby' | ||
spec.metadata['changelog_uri'] = 'https://github.com/nagstler/chatgpt-ruby/blob/main/CHANGELOG.md' | ||
|
||
spec.files = Dir.glob("{lib,exe}/**/*") + %w[README.md LICENSE.txt] | ||
spec.bindir = "exe" | ||
spec.files = Dir.glob('{lib,exe}/**/*') + %w[README.md LICENSE.txt] | ||
spec.bindir = 'exe' | ||
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } | ||
spec.require_paths = ["lib"] | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_dependency "rest-client", "~> 2.1" | ||
spec.add_dependency 'rest-client', '~> 2.1' | ||
|
||
spec.add_development_dependency "minitest", "~> 5.0" | ||
spec.add_development_dependency "rake", "~> 13.0" | ||
spec.add_development_dependency "simplecov", "~> 0.21" | ||
spec.add_development_dependency "simplecov_json_formatter", "~> 0.1" | ||
spec.add_development_dependency "webmock", "~> 3.18" | ||
spec.add_development_dependency 'brakeman', '~> 5.2' | ||
spec.add_development_dependency 'bundler-audit', '~> 0.9' | ||
spec.add_development_dependency 'minitest', '~> 5.0' | ||
spec.add_development_dependency 'rake', '~> 13.0' | ||
spec.add_development_dependency 'rubocop', '~> 1.21' | ||
spec.add_development_dependency 'simplecov', '~> 0.21' | ||
spec.add_development_dependency 'simplecov_json_formatter', '~> 0.1' | ||
spec.add_development_dependency 'webmock', '~> 3.18' | ||
spec.metadata['rubygems_mfa_required'] = 'true' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.