Skip to content

Commit

Permalink
combined both comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DE7924 committed Dec 5, 2024
1 parent d9fdb87 commit 04cf9e9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 86 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,3 @@ jobs:
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
- name: Post failure comment
if: always()
# if: failure()
uses: actions/github-script@v6
with:
script: |
const conclusion = '${{ steps.perform-codeql-analysis.conclusion }}';
const outcome = '${{ steps.perform-codeql-analysis.outcome }}';
const sarif = '${{ steps.perform-codeql-analysis.outputs.db-locations }}';
const commentBody = `
## CodeQL Analysis
${conclusion}
${outcome}
${sarif}
`;
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const comment = comments.find(comment => comment.body.includes('CodeQL Analysis'));
if (comment) {
await github.rest.issues.updateComment({
comment_id: comment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
}
79 changes: 29 additions & 50 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,81 +75,59 @@ jobs:
git add -A
git commit -m '[automated commit] lint format and import sort'
git push
- name: Post coverage comment
- name: PR checks complete
if: always()
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const steps = [
{ name: 'Install dependencies', conclusion: '${{ steps.install-dependencies.outcome }}' },
{ name: 'Run custom elements manifest analyzer', conclusion: '${{ steps.run-custom-elements-manifest-analyzer.outcome }}' },
{ name: 'Run eslint', conclusion: '${{ steps.run-eslint.outcome }}' },
{ name: 'Run prettier', conclusion: '${{ steps.run-prettier.outcome }}' },
{ name: 'Run lit-analyzer', conclusion: '${{ steps.run-lit-analyzer.outcome }}' },
{ name: 'Run tests and generate coverage', conclusion: '${{ steps.run-tests-and-generate-coverage.outcome }}' },
{ name: 'Test tsdoc', conclusion: '${{ steps.test-tsdoc.outcome }}' },
{ name: 'Check for modified files', conclusion: '${{ steps.git-check.outcome }}' },
{ name: 'Update changes in GitHub repository', conclusion: '${{ steps.update-changes-in-github-repository.outcome }}' }
]
const failedSteps = steps.filter(step => step.conclusion === 'failure');
const skippedSteps = steps.filter(step => step.conclusion === 'skipped');
const passedSteps = steps.filter(step => step.conclusion === 'success');
const failedStepsDetails = failedSteps.map(step => `- ❌ - ${step.name} failed`).join('\n');
const skippedStepsDetails = skippedSteps.map(step => `- ⏭️ - ${step.name} skipped`).join('\n');
const passedStepsDetails = passedSteps.map(step => `- ✅ - ${step.name} passed`).join('\n');
const coverage = fs.readFileSync("coverage/lcov-report/index.html", "utf8");
const coverageData = coverage
.split('<table class="coverage-summary">')
.pop()
?.split("</table>")[0]
.replaceAll(/<a [^>]*>([^<]*)<\/a>/g, "$1");
const commentBody = `
## Test Coverage Report
## PR Checks Complete
${failedSteps.length > 0 ? `${failedStepsDetails}` : ''}
${skippedSteps.length > 0 ? `${skippedStepsDetails}` : ''}
${passedSteps.length > 0 ? `${passedStepsDetails}` : ''}
<details>
<summary>
Code Coverage Report
📈 - Code Coverage Report
</summary>
<table class="coverage-summary">
${coverageData}
</table>
</details>
`;
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const comment = comments.find(comment => comment.body.includes('Test Coverage Report'));
if (comment) {
await github.rest.issues.updateComment({
comment_id: comment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
}
- name: Post failure comment
if: always()
uses: actions/github-script@v6
with:
script: |
const failedSteps = [
{ name: 'Install dependencies', conclusion: '${{ steps.install-dependencies.outcome }}' },
{ name: 'Run custom elements manifest analyzer', conclusion: '${{ steps.run-custom-elements-manifest-analyzer.outcome }}' },
{ name: 'Run eslint', conclusion: '${{ steps.run-eslint.outcome }}' },
{ name: 'Run prettier', conclusion: '${{ steps.run-prettier.outcome }}' },
{ name: 'Run lit-analyzer', conclusion: '${{ steps.run-lit-analyzer.outcome }}' },
{ name: 'Run tests and generate coverage', conclusion: '${{ steps.run-tests-and-generate-coverage.outcome }}' },
{ name: 'Test tsdoc', conclusion: '${{ steps.test-tsdoc.outcome }}' },
{ name: 'Check for modified files', conclusion: '${{ steps.git-check.outcome }}' },
{ name: 'Update changes in GitHub repository', conclusion: '${{ steps.update-changes-in-github-repository.outcome }}' }
].filter(step => step.conclusion === 'failure');
const failedStepsDetails = failedSteps.map(step => `- ${step.name}`).join('\n');
const commentBody = failedSteps.length > 0 ? `
## Code Quality Checks
The following checks failed:
${failedStepsDetails}
` : `
## Code Quality Checks
All code quality checks passed.
`;
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const comment = comments.find(comment => comment.body.includes('Code Quality Checks'));
const comment = comments.find(comment => comment.body.includes('PR Checks Complete'));
if (comment) {
await github.rest.issues.updateComment({
comment_id: comment.id,
Expand All @@ -165,6 +143,7 @@ jobs:
body: commentBody
});
}
generate-localizations:
name: Generate localizations.
needs: [code-quality]
Expand Down

0 comments on commit 04cf9e9

Please sign in to comment.