From 233eeaefecfe44c7b28a0101ac8176f2adf3445c Mon Sep 17 00:00:00 2001 From: ahmad Date: Wed, 7 May 2025 13:29:03 +0300 Subject: [PATCH 1/3] add EnricoMi/publish-unit-test-result-action@v2 action to view the result in comment in the pr and ensure that the html report artifact always exited --- .github/workflows/ci.yml | 99 ++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7dc36a0..05805a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,19 +1,22 @@ -name: CI with Kover +name: CI with Kover & PR Comment on: + push: + branches: [ main, development ] pull_request: branches: [ main, development ] workflow_dispatch: permissions: - contents: write - issues: write + contents: read pull-requests: write + checks: write jobs: run-tests: - name: Execute Tests & Generate Coverage + name: Run Tests and Generate Coverage runs-on: ubuntu-latest + steps: - name: Checkout uses: actions/checkout@v4 @@ -28,66 +31,62 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - - name: Run Unit Tests - run: ./gradlew test + - name: Run tests and generate Kover reports + run: ./gradlew test koverHtmlReport - - name: Generate Kover XML Report - run: ./gradlew koverXmlReport + - name: Verify coverage thresholds (≥ 80%) + run: ./gradlew koverVerify - - name: Upload coverage report XML - uses: actions/upload-artifact@v4 + - name: Debug test result files if: always() - with: - name: kover-coverage-report - path: build/reports/kover/xml/report.xml - retention-days: 1 + run: | + echo "Checking if test results exist..." + ls -l build/test-results/test || echo "Directory not found" - - name: Test Summary - uses: test-summary/action@v2 - with: - paths: "**/build/test-results/**/*.xml" + - name: Upload test results (JUnit XML) if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results + path: build/test-results/test/TEST-*.xml - - name: Verify coverage thresholds - run: ./gradlew koverVerify + - name: Upload Kover HTML report + if: always() + uses: actions/upload-artifact@v4 + with: + name: kover-html-report + path: build/reports/kover/html/ - analyze-pr: - name: Analyze PR Code Coverage + publish-test-results: + name: Comment on PR with Test Results needs: run-tests runs-on: ubuntu-latest if: ${{ always() && github.event_name == 'pull_request' }} steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Download test results + uses: actions/download-artifact@v4 + with: + name: test-results + path: test-results - - name: Check for Kover artifact - id: check_artifact - uses: actions/github-script@v6 + - name: Publish Unit Test Results as PR comment + uses: EnricoMi/publish-unit-test-result-action@v2 with: - script: | - const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.runId - }); - return artifacts.data.artifacts.some(a => a.name === "kover-coverage-report"); - - - name: Download coverage report - if: steps.check_artifact.outputs.result == 'true' + files: test-results/TEST-*.xml + + upload-coverage-html: + name: Upload HTML Coverage Report (Separate Job) + needs: run-tests + runs-on: ubuntu-latest + if: always() + + steps: + - name: Download Kover HTML report uses: actions/download-artifact@v4 with: - name: kover-coverage-report - path: build/reports/kover + name: kover-html-report + path: build/reports/kover/html/ - - name: Comment on PR with coverage - uses: madrapps/jacoco-report@v1.7.1 - with: - paths: build/reports/kover/**/xml/report.xml - token: ${{ secrets.GITHUB_TOKEN }} - min-coverage-overall: 80 - min-coverage-changed-files: 80 - update-comment: true - title: Code Coverage Summary - pass-emoji: '✅' - fail-emoji: '❌' + - name: Confirm HTML report upload + run: echo "Kover HTML report is available as artifact." From ac5b8c373bed9dd0ee8dae4c379c11a26e561695 Mon Sep 17 00:00:00 2001 From: ahmad Date: Wed, 7 May 2025 14:06:41 +0300 Subject: [PATCH 2/3] change the name of the action to lower case and no space name --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 05805a9..1d07659 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: CI with Kover & PR Comment +name: ci-kover on: push: From de7fad1a65582c7b3c6cd9cf6e67d483d43e6371 Mon Sep 17 00:00:00 2001 From: ahmad Date: Wed, 7 May 2025 16:30:53 +0300 Subject: [PATCH 3/3] remove from push --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d07659..4c28ae1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,12 +1,11 @@ name: ci-kover on: - push: - branches: [ main, development ] pull_request: branches: [ main, development ] workflow_dispatch: + permissions: contents: read pull-requests: write