From 5724312e64cbdec7a50124e52983167dce3698f0 Mon Sep 17 00:00:00 2001 From: Daniel Eshkeri Date: Wed, 4 Dec 2024 16:39:59 +0000 Subject: [PATCH] feat: added post coverage comment github PR feat: added post faliure comment github PR --- .github/workflows/pull-request.yml | 51 ++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 1fdf43c..4cfe020 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -50,8 +50,8 @@ jobs: run: npm run prettier - name: Run lit-analyzer run: npm run lint:lit-analyzer - - name: Run tests - run: npm run test -- --debug + - name: Run tests and generate coverage + run: npm run test -- --coverage --debug - name: Test tsdoc run: npm run docs - name: Check for modified files @@ -67,6 +67,53 @@ jobs: git add -A git commit -m '[automated commit] lint format and import sort' git push + - name: Post coverage comment + if: always() + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + const coverage = fs.readFileSync("coverage/lcov-report/index.html", "utf8"); + const coverageData = coverage + .split('') + .pop() + ?.split("
")[0] + .replaceAll(/]*>([^<]*)<\/a>/g, "$1"); + const commentBody = ` + ## Test Coverage Report +
+ + Code Coverage Report + + + ${coverageData} +
+
+ `; + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody + }); + - name: Post failure comment + if: failure() + uses: actions/github-script@v6 + with: + script: | + const failedSteps = context.payload.workflow_run.jobs.filter(job => job.conclusion === 'failure'); + const failedStepsDetails = failedSteps.map(step => `- ${step.name}: ${step.conclusion}`).join('\n'); + const commentBody = ` + ## Code Quality Checks Failed + The following checks failed: + ${failedStepsDetails} + `; + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody + }); generate-localizations: name: Generate localizations. needs: [code-quality]