Skip to content

Commit

Permalink
feat: Test coverage and automate publish (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 authored Oct 13, 2023
1 parent 4133883 commit a283340
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
79 changes: 79 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: CI
on:
push:
branches:
- master
tags:
- v[0-9]+.[0-9]+.[0-9]+*
pull_request:
branches:
- master
jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
- name: Install dependencies
run: bundle install
- name: Build
run: gem build *.gemspec
- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
with:
name: gems
path: '*.gem'
test:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
ruby-version: ['2.6', '2.7', '3.0', '3.1']

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Ruby latest
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
- name: Install dependencies
run: bundle install
- name: Run tests and collect coverage
run: bundle exec rake
- name: Upload coverage to Codecov
if: ${{ matrix.ruby-version == 3.1 }}
uses: codecov/codecov-action@v3
with:
files: ${{ github.workspace }}/coverage/coverage.xml
publish:
name: Publish
if: startsWith(github.ref, 'refs/tags/v')
needs: [build, test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: sudo apt-get install -y oathtool
- name: Download all workflow run artifacts
uses: actions/download-artifact@v3
with:
name: gems
path: gems
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
- name: Publish gems to Rubygems
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_API_KEY}\n" > $HOME/.gem/credentials
gem push gems/*.gem
env:
GEM_API_KEY: ${{secrets.GEM_API_KEY}}
3 changes: 2 additions & 1 deletion razorpay-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ Gem::Specification.new do |spec|

spec.add_dependency 'httparty', '~> 0.14'

spec.add_development_dependency 'coveralls', '~> 0.8'
spec.add_development_dependency 'coveralls_reborn', '~> 0.8'
spec.add_development_dependency 'minitest', '~> 5.11'
spec.add_development_dependency 'rake', '~> 12.0'

if RUBY_VERSION >= '2.1.0'
# rubocop is only run in the latest ruby build
# so we use the latest version and don't switch to a
# older version for 1.9.3
spec.add_development_dependency 'simplecov-cobertura'
spec.add_development_dependency 'rubocop', '~> 0.49'
spec.add_development_dependency 'webmock', '~> 3.0'
else
Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
require 'minitest/autorun'
require 'webmock/minitest'
require 'razorpay'
require 'simplecov-cobertura'

Coveralls.wear! if ENV['CI']
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter

def fixture_file(filename)
return '' if filename == ''
Expand Down

0 comments on commit a283340

Please sign in to comment.