Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): coverage #3690

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
104 changes: 104 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: "Quality"

on:
pull_request_target:
branches:
- main
- master
types:
- opened
- edited
- synchronize

jobs:
coverage:
permissions:
contents: read
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
# - name: Cache dependencies
# uses: actions/cache@v3
# with:
# path: |
# ~/.cache/yarn
# node_modules
# key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
# restore-keys: |
# ${{ runner.os }}-yarn-
# - name: Install dependencies
# run: yarn install --frozen-lockfile
# - name: Build
# run: yarn build
# - name: Run tests
# run: yarn test --coverage || true
# - name: Read coverage data
# id: coverage
# run: |
# echo "lines=$(jq '.total.lines.pct' reports/coverage-summary.json)" >> $GITHUB_OUTPUT
# echo "statements=$(jq '.total.statements.pct' reports/coverage-summary.json)" >> $GITHUB_OUTPUT
# echo "functions=$(jq '.total.functions.pct' reports/coverage-summary.json)" >> $GITHUB_OUTPUT
# echo "branches=$(jq '.total.branches.pct' reports/coverage-summary.json)" >> $GITHUB_OUTPUT
- name: Read coverage data
id: coverage
run: |
echo "lines=100" >> $GITHUB_OUTPUT
echo "statements=100" >> $GITHUB_OUTPUT
echo "functions=100" >> $GITHUB_OUTPUT
echo "branches=100" >> $GITHUB_OUTPUT
- name: Generate GitHub App Token
id: generate_token
uses: actions/create-github-app-token@v1.11.0
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Post coverage comment
uses: actions/github-script@v6
with:
github-token: ${{ steps.generate_token.outputs.token }}
script: |
const lines = `${{ steps.coverage.outputs.lines }}`.trim();
const statements = `${{ steps.coverage.outputs.statements }}`.trim();
const functions = `${{ steps.coverage.outputs.functions }}`.trim();
const branches = `${{ steps.coverage.outputs.branches }}`.trim();

const commentBody = `
### Jest Coverage Report 📊
|Metric | Coverage (%) |
|------------|----------------|
| Lines | ${lines}% |
| Statements | ${statements}% |
| Functions | ${functions}% |
| Branches | ${branches}% |
`;

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const existingComment = comments.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('### Jest Coverage Report'));

if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody,
});
}
1 change: 1 addition & 0 deletions scripts/jest/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
collectCoverageFrom: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.js', '!**/node_modules/**', '!**/__tests__/**'],
coverageDirectory: '<rootDir>/reports',
coveragePathIgnorePatterns: ['\\.stories.*$', 'src/icon/*', 'src/icons/*', 'src/illustration'],
coverageReporters: ['clover', 'json', 'lcov', 'text', 'json-summary'],
globalSetup: '<rootDir>/scripts/jest/env-setup.js',
moduleNameMapper: {
'box-ui-elements-locale-data': '<rootDir>/i18n/en-US.js',
Expand Down
Loading