From 619bead7f5a500ece071a56dc8cc918bfc1e518d Mon Sep 17 00:00:00 2001 From: pshu Date: Mon, 20 Jun 2022 22:29:27 +0800 Subject: [PATCH] =?UTF-8?q?chore(ci):=20=F0=9F=91=B7=20coverage=20action?= =?UTF-8?q?=20(#907)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(ci): 👷 coverage action * chore(actions): 👷 split yml * chore(ci-coverage): 👷 continue-on-error when doing coverage * chore(scripts): 🔧 add scripts.cov for coverage * refactor: 🔥 remove coverage github action * Revert "refactor: 🔥 remove coverage github action" This reverts commit 9a683dd82c4abb405243b663074b685c0b6c0204. * feat: ✨ using codecov service --- .github/workflows/coverage.yml | 72 ++++++++++++++++++++++++++++++++++ .gitignore | 1 + jest.config.ts | 7 ++++ package.json | 1 + 4 files changed, 81 insertions(+) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 000000000000..44d0aabe30fb --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,72 @@ +name: Coverage + +env: + NODE_OPTIONS: --max-old-space-size=6144 + +on: + push: + branches: + - master + paths-ignore: + - 'examples/**' + - 'docs/**' + - '**/*.md' + pull_request: + types: + - 'opened' + - 'synchronize' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + coverage: + permissions: + checks: write + pull-requests: write + contents: read + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [16.x] + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: 'https://registry.npmjs.org/' + + - name: Install pnpm + uses: pnpm/action-setup@v2.2.2 + with: + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + run: | + echo "::set-output name=pnpm_cache_dir::$(pnpm store path)" + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }} + key: ${{ runner.os }}-pnpm-store-node-jest-${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store-node-jest-${{ matrix.node-version }}- + + - run: pnpm install + + - run: pnpm build + + - name: Run tests + run: pnpm run cov + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + diff --git a/.gitignore b/.gitignore index 722cd783c668..5d53c220bb05 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ /test/**/fixtures/*/.umi-production /test/**/fixtures/*/src/.umi /test/**/fixtures/*/src/.umi-production +/coverage diff --git a/jest.config.ts b/jest.config.ts index e78fe6e4919b..531a47bcfb9f 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -8,4 +8,11 @@ export default { '/packages/.+/fixtures', ], transformIgnorePatterns: ['/node_modules/', '/compiled/'], + collectCoverageFrom: [ + '**/src/**/*.{ts,tsx}', + '!**/examples/**/*.{js,jsx,ts,tsx}', + '!**/compiled/**/*.{js,jsx}', + '!**/fixtures/**/*.*', + '!packages/create-umi/templates/**/*.*', + ], } as Config.InitialOptions; diff --git a/package.json b/package.json index cebbecb1558b..91a77b7f8773 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "build:force": "umi-scripts turbo --cmd build --no-cache", "build:release": "umi-scripts turbo --cmd build --no-cache -- --declarationMap false", "check:packageFiles": "umi-scripts checkPackageFiles", + "cov": "jest --coverage", "dep:update": "pnpm up --interactive --latest --recursive", "dev": "umi-scripts turbo --cmd dev", "doc:build": "pnpm doc:deps && umi build",