From 8f0bff3e482fde326f24510ccfbd65af1ae34486 Mon Sep 17 00:00:00 2001 From: Ajay Krishnan <50063680+ajaynomics@users.noreply.github.com> Date: Sat, 20 Jan 2024 20:53:02 -0500 Subject: [PATCH] build: ci github action --- .github/workflows/ci.yml | 37 +++++++++++++++++++ .github/workflows/main.yml | 27 -------------- .rubocop.yml | 2 + Gemfile | 2 + Gemfile.lock | 7 ++++ .../clients/text_generation/test_helpers.rb | 2 +- test/cloudflare/message_test.rb | 4 +- test/cloudflare/result_test.rb | 4 +- 8 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d01de5d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: Tests +on: + pull_request: + push: + branches: + - main +jobs: + tests: + runs-on: ubuntu-latest + strategy: + matrix: + ruby: [ "3.0", "3.1", "3.2" ] + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler: default + bundler-cache: true + + - name: Run tests + run: | + bundle exec rake + linters: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 + bundler: default + bundler-cache: true + - name: rubocop check + run: | + bundle exec rubocop diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 6e5d801..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Ruby - -on: - push: - branches: - - master - - pull_request: - -jobs: - build: - runs-on: ubuntu-latest - name: Ruby ${{ matrix.ruby }} - strategy: - matrix: - ruby: - - '3.2.2' - - steps: - - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Run the default task - run: bundle exec rake diff --git a/.rubocop.yml b/.rubocop.yml index 2b02314..164bdee 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,7 @@ require: - standard + - rubocop-minitest + - rubocop-rake inherit_gem: standard: config/base.yml diff --git a/Gemfile b/Gemfile index ef8488b..f74f83a 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,8 @@ gem "rake" gem "minitest" gem "rubocop" +gem "rubocop-minitest" +gem "rubocop-rake" gem "standard", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 53ed0e4..adc09dc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -70,9 +70,14 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) + rubocop-minitest (0.34.5) + rubocop (>= 1.39, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) rubocop-performance (1.20.2) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) standard (1.33.0) @@ -106,6 +111,8 @@ DEPENDENCIES minitest rake rubocop + rubocop-minitest + rubocop-rake standard webmock diff --git a/test/cloudflare/ai/clients/text_generation/test_helpers.rb b/test/cloudflare/ai/clients/text_generation/test_helpers.rb index 240163c..98dde39 100644 --- a/test/cloudflare/ai/clients/text_generation/test_helpers.rb +++ b/test/cloudflare/ai/clients/text_generation/test_helpers.rb @@ -7,7 +7,7 @@ module TestHelpers def stub_response_for_successful_completion(response: "Happy song") stub_request(:post, @url) - .to_return(status: 200, body: {result: {response:}, success: true}.to_json) + .to_return(status: 200, body: {result: {response: response}, success: true}.to_json) end def stub_response_for_unsuccessful_completion diff --git a/test/cloudflare/message_test.rb b/test/cloudflare/message_test.rb index e603508..e1b511b 100644 --- a/test/cloudflare/message_test.rb +++ b/test/cloudflare/message_test.rb @@ -30,10 +30,10 @@ def test_to_json private def system_message_fixture(content: "Hello") - Cloudflare::AI::Message.new(role: "system", content:) + Cloudflare::AI::Message.new(role: "system", content: content) end def user_message_fixture(content: "Hello") - Cloudflare::AI::Message.new(role: "user", content:) + Cloudflare::AI::Message.new(role: "user", content: content) end end diff --git a/test/cloudflare/result_test.rb b/test/cloudflare/result_test.rb index 47e22fc..4077972 100644 --- a/test/cloudflare/result_test.rb +++ b/test/cloudflare/result_test.rb @@ -4,14 +4,14 @@ class Cloudflare::AI::ResultTest < Minitest::Test def test_successful_result result = Cloudflare::AI::Result.new(successful_response_json) assert result.success? - assert !result.failure? + refute result.failure? assert_equal successful_response_json["result"]["response"], result.response end def test_unsuccessful_result result = Cloudflare::AI::Result.new(unsuccessful_response_json) - assert !result.success? + refute result.success? assert result.failure? assert_equal unsuccessful_response_json["errors"][0]["code"], result.errors[0]["code"]