diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..863b6f6 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,33 @@ +name: Lint + +on: + push: + branches: + - master + paths: + - "gemfiles/*" + - "Gemfile" + - "**/*.rb" + - "**/*.gemspec" + - ".github/workflows/lint.yml" + pull_request: + paths: + - "gemfiles/*" + - "Gemfile" + - "**/*.rb" + - "**/*.gemspec" + - ".github/workflows/lint.yml" + +jobs: + rubocop: + name: "RuboCop" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 + bundler-cache: true + - name: Lint Ruby code with RuboCop + run: | + bundle exec rubocop diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cb59563..f6f6b88 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Run tests +name: Tests on: pull_request: @@ -10,38 +10,23 @@ on: jobs: test: - name: "Run tests" - if: "! contains(toJSON(github.event.commits.latest.message), '[ci skip]')" + # Skip running tests for local pull requests (use push event instead), run only for foreign ones + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login != github.event.pull_request.base.repo.owner.login + name: 'Ruby ${{ matrix.ruby }}' runs-on: ubuntu-latest strategy: fail-fast: false matrix: - include: - - ruby: 3.0 - - ruby: 2.7 - - ruby: 2.6 - - ruby: 2.5 - container: - image: ruby:${{ matrix.ruby }} - env: - CI: true + ruby: + - '2.7' + - '3.0' + - '3.1' + - '3.2' steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v2 + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 with: - path: vendor/bundle - key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }} - restore-keys: | - bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }} - bundle-${{ matrix.ruby }}- - - name: Upgrade Bundler to 2.0 (for older Rubies) - run: gem install bundler -v '~> 2.0' - - name: Bundle install - run: | - bundle config path vendor/bundle - bundle install - bundle update - - name: Run Rubocop - run: bundle exec rubocop + ruby-version: ${{ matrix.ruby }} + bundler-cache: true - name: Run RSpec run: bundle exec rspec diff --git a/.rubocop.yml b/.rubocop.yml index 654df6c..98d6d8e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,6 @@ +AllCops: + TargetRubyVersion: "2.5" + Style/Documentation: Exclude: - 'example/**/*' diff --git a/example/Gemfile b/example/Gemfile index 3e4c324..ad7b63f 100644 --- a/example/Gemfile +++ b/example/Gemfile @@ -8,8 +8,8 @@ gem 'yabeda-prometheus' gem 'puma' gem 'rack', '~> 2.2' -gem 'webrick' gem 'sidekiq' +gem 'webrick' gem 'faraday', require: false gem 'sniffer', '>= 0.4.0' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b5b9452..37c5962 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ require 'yabeda/http_requests' require 'faraday' require 'byebug' +require 'yabeda/rspec' RSpec.configure do |config| # Enable flags like --only-failures and --next-failure diff --git a/spec/yabeda/http_requests_spec.rb b/spec/yabeda/http_requests_spec.rb index d10491c..da17c4b 100644 --- a/spec/yabeda/http_requests_spec.rb +++ b/spec/yabeda/http_requests_spec.rb @@ -6,24 +6,18 @@ end describe 'metrics' do - before do - Yabeda.configure! - Faraday.get 'http://sushi.com/nigiri/sake.json' - end - + # rubocop: disable Layout/MultilineMethodCallIndentation it 'holds the proper data' do - expect(Yabeda.http_request_total.values).to( - eq({ host: 'sushi.com', method: 'GET', port: 80 } => 1) - ) - expect(Yabeda.http_response_total.values.keys.first).to( - include({ - host: 'sushi.com', method: 'GET', port: 80, - status: 301 - }) - ) - expect(Yabeda.http_response_duration.values.keys.first).to( - eq(host: 'sushi.com', port: 80, method: 'GET', status: 301) - ) + expect { Faraday.get 'https://example.net/' }.to \ + increment_yabeda_counter(Yabeda.http_request_total).by(1) + .with_tags(method: 'GET', host: 'example.net', port: 443) + .and \ + increment_yabeda_counter(Yabeda.http_response_total).by(1) + .with_tags(method: 'GET', host: 'example.net', port: 443, status: 200) + .and \ + measure_yabeda_histogram(Yabeda.http_response_duration) + .with_tags(method: 'GET', host: 'example.net', port: 443, status: 200) end + # rubocop: enable Layout/MultilineMethodCallIndentation end end