Skip to content

Commit 6c50e0f

Browse files
authored
chore: Add sonarcloud analysis (#589)
* Added sonarcloud analysis * removed unneeded gem
1 parent c9a465a commit 6c50e0f

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

.github/workflows/test-and-deploy.yml

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
steps:
2222
- name: Checkout twilio-ruby
2323
uses: actions/checkout@v2
24+
with:
25+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
2426

2527
- name: Set up Ruby
2628
uses: ruby/setup-ruby@v1
@@ -43,6 +45,19 @@ jobs:
4345
- name: Run Unit Tests
4446
run: make test
4547

48+
- name: Fix code coverage paths
49+
if: ${{ (github.event_name == 'pull_request' || github.ref_type == 'branch') && matrix.ruby == '3.0' && !github.event.pull_request.head.repo.fork }}
50+
working-directory: ./coverage
51+
run: |
52+
sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.json
53+
54+
- name: SonarCloud Scan
55+
if: ${{ (github.event_name == 'pull_request' || github.ref_type == 'branch') && matrix.ruby == '3.0' && !github.event.pull_request.head.repo.fork }}
56+
uses: SonarSource/sonarcloud-github-action@master
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
59+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
60+
4661
deploy:
4762
name: Deploy
4863
if: success() && github.ref_type == 'tag'

sonar-project.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ sonar.tests=spec/
1010
sonar.test.exclusions=spec/integration/**/*.spec.rb
1111

1212
# For Code Coverage analysis
13-
sonar.ruby.coverage.reportPaths=coverage/.resultset.sonarqube.json
13+
sonar.ruby.coverage.reportPaths=coverage/coverage.json

spec/spec_helper.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
require 'simplecov'
2-
SimpleCov.start
1+
if RUBY_VERSION.start_with?('3.0')
2+
require 'simplecov'
3+
require 'simplecov_json_formatter'
4+
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
5+
SimpleCov.start
6+
end
37

48
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
59

0 commit comments

Comments
 (0)