Skip to content

Commit

Permalink
Generate code coverage reports using CodeCov
Browse files Browse the repository at this point in the history
  • Loading branch information
heshanpadmasiri committed Jul 26, 2023
1 parent e5e0d51 commit 89744c8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 36 deletions.
22 changes: 4 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Ballerina Test
uses: ballerina-platform/ballerina-action/@nightly
with:
args: test --code-coverage ./twitter
args: test --test-report --code-coverage --coverage-format=xml ./twitter
env:
JAVA_HOME: /usr/lib/jvm/default-jvm
API_KEY: ${{ secrets.API_KEY }}
Expand All @@ -49,22 +49,8 @@ jobs:
CALLBACK_URL: ${{ secrets.CALLBACK_URL }}
PORT: ${{ secrets.PORT }}

# Read the ballerina test results
- name: Read Ballerina Test Results
id: test_results
run: |
content=`cat ./twitter/target/report/test_results.json`
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
echo "::set-output name=testResultsJson::$content"
# Print the code coverage information
- name: Code Coverage
run: |
echo "Code Coverage Percentage : ${{fromJson(steps.test_results.outputs.testResultsJson).coveragePercentage}}"
echo "Covered Code Lines : ${{fromJson(steps.test_results.outputs.testResultsJson).coveredLines}}"
echo "Total Code Lines : $(expr ${{fromJson(steps.test_results.outputs.testResultsJson).missedLines}} + ${{fromJson(steps.test_results.outputs.testResultsJson).coveredLines}})"
echo "Code Coverage Percentage : ${{fromJson(steps.test_results.outputs.testResultsJson).coveragePercentage}}"
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3

- name: Alert notifier on failure
if: failure() && (github.event.action == 'check_connector_for_breaking_changes')
Expand All @@ -81,4 +67,4 @@ jobs:
}
}'
20 changes: 3 additions & 17 deletions .github/workflows/daily-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
uses: ballerina-platform/ballerina-action/@nightly
with:
args:
test --code-coverage ./twitter
test --test-report --code-coverage --coverage-format=xml --code-coverage ./twitter
env:
JAVA_HOME: /usr/lib/jvm/default-jvm
API_KEY: ${{ secrets.API_KEY }}
Expand All @@ -63,22 +63,8 @@ jobs:
CALLBACK_URL: ${{ secrets.CALLBACK_URL }}
PORT: ${{ secrets.PORT }}

# Read the ballerina test results
- name: Read Ballerina Test Results
id: test_results
run: |
content=`cat ./twitter/target/report/test_results.json`
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
echo "::set-output name=testResultsJson::$content"
# Print the code coverage information
- name: Code Coverage
run: |
echo "Covered Code Lines : ${{fromJson(steps.test_results.outputs.testResultsJson).coveredLines}}"
echo "Total Code Lines : $(expr ${{fromJson(steps.test_results.outputs.testResultsJson).missedLines}} + ${{fromJson(steps.test_results.outputs.testResultsJson).coveredLines}})"
echo "Code Coverage Percentage : ${{fromJson(steps.test_results.outputs.testResultsJson).coveragePercentage}}"
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3

# Send notification when build fails
- name: Notify failure
Expand Down
20 changes: 19 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,22 @@ jobs:
args: pack ./twitter
env:
JAVA_HOME: /usr/lib/jvm/default-jvm


- name: Ballerina Tests
# tests will be skipped if the PR is from a forked repository (as the secrets are not available)
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
uses: ballerina-platform/ballerina-action/@nightly
with:
args: test --test-report --code-coverage --coverage-format=xml ./twitter
env:
JAVA_HOME: /usr/lib/jvm/default-jvm
API_KEY: ${{ secrets.API_KEY }}
API_SECRET: ${{ secrets.API_SECRET }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }}
DEV_ENVIRONMENT_NAME: ${{ secrets.DEV_ENVIRONMENT_NAME }}
CALLBACK_URL: ${{ secrets.CALLBACK_URL }}
PORT: ${{ secrets.PORT }}

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Ballerina Twitter Connector

[![Build](https://github.com/ballerina-platform/module-ballerinax-twitter/workflows/CI/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-twitter/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/ballerina-platform/module-ballerinax-twitter/branch/main/graph/badge.svg)](https://codecov.io/gh/ballerina-platform/module-ballerinax-twitter)
[![GitHub Last Commit](https://img.shields.io/github/last-commit/ballerina-platform/module-ballerinax-twitter.svg)](https://github.com/ballerina-platform/module-ballerinax-twitter/commits/master)
[![GraalVM Check](https://github.com/ballerina-platform/module-ballerinax-twitter/actions/workflows/build-with-bal-test-native.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-twitter/actions/workflows/build-with-bal-test-native.yml)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
Expand Down

0 comments on commit 89744c8

Please sign in to comment.