From 1edfbecac62ac4ab3eabbb53e97aebb55dc678eb Mon Sep 17 00:00:00 2001 From: Steve Agalloco Date: Fri, 15 Jan 2021 17:34:38 -0500 Subject: [PATCH] Setup CI with GitHub actions (#8) --- .github/workflows/ci.yml | 45 ++++++++++++++++++++++++++++ .github/workflows/linter.yml | 52 +++++++++++++++++++++++++++++++++ .rubocop.yml | 6 +++- .travis.yml | 25 ---------------- instapaper.gemspec | 4 +-- lib/instapaper/api/folders.rb | 2 +- lib/instapaper/api/oauth.rb | 1 + lib/instapaper/bookmark_list.rb | 4 +-- lib/instapaper/http/response.rb | 8 +++-- lib/instapaper/http/utils.rb | 4 +-- spec/spec_helper.rb | 4 +-- 11 files changed, 116 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/linter.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..62cf909 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +name: CI + +on: + pull_request: + branches: [ '**' ] + +jobs: + # Set the job key. The key is displayed as the job name + # when a job name is not provided + tests: + strategy: + matrix: + ruby: [ '2.6', '2.7', '3.0' ] + + name: Tests - Ruby ${{ matrix.ruby }} + # Set the type of machine to run on + runs-on: ubuntu-latest + + steps: + # Checks out a copy of your repository on the ubuntu-latest machine + - name: Checkout code + uses: actions/checkout@v2 + + - uses: actions/cache@v2 + with: + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems- + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + + - name: Bundle install + run: | + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 --without development + + - name: Run tests + run: | + bundle exec rake test + diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..42c317f --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,52 @@ +--- +########################### +########################### +## Linter GitHub Actions ## +########################### +########################### +name: Lint Code Base + +# +# Documentation: +# https://help.github.com/en/articles/workflow-syntax-for-github-actions +# + +############################# +# Start the job on all push # +############################# +on: + pull_request: + branches: [ '**' ] + +############### +# Set the Job # +############### +jobs: + build: + # Name the Job + name: Lint Code Base + # Set the agent to run on + runs-on: ubuntu-latest + + ################## + # Load all steps # + ################## + steps: + ########################## + # Checkout the code base # + ########################## + - name: Checkout Code + uses: actions/checkout@v2 + with: + # Full git history is needed to get a proper list of changed files within `super-linter` + fetch-depth: 0 + + ################################ + # Run Linter against code base # + ################################ + - name: Lint Code Base + uses: github/super-linter@v3 + env: + VALIDATE_ALL_CODEBASE: false + DEFAULT_BRANCH: main + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.rubocop.yml b/.rubocop.yml index 34e7e78..6cca6d2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,6 +5,7 @@ AllCops: - 'lib/**/*.rb' - 'spec/**/*.rb' DisplayCopNames: true + NewCops: enable Metrics/BlockLength: Max: 36 @@ -54,7 +55,10 @@ Layout/SpaceInsideHashLiteralBraces: Style/TrailingCommaInArguments: EnforcedStyleForMultiline: 'comma' -Style/TrailingCommaInLiteral: +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: 'comma' + +Style/TrailingCommaInHashLiteral: EnforcedStyleForMultiline: 'comma' Style/FileName: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6751655..0000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -language: ruby - -rvm: - - 2.6.0 - - 2.7.0 - - 3.0.0 - - jruby-9.1.7.0 - - ruby-head - -sudo: false - -bundler_args: --without development --retry=3 --jobs=3 - -before_install: - - gem update --system - - gem update bundler - -env: - global: - - JRUBY_OPTS="$JRUBY_OPTS --debug" - -matrix: - allow_failures: - - rvm: ruby-head - fast_finish: true diff --git a/instapaper.gemspec b/instapaper.gemspec index 67c960c..d3a785f 100644 --- a/instapaper.gemspec +++ b/instapaper.gemspec @@ -1,4 +1,4 @@ -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'instapaper/version' @@ -8,7 +8,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'multi_json', '~> 1' spec.add_dependency 'simple_oauth', '~> 0.3' spec.add_dependency 'virtus', '~> 1' - spec.add_development_dependency 'bundler', '~> 1.0' + spec.add_development_dependency 'bundler' spec.author = 'Steve Agalloco' spec.description = "Ruby Client for Instapaper's Full API" spec.email = 'steve.agalloco@gmail.com' diff --git a/lib/instapaper/api/folders.rb b/lib/instapaper/api/folders.rb index 434460d..ad4c435 100644 --- a/lib/instapaper/api/folders.rb +++ b/lib/instapaper/api/folders.rb @@ -27,7 +27,7 @@ module Instapaper # @param order [Array] An array of folder_id:position pairs joined by commas. # @example Ordering folder_ids 100, 200, and 300 # Instapaper.set_order(['100:1','200:2','300:3']) - def set_order(order = []) # rubocop:disable Style/AccessorMethodName + def set_order(order = []) # rubocop:disable Naming/AccessorMethodName perform_post_with_objects('/api/1.1/folders/set_order', {order: order.join(',')}, Instapaper::Folder) end end diff --git a/lib/instapaper/api/oauth.rb b/lib/instapaper/api/oauth.rb index 52a0022..60f821a 100644 --- a/lib/instapaper/api/oauth.rb +++ b/lib/instapaper/api/oauth.rb @@ -10,6 +10,7 @@ module Instapaper response = perform_post_with_unparsed_response('/api/1.1/oauth/access_token', x_auth_username: username, x_auth_password: password, x_auth_mode: 'client_auth') parsed_response = QLineParser.parse(response) raise Instapaper::Error::OAuthError, parsed_response['error'] if parsed_response.key?('error') + Instapaper::Credentials.new(parsed_response) end end diff --git a/lib/instapaper/bookmark_list.rb b/lib/instapaper/bookmark_list.rb index 2832e74..777d490 100644 --- a/lib/instapaper/bookmark_list.rb +++ b/lib/instapaper/bookmark_list.rb @@ -13,8 +13,8 @@ module Instapaper attribute :delete_ids, Array[Integer] end - def each - bookmarks.each { |bookmark| yield(bookmark) } + def each(&block) + bookmarks.each(&block) end end end diff --git a/lib/instapaper/http/response.rb b/lib/instapaper/http/response.rb index 234e6a7..3a4bfb0 100644 --- a/lib/instapaper/http/response.rb +++ b/lib/instapaper/http/response.rb @@ -5,7 +5,9 @@ module Instapaper module HTTP class Response attr_reader :response, :raw_format, :path - def initialize(response, path, raw_format = false) + + # TODO: Change this to a keyword argument (needs a major version bump) + def initialize(response, path, raw_format = false) # rubocop:disable Style/OptionalBooleanParameter @response = response @path = path @raw_format = raw_format @@ -28,9 +30,9 @@ module Instapaper private def parsed - @parsed_response ||= begin + @parsed ||= begin response.parse(:json) - rescue + rescue StandardError response.body end end diff --git a/lib/instapaper/http/utils.rb b/lib/instapaper/http/utils.rb index 41293ce..972fa6e 100644 --- a/lib/instapaper/http/utils.rb +++ b/lib/instapaper/http/utils.rb @@ -57,9 +57,7 @@ module Instapaper end def coerce_hash(response) - if response.key?('hash') - response['instapaper_hash'] = response.delete('hash') - end + response['instapaper_hash'] = response.delete('hash') if response.key?('hash') if response.key?('bookmarks') response['bookmarks'] = response['bookmarks'].collect do |bookmark| coerce_hash(bookmark) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b1796fa..8d73cee 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,9 +26,9 @@ def stub_get(path) end def fixture_path - File.expand_path('../fixtures', __FILE__) + File.expand_path('fixtures', __dir__) end def fixture(file) - File.new(fixture_path + '/' + file) + File.new("#{fixture_path}/#{file}") end