Skip to content

[SDK] Chore: Sets coverage thresholds #15983

[SDK] Chore: Sets coverage thresholds

[SDK] Chore: Sets coverage thresholds #15983

Workflow file for this run

name: CI
on:
push:
branches: ["main"]
pull_request:
types: [opened, synchronize]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# To use Remote Caching, uncomment the next lines and follow the steps below.
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TW_SECRET_KEY: ${{ secrets.TW_SECRET_KEY }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
jobs:
optimize_ci:
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.check_skip.outputs.skip }}
steps:
- name: Optimize CI
id: check_skip
uses: withgraphite/graphite-ci-action@main
with:
graphite_token: ${{ secrets.GRAPHITE_OMTIMIZE_TOKEN }}
build:
needs: optimize_ci
if: needs.optimize_ci.outputs.skip == 'false'
runs-on: ubuntu-latest
name: Build Packages
steps:
- name: Check out the code
uses: actions/checkout@v4
- name: Setup & Install
uses: ./.github/composite-actions/install
- name: Build Packages
run: pnpm build:packages
lint:
needs: optimize_ci
if: needs.optimize_ci.outputs.skip == 'false'
timeout-minutes: 15
name: Lint Packages
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v4
- name: Setup & Install
uses: ./.github/composite-actions/install
- name: Setup Biome
uses: biomejs/setup-biome@v2
with:
version: latest
- run: pnpm lint
test:
needs: optimize_ci
if: needs.optimize_ci.outputs.skip == 'false'
timeout-minutes: 15
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v4
- name: Setup & Install
uses: ./.github/composite-actions/install
- name: Set up foundry
uses: foundry-rs/foundry-toolchain@v1
with:
cache: false
version: nightly-c4a984fbf2c48b793c8cd53af84f56009dd1070c
- run: pnpm test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
directory: packages/
flags: packages
verbose: true
- name: Check coverage on changed files
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const coverage = JSON.parse(fs.readFileSync('./coverage/coverage-summary.json', 'utf8'));
// Get list of changed files
const exec = require('child_process').execSync;
const diff = exec('git diff --name-only origin/${{ github.base_ref }} HEAD')
.toString()
.split('\n')
.filter(file => file.endsWith('.ts') || file.endsWith('.tsx'));
let failed = false;
const threshold = 80; // Match your vitest config threshold
for (const file of diff) {
if (coverage[file]) {
const fileCoverage = coverage[file];
if (fileCoverage.lines.pct < threshold) {
failed = true;
console.log(`${file} has insufficient coverage: ${fileCoverage.lines.pct}%`);
}
}
}
if (failed) {
core.setFailed('Some changed files have insufficient coverage');
}
e2e:
needs: optimize_ci
if: needs.optimize_ci.outputs.skip == 'false'
timeout-minutes: 15
name: E2E Tests
runs-on: ubuntu-latest
strategy:
matrix:
package_manager: [npm, yarn, pnpm, bun]
bundler: [vite, webpack, esbuild]
steps:
- name: Check out the code
uses: actions/checkout@v4
- name: Setup & Install
uses: ./.github/composite-actions/install
- name: Build Packages
run: pnpm build:packages
- name: Install Yarn (if needed)
if: matrix.package_manager == 'yarn'
run: npm install -g [email protected]
- name: Create test project
run: |
mkdir test-project
cd test-project
npm init -y
${{ matrix.package_manager }} add react react-dom ../packages/thirdweb
- name: Create test file
run: |
cd test-project
echo "import { createThirdwebClient } from 'thirdweb'; console.log(createThirdwebClient({clientId: "foo_bar_baz"}));" > index.js
- name: Bundle with vite
if: matrix.bundler == 'vite'
run: |
cd test-project
${{matrix.package_manager}} add vite
echo 'import { defineConfig } from "vite"; import {resolve} from "path"; export default defineConfig({ build: { lib: { entry: resolve(__dirname, "index.js"), name: "e2e_test" }, outDir: "dist" }});' > vite.config.js
npx vite build
- name: Bundle with webpack
if: matrix.bundler == 'webpack'
run: |
cd test-project
${{matrix.package_manager}} add webpack webpack-cli
echo 'const path = require("path"); module.exports = { mode: "production", entry: "./index.js", output: { path: path.resolve(__dirname, "dist"), filename: "bundle.js" }};' > webpack.config.js
npx webpack
- name: Bundle with esbuild
if: matrix.bundler == 'esbuild'
run: |
cd test-project
${{matrix.package_manager}} add esbuild
npx esbuild index.js --bundle --outdir=dist
- name: Verify bundle
run: |
cd test-project/dist
file_count=$(find . -type f | wc -l)
if [ "$file_count" -gt 0 ]; then
echo "Bundling successful"
else
echo "Bundling failed"
exit 1
fi
size:
needs: optimize_ci
# only run on pull requests
if: github.event_name == 'pull_request' && needs.optimize_ci.outputs.skip == 'false'
timeout-minutes: 15
name: "Size"
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v4
- name: Setup & Install
uses: ./.github/composite-actions/install
- name: Report bundle size
uses: andresz1/size-limit-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
package_manager: pnpm
directory: packages/thirdweb