test: use bun in github action (#50466)

This commit is contained in:
afc163 2024-08-18 00:23:19 +08:00 committed by GitHub
parent 8a230505b8
commit fa3fddb0ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 80 additions and 493 deletions

View File

@ -20,9 +20,7 @@ jobs:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: oven-sh/setup-bun@v2
- uses: actions/cache@v4
with:
@ -54,7 +52,7 @@ jobs:
- name: 🎨 Diff Report
if: ${{ failure() }}
run: npx diff-yarn-lock --source=~tmpProj/yarn.lock --target=~tmpProj/yarn.lock.failed
run: bunx diff-yarn-lock --source=~tmpProj/yarn.lock --target=~tmpProj/yarn.lock.failed
- uses: actions-cool/ci-notice@v1
if: ${{ failure() }}

View File

@ -10,15 +10,13 @@ jobs:
uses: actions/checkout@v4
- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: oven-sh/setup-bun@v2
- name: Install dependencies
run: npm install
run: bun install
- name: Build
run: npm run build
run: bun run build
# ========== Prepare examples ==========
- name: Clear examples
@ -31,6 +29,6 @@ jobs:
path: examples
- name: Modify examples
run: npx tsx scripts/prepare-examples.ts
run: bunx tsx scripts/prepare-examples.ts
- run: npx pkg-pr-new publish --template './examples/examples/*'
- run: bunx pkg-pr-new publish --template './examples/examples/*'

View File

@ -15,73 +15,26 @@ permissions:
contents: read
jobs:
# Prepare node modules. Reuse cache if available
setup:
name: prepare preview
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: cache package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: create package-lock.json
run: npm i --package-lock-only --ignore-scripts
- name: hack for single file
run: |
if [ ! -d "package-temp-dir" ]; then
mkdir package-temp-dir
fi
cp package-lock.json package-temp-dir
- name: cache node_modules
id: node_modules_cache_id
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- name: install
if: steps.node_modules_cache_id.outputs.cache-hit != 'true'
run: npm ci
build-site:
name: build preview
runs-on: ubuntu-latest
needs: setup
steps:
- name: checkout
uses: actions/checkout@v4
- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- name: npm run site
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- name: bun run site
id: site
run: npm run site
run: bun run site
env:
NODE_OPTIONS: "--max_old_space_size=4096"
- name: run e2e test
run: bun run test:site
- name: upload site artifact
uses: actions/upload-artifact@v4
with:
name: site
path: _site/
retention-days: 5
# Upload PR id for next workflow use
- name: Save PR number
if: ${{ always() }}
@ -93,32 +46,3 @@ jobs:
with:
name: pr
path: ./pr-id.txt
site-test:
name: site E2E test
runs-on: ubuntu-latest
needs: [setup, build-site]
steps:
- name: checkout
uses: actions/checkout@v4
- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- name: download site artifact
uses: actions/download-artifact@v4
with:
name: site
path: _site
- name: run e2e test
run: npm run test:site

View File

@ -11,69 +11,24 @@ permissions:
contents: write
jobs:
setup:
build-and-deploy:
runs-on: ubuntu-latest
if: (startsWith(github.ref, 'refs/tags/') && (contains(github.ref_name, '-') == false)) || github.event_name == 'workflow_dispatch'
steps:
- name: checkout
uses: actions/checkout@v4
- name: cache package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- uses: oven-sh/setup-bun@v2
- name: create package-lock.json
run: npm i --package-lock-only --ignore-scripts
- name: hack for single file
run: |
if [ ! -d "package-temp-dir" ]; then
mkdir package-temp-dir
fi
cp package-lock.json package-temp-dir
- name: cache node_modules
id: node_modules_cache_id
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- name: install
if: steps.node_modules_cache_id.outputs.cache-hit != 'true'
run: npm ci
build-and-deploy:
runs-on: ubuntu-latest
needs: setup
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- run: bun install
- name: build site
run: npm run predeploy
run: bun run predeploy
env:
NODE_OPTIONS: "--max_old_space_size=4096"
- name: build dist and bundle analyzer report
run: npm run dist
run: bun run dist
env:
ANALYZER: 1
NODE_OPTIONS: "--max_old_space_size=4096"

View File

@ -13,67 +13,13 @@ permissions:
contents: read
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: cache package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: create package-lock.json
run: npm i --package-lock-only --ignore-scripts
- name: hack for single file
run: |
if [ ! -d "package-temp-dir" ]; then
mkdir package-temp-dir
fi
cp package-lock.json package-temp-dir
- name: cache node_modules
id: node_modules_cache_id
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- name: install
if: steps.node_modules_cache_id.outputs.cache-hit != 'true'
run: npm ci
lint:
runs-on: ubuntu-latest
needs: setup
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- name: lint
run: npm run lint
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run lint
################################ Test ################################
test-react-legacy:
@ -85,68 +31,28 @@ jobs:
env:
REACT: ${{ matrix.react }}
runs-on: ubuntu-latest
needs: setup
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- name: install react 16
if: ${{ matrix.react == '16' }}
run: npm run install-react-16
run: bun run bun-install-react-16
- name: install react 17
if: ${{ matrix.react == '17' }}
run: npm run install-react-17
run: bun run bun-install-react-17
# dom test
- name: dom test
run: npm test -- --maxWorkers=2 --shard=${{matrix.shard}} --coverage
run: bun run test -- --maxWorkers=2 --shard=${{matrix.shard}} --coverage
test-node:
name: test-node
runs-on: ubuntu-latest
needs: setup
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- name: install react 18
run: npm run install-react-18
- name: node test
run: npm run test:node
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun run test:node
test-react-latest:
name: test-react-latest
@ -155,33 +61,14 @@ jobs:
module: ['dom']
shard: ['1/2', '2/2']
runs-on: ubuntu-latest
needs: setup
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- name: install react 18
run: npm run install-react-18
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
# dom test
- name: dom test
run: npm test -- --maxWorkers=2 --shard=${{matrix.shard}} --coverage
run: bun run test -- --maxWorkers=2 --shard=${{matrix.shard}} --coverage
- name: persist coverages
run: |
@ -203,27 +90,9 @@ jobs:
runs-on: ubuntu-latest
needs: build
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- name: install react 18
run: npm run install-react-18
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- name: restore cache from dist
uses: actions/cache@v4
@ -233,13 +102,13 @@ jobs:
- name: dist-min test
if: ${{ matrix.module == 'dist-min' }}
run: npm test
run: bun run test
env:
LIB_DIR: dist-min
- name: dist test
if: ${{ matrix.module == 'dist' }}
run: npm test
run: bun run test
env:
LIB_DIR: dist
@ -250,10 +119,8 @@ jobs:
needs: test-react-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: oven-sh/setup-bun@v2
- run: bun install
- uses: actions/download-artifact@v4
with:
@ -262,8 +129,8 @@ jobs:
path: persist-coverage
- name: Merge Code Coverage
run: |
npx nyc merge persist-coverage/ coverage/coverage-final.json
npx nyc report --reporter text -t coverage --report-dir coverage
bunx nyc merge persist-coverage/ coverage/coverage-final.json
bunx nyc report --reporter text -t coverage --report-dir coverage
rm -rf persist-coverage
- name: Upload coverage to codecov
uses: codecov/codecov-action@v4
@ -274,26 +141,10 @@ jobs:
########################### Compile & Test ###########################
build:
runs-on: ubuntu-latest
needs: setup
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- name: cache lib
uses: actions/cache@v4
@ -308,7 +159,7 @@ jobs:
key: es-${{ github.sha }}
- name: compile
run: npm run compile
run: bun run compile
- name: cache dist
uses: actions/cache@v4
@ -317,7 +168,7 @@ jobs:
key: dist-${{ github.sha }}
- name: dist
run: npm run dist
run: bun run dist
env:
NODE_OPTIONS: "--max_old_space_size=4096"
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
@ -351,36 +202,14 @@ jobs:
test-lib-es:
name: test lib/es module
runs-on: ubuntu-latest
needs: setup
strategy:
matrix:
module: [lib, es]
shard: ['1/2', '2/2']
steps:
- name: checkout
# lib only run in master branch not in pull request
if: ${{ github.event_name != 'pull_request' || matrix.module != 'lib' }}
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: restore cache from package-lock.json
# lib only run in master branch not in pull request
if: ${{ github.event_name != 'pull_request' || matrix.module != 'lib' }}
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
# lib only run in master branch not in pull request
if: ${{ github.event_name != 'pull_request' || matrix.module != 'lib' }}
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- name: restore cache from ${{ matrix.module }}
# lib only run in master branch not in pull request
@ -393,15 +222,11 @@ jobs:
- name: compile
# lib only run in master branch not in pull request
if: ${{ github.event_name != 'pull_request' || matrix.module != 'lib' }}
run: npm run compile
- name: install react 18
if: ${{ github.event_name != 'pull_request' || matrix.module != 'lib' }}
run: npm run install-react-18
run: bun run compile
- name: test
# lib only run in master branch not in pull request
if: ${{ github.event_name != 'pull_request' || matrix.module != 'lib' }}
run: npm test -- --maxWorkers=2 --shard=${{matrix.shard}}
run: bun run test -- --maxWorkers=2 --shard=${{matrix.shard}}
env:
LIB_DIR: ${{ matrix.module }}

View File

@ -21,10 +21,8 @@ jobs:
.ncurc.js
package.json
- name: setup node
uses: actions/setup-node@v4
with:
node-version: 20
- name: setup bun
uses: oven-sh/setup-bun@v2
- name: upgrade deps
id: upgrade
@ -32,7 +30,7 @@ jobs:
if [ ! -d .tmp ] ; then
mkdir .tmp
fi
$(npx npm-check-updates -u > .tmp/upgrade-deps-logs.txt) 2>&1 || true
$(bunx npm-check-updates -u > .tmp/upgrade-deps-logs.txt) 2>&1 || true
if [ -s .tmp/upgrade-deps-logs.txt ]; then
cat .tmp/upgrade-deps-logs.txt
echo "logs<<EOF" >> $GITHUB_OUTPUT

View File

@ -16,41 +16,6 @@ permissions:
contents: read
jobs:
# Prepare node modules. Reuse cache if available
setup:
name: prepare node_modules
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: cache package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: create package-lock.json
run: npm i --package-lock-only --ignore-scripts
- name: hack for single file
run: |
if [ ! -d "package-temp-dir" ]; then
mkdir package-temp-dir
fi
cp package-lock.json package-temp-dir
- name: cache node_modules
id: node_modules_cache_id
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- name: install
if: steps.node_modules_cache_id.outputs.cache-hit != 'true'
run: npm ci
############################ Generate Snapshot ###########################
visual-diff-snapshot:
name: visual-diff snapshot
@ -58,33 +23,17 @@ jobs:
matrix:
shard: ['1/2', '2/2']
runs-on: ubuntu-latest
needs: setup
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- name: generate image snapshots
id: test-image
run: |
node node_modules/puppeteer/install.mjs
npm run version
npm run test:image -- --shard=${{matrix.shard}}
bun run version
bun run test:image -- --shard=${{matrix.shard}}
env:
NODE_OPTIONS: "--max_old_space_size=4096"
@ -102,22 +51,8 @@ jobs:
needs: visual-diff-snapshot
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- uses: oven-sh/setup-bun@v2
- run: bun install
- uses: actions/download-artifact@v4
with:
@ -132,7 +67,7 @@ jobs:
EVENT_NUMBER: ${{ github.event.number }}
BASE_REF: ${{ github.base_ref }}
run: |
npm run test:visual-regression -- --pr-id=$EVENT_NUMBER --base-ref=$BASE_REF --max-workers=2
bun run test:visual-regression -- --pr-id=$EVENT_NUMBER --base-ref=$BASE_REF --max-workers=2
# Upload report in `visualRegressionReport`
- name: upload report artifact

View File

@ -63,8 +63,8 @@ jobs:
runs-on: ubuntu-latest
needs: [upstream-workflow-summary]
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
# We need get persist-index first
- name: download image snapshot artifact
@ -110,7 +110,7 @@ jobs:
echo "✅ Uncompress Finished"
rm package.json
npm i ali-oss --no-save
bun add ali-oss --no-save
echo "✅ Install `ali-oss` Finished"
echo "🤖 Uploading"

View File

@ -12,65 +12,18 @@ permissions:
contents: read
jobs:
# Prepare node modules. Reuse cache if available
setup:
name: prepare node_modules
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: cache package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: create package-lock.json
run: npm i --package-lock-only --ignore-scripts
- name: hack for single file
run: |
if [ ! -d "package-temp-dir" ]; then
mkdir package-temp-dir
fi
cp package-lock.json package-temp-dir
- name: cache node_modules
id: node_modules_cache_id
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- name: install
if: steps.node_modules_cache_id.outputs.cache-hit != 'true'
run: npm ci
test-image:
name: test image
runs-on: ubuntu-latest
needs: setup
steps:
- name: checkout
uses: actions/checkout@v4
- name: restore cache from package-lock.json
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}
- name: restore cache from node_modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install
- name: generate image snapshots
run: |
node node_modules/puppeteer/install.mjs
npm run version
npm run test:image
bun run version
bun run test:image
tar -czvf imageSnapshots.tar.gz imageSnapshots/*
env:
NODE_OPTIONS: "--max_old_space_size=4096"

View File

@ -176,8 +176,8 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
- name: Setup bun
uses: oven-sh/setup-bun@v2
with:
node-version: 16

View File

@ -180,7 +180,7 @@ jobs:
uses: actions/checkout@v4
- name: Setup Node.js (设置 node 版本)
uses: actions/setup-node@v3
uses: oven-sh/setup-bun@v2
with:
node-version: 16

View File

@ -52,7 +52,8 @@
"format": "biome format --write .",
"install-react-16": "npm i --no-save --legacy-peer-deps react@16 react-dom@16 @testing-library/react@12",
"install-react-17": "npm i --no-save --legacy-peer-deps react@17 react-dom@17 @testing-library/react@12",
"install-react-18": "npm i --no-save --legacy-peer-deps react@18 react-dom@18",
"bun-install-react-16": "bun remove react react-dom @testing-library/react && bun add --no-save react@16 react-dom@16 @testing-library/react@12",
"bun-install-react-17": "bun remove react react-dom @testing-library/react && bun add --no-save react@17 react-dom@17 @testing-library/react@12",
"prelint": "dumi setup",
"lint": "npm run version && npm run tsc && npm run lint:script && npm run lint:biome && npm run lint:demo && npm run lint:md && npm run lint:style && npm run lint:changelog",
"lint-fix": "npm run lint-fix:script && npm run lint-fix:demo",