Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ba46518
RI-7038: add code coverage summary for FE tests
KrumTy May 16, 2025
594e269
temp: trigger code change
KrumTy May 16, 2025
5848a65
update workflow
KrumTy May 16, 2025
8e304f0
add jest coverage report
KrumTy May 16, 2025
af70726
update workflows
KrumTy May 16, 2025
a4828dd
update workflow
KrumTy May 16, 2025
d46f303
update workflow
KrumTy May 16, 2025
300eae3
update workflow file
KrumTy May 16, 2025
b5a63a1
update workflow
KrumTy May 16, 2025
e88b8ac
update workflow
KrumTy May 16, 2025
9902796
update workflow
KrumTy May 16, 2025
ce112f9
update workflow
KrumTy May 16, 2025
3cc458b
Merge branch 'main' into feature/RI-7038/code-coverage-workflows
KrumTy May 19, 2025
901ac4b
update workflow
KrumTy May 20, 2025
0ef0260
update workflow
KrumTy May 20, 2025
157d06a
update workflows
KrumTy May 20, 2025
5a80bdd
update code coverage title
KrumTy May 20, 2025
30d728f
remove comment
KrumTy May 20, 2025
d37c01c
add integration tests code coverage
KrumTy May 20, 2025
efe6939
fix workflow
KrumTy May 20, 2025
d2860fd
update integration workflow
KrumTy May 20, 2025
8c93fed
update integration workflow
KrumTy May 20, 2025
601780f
debug integration workflow
KrumTy May 20, 2025
1f8be59
update workflow
KrumTy May 20, 2025
591df4a
remove debug section
KrumTy May 20, 2025
bcc3959
update integration tests coverage markdown
KrumTy May 21, 2025
628c354
remove dep install for jest test coverage
KrumTy May 21, 2025
c941a2a
update integration flow and formatting
KrumTy May 21, 2025
5b500e9
refactor workflows
KrumTy May 21, 2025
a5c83e6
update workflow
KrumTy May 21, 2025
532a0a2
revert temp code change
KrumTy May 21, 2025
c207a2d
RI-7038: apply review suggestions
KrumTy May 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
name: 'Code Coverage'
on:
workflow_call:
inputs:
type:
description: Type of report (unit or integration)
type: string
resource_name:
description: Resource name of coverage report
type: string

jobs:
coverage-unit:
runs-on: ubuntu-latest
name: Unit tests coverage
if: ${{ inputs.type == 'unit' }}
steps:
- uses: actions/checkout@v4

- name: Download Coverage Report
uses: actions/download-artifact@v4
with:
name: ${{ inputs.resource_name }}
path: report

- uses: jwalton/gh-find-current-pr@v1
id: findPr

- uses: ArtiomTr/jest-coverage-report-action@v2
with:
prnumber: ${{ steps.findPr.outputs.number }}
coverage-file: report/coverage/report.json
base-coverage-file: report/coverage/report.json
github-token: ${{ secrets.GITHUB_TOKEN }}
skip-step: all
custom-title: Code Coverage - ${{ inputs.resource_name == 'report-be' && 'Backend' || 'Frontend' }} unit tests

coverage-integration:
runs-on: ubuntu-latest
name: Integration tests coverage
if: ${{ inputs.type == 'integration' }}
steps:
- uses: actions/checkout@v4

- name: Download Coverage Report
uses: actions/download-artifact@v4
with:
name: ${{ inputs.resource_name }}

- name: Parse Coverage Summary
id: parse-coverage
run: |
# Extract coverage data from file.
# Example of processed row:
# Statements : 81.75% ( 16130/19730 )
# field '$3' = 81.75%, field '$5' = 16130
extract_coverage_data() {
local keyword=$1
local field=$2
awk "/$keyword/ {print $field}" integration-coverage.txt | tr -d '\n|%'
}

# Determine status based on percentage
get_status() {
if [ "$(echo "$1 < 50" | bc)" -eq 1 ]; then
echo "🔴"
elif [ "$(echo "$1 < 80" | bc)" -eq 1 ]; then
echo "🟡"
else
echo "🟢"
fi
}

# Extract coverage data from the summary
STATEMENTS_PERCENT=$(extract_coverage_data "Statements" '$3')
STATEMENTS_COVERED=$(extract_coverage_data "Statements" '$5')
STATEMENTS_STATUS=$(get_status $STATEMENTS_PERCENT)

BRANCHES_PERCENT=$(extract_coverage_data "Branches" '$3')
BRANCHES_COVERED=$(extract_coverage_data "Branches" '$5')
BRANCHES_STATUS=$(get_status $BRANCHES_PERCENT)

FUNCTIONS_PERCENT=$(extract_coverage_data "Functions" '$3')
FUNCTIONS_COVERED=$(extract_coverage_data "Functions" '$5')
FUNCTIONS_STATUS=$(get_status $FUNCTIONS_PERCENT)

LINES_PERCENT=$(extract_coverage_data "Lines" '$3')
LINES_COVERED=$(extract_coverage_data "Lines" '$5')
LINES_STATUS=$(get_status $LINES_PERCENT)

# Format as a Markdown table
echo "| Status | Category | Percentage | Covered / Total |" > coverage-table.md
echo "|-------------|-------------|-------------|-----------------|" >> coverage-table.md
echo "| $STATEMENTS_STATUS | Statements | ${STATEMENTS_PERCENT}% | ${STATEMENTS_COVERED} |" >> coverage-table.md
echo "| $BRANCHES_STATUS | Branches | ${BRANCHES_PERCENT}% | ${BRANCHES_COVERED} |" >> coverage-table.md
echo "| $FUNCTIONS_STATUS | Functions | ${FUNCTIONS_PERCENT}% | ${FUNCTIONS_COVERED} |" >> coverage-table.md
echo "| $LINES_STATUS | Lines | ${LINES_PERCENT}% | ${LINES_COVERED} |" >> coverage-table.md

- uses: jwalton/gh-find-current-pr@v1
id: findPr

- name: Post or Update Coverage Summary Comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const table = fs.readFileSync('coverage-table.md', 'utf8');
const commentBody = `### Code Coverage - Integration Tests\n\n${table}`;

// Fetch existing comments on the pull request
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: process.env.RR_Number,
});

// Check if a comment with the same header already exists
const existingComment = comments.find(comment =>
comment.body.startsWith('### Code Coverage - Integration Tests')
);

if (existingComment) {
// Update the existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody,
});
} else {
// Create a new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: process.env.RR_Number,
body: commentBody,
});
}
env:
RR_Number: ${{ steps.findPr.outputs.number }}
9 changes: 8 additions & 1 deletion .github/workflows/tests-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,14 @@ jobs:
sudo mkdir -p /usr/src/app
sudo cp -a ./redisinsight/api/. /usr/src/app/
sudo cp -R ./coverages /usr/src/app && sudo chmod 777 -R /usr/src/app
cd /usr/src/app && npx nyc report -t ./coverages -r text -r text-summary
cd /usr/src/app && npx nyc report -t ./coverages -r text -r text-summary > integration-coverage.txt
cp integration-coverage.txt $GITHUB_WORKSPACE/integration-coverage.txt

- name: Upload integration-coverage as artifact
uses: actions/upload-artifact@v4
with:
name: integration-coverage
path: integration-coverage.txt

- name: Delete Artifact
uses: actions/github-script@v7
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,28 @@ jobs:
uses: ./.github/workflows/tests-frontend.yml
secrets: inherit

frontend-tests-coverage:
needs: frontend-tests
uses: ./.github/workflows/code-coverage.yml
secrets: inherit
with:
resource_name: report-fe
type: unit

backend-tests:
needs: changes
if: inputs.group_tests == 'all' || inputs.group_tests == 'without_e2e' || startsWith(github.ref_name, 'be/') || startsWith(github.ref_name, 'fe-be/') || startsWith(github.ref_name, 'feature/') || startsWith(github.ref_name, 'bugfix/') || startsWith(github.ref_name, 'ric/')
uses: ./.github/workflows/tests-backend.yml
secrets: inherit

backend-tests-coverage:
needs: backend-tests
uses: ./.github/workflows/code-coverage.yml
secrets: inherit
with:
resource_name: report-be
type: unit

integration-tests:
needs: changes
if: inputs.group_tests == 'all' || inputs.group_tests == 'without_e2e' || startsWith(github.ref_name, 'be/') || startsWith(github.ref_name, 'fe-be/') || startsWith(github.ref_name, 'feature/') || startsWith(github.ref_name, 'bugfix/') || startsWith(github.ref_name, 'ric/')
Expand All @@ -110,6 +126,14 @@ jobs:
redis_client: ${{ inputs.redis_client || '' }}
debug: ${{ inputs.debug || false }}

integration-tests-coverage:
needs: integration-tests
uses: ./.github/workflows/code-coverage.yml
secrets: inherit
with:
resource_name: integration-coverage
type: integration

# # E2E Approve
e2e-approve:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"test:api": "yarn --cwd redisinsight/api test",
"test:api:integration": "yarn --cwd redisinsight/api test:api",
"test:watch": "jest ./redisinsight/ui --watch -w 1",
"test:cov": "cross-env NODE_OPTIONS='' jest ./redisinsight/ui --silent --coverage --no-cache --forceExit -w 3",
"test:cov": "cross-env NODE_OPTIONS='' jest ./redisinsight/ui --testLocationInResults --json --outputFile=\"report/coverage/report.json\" --silent --coverage --no-cache --forceExit -w 3",
"test:cov:unit": "jest ./redisinsight/ui --group=-component --coverage -w 1",
"test:cov:component": "jest ./redisinsight/ui --group=component --coverage -w 1",
"type-check:ui": "tsc --project redisinsight/ui --noEmit"
Expand Down
2 changes: 1 addition & 1 deletion redisinsight/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"start:prod": "cross-env NODE_ENV=production node dist/src/main",
"test": "cross-env NODE_ENV=test ./node_modules/.bin/jest -w 1",
"test:watch": "cross-env NODE_ENV=test jest --watch -w 1",
"test:cov": "cross-env NODE_ENV=test ./node_modules/.bin/jest --forceExit --coverage --runInBand",
"test:cov": "cross-env NODE_ENV=test ./node_modules/.bin/jest --testLocationInResults --json --outputFile=\"report/coverage/report.json\" --forceExit --coverage --runInBand",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand -w 1",
"test:e2e": "jest --config ./test/jest-e2e.json -w 1",
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js -d ./config/ormconfig.ts",
Expand Down
Loading