Skip to content

feat: Setup Vitest #4601

feat: Setup Vitest

feat: Setup Vitest #4601

Workflow file for this run

name: Gazebo CI
on:
push:
branches:
- main
- staging
pull_request:
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
install:
name: Install deps
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-gazebo-node-modules
with:
path: |
node_modules
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
# - name: Setup Bun
# uses: oven-sh/setup-bun@v1
# if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
- name: Install packages
if: ${{ steps.cache-node-modules.outputs.cache-hit != 'true' }}
run: |
yarn install
lint:
name: Run Lint
runs-on: ubuntu-latest
needs: install
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-gazebo-node-modules
with:
path: |
node_modules
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Run linter
run: |
yarn lint
type-check:
name: Run Type Checker
runs-on: ubuntu-latest
needs: install
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-gazebo-node-modules
with:
path: |
node_modules
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Run TSC
run: |
yarn type-check
format-check:
name: Run Prettier Check
runs-on: ubuntu-latest
needs: install
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-gazebo-node-modules
with:
path: |
node_modules
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Run Prettier
run: |
yarn format-check
codecov-startup:
name: Codecov Startup
needs: install
uses: codecov/gha-workflows/.github/workflows/[email protected]
secrets: inherit
runner-indexes-craco:
runs-on: ubuntu-latest
name: Generate runner indexes CRACO
needs: install
env:
TEST_SPLIT_NUMBER: 80
outputs:
json: ${{ steps.generate-index-list.outputs.json }}
test_list_array: ${{ steps.generate-index-list.outputs.test_list_array }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate test index list
id: generate-index-list
run: |
shopt -s globstar
TEST_LIST=$(ls src/**/*.spec.js src/**/*.spec.jsx src/**/*.spec.ts src/**/*.spec.tsx | jq -R -s -c 'split("\n")[:-1]')
TEST_LENGTH=$(echo $TEST_LIST | jq length)
MAX_INDEX=$((($TEST_LENGTH/${{ env.TEST_SPLIT_NUMBER }})))
MAX_INDEX=$(($MAX_INDEX < 0 ? 0 : $TEST_LENGTH % ${{ env.TEST_SPLIT_NUMBER }} == 0 ? $MAX_INDEX - 1 : $MAX_INDEX))
INDEX_LIST=$(seq 0 ${MAX_INDEX})
INDEX_JSON=$(jq --null-input --compact-output '. |= [inputs]' <<< ${INDEX_LIST})
echo json=${INDEX_JSON} >> $GITHUB_OUTPUT
echo test_list_array=$(echo ${TEST_LIST} | jq -c '[_nwise(${{ env.TEST_SPLIT_NUMBER }})]') >> $GITHUB_OUTPUT
test-craco:
name: 'Test Runner #${{ matrix.runner-index }} - CRACO'
needs: [install, codecov-startup, runner-indexes-craco]
runs-on: ubuntu-latest
strategy:
matrix:
runner-index: ${{ fromjson(needs.runner-indexes-craco.outputs.json) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-gazebo-node-modules
with:
path: |
node_modules
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Run tests
run: |
yarn generate-icons:webpack
TESTS=$(echo $TEST_LIST | jq -cr 'join(" ")')
yarn test:ci --maxWorkers=2 $TESTS
env:
JEST_JUNIT_OUTPUT_DIR: ./reports/junit/
TEST_LIST: ${{ tojson(fromjson(needs.runner-indexes-craco.outputs.test_list_array)[matrix.runner-index]) }}
- name: Upload test results to Codecov
uses: codecov/test-results-action@v1
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov'}}
with:
token: ${{ secrets.CODECOV_ORG_TOKEN }}
url: ${{ secrets.CODECOV_URL }}
- name: Upload test results to Codecov staging
uses: codecov/test-results-action@v1
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov'}}
with:
token: ${{ secrets.CODECOV_ORG_TOKEN_STAGING }}
url: ${{ secrets.CODECOV_STAGING_URL }}
- name: Upload test results to Codecov QA
uses: codecov/test-results-action@v1
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov'}}
with:
token: ${{ secrets.CODECOV_QA_TOKEN }}
url: ${{ secrets.CODECOV_QA_URL }}
- name: Upload test results to Codecov public QA
uses: codecov/test-results-action@v1
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov'}}
with:
token: ${{ secrets.CODECOV_PUBLIC_QA_TOKEN }}
url: ${{ secrets.CODECOV_PUBLIC_QA_URL }}
- name: Install CLI
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
run: |
make test_env.install_cli
## Don't upload on forks for now.
- name: Upload coverage to Production
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
run: |
codecovcli -u ${{ secrets.CODECOV_URL }} do-upload -t ${{ secrets.CODECOV_ORG_TOKEN }} --fail-on-error --name "CRACO-${{ matrix.runner-index }}"
- name: Upload coverage to Staging
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
run: |
codecovcli -u ${{ secrets.CODECOV_STAGING_URL }} do-upload -t ${{ secrets.CODECOV_ORG_TOKEN_STAGING }} --fail-on-error
- name: Upload coverage to QA
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
run: |
codecovcli -u ${{ secrets.CODECOV_QA_URL }} do-upload -t ${{ secrets.CODECOV_QA_TOKEN }} --fail-on-error
- name: Upload coverage to Public QA
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
run: |
codecovcli -u ${{ secrets.CODECOV_PUBLIC_QA_URL }} do-upload -t ${{ secrets.CODECOV_PUBLIC_QA_TOKEN }} --fail-on-error
runner-indexes-vitest:
runs-on: ubuntu-latest
name: Generate runner indexes Vitest
needs: install
env:
TEST_SPLIT_NUMBER: 80
outputs:
json: ${{ steps.generate-index-list.outputs.json }}
test_list_array: ${{ steps.generate-index-list.outputs.test_list_array }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate test index list
id: generate-index-list
run: |
shopt -s globstar
TEST_LIST=$(ls src/**/*.test.js src/**/*.test.jsx src/**/*.test.ts src/**/*.test.tsx | jq -R -s -c 'split("\n")[:-1]')
TEST_LENGTH=$(echo $TEST_LIST | jq length)
MAX_INDEX=$((($TEST_LENGTH/${{ env.TEST_SPLIT_NUMBER }})))
MAX_INDEX=$(($MAX_INDEX < 0 ? 0 : $TEST_LENGTH % ${{ env.TEST_SPLIT_NUMBER }} == 0 ? $MAX_INDEX - 1 : $MAX_INDEX))
INDEX_LIST=$(seq 0 ${MAX_INDEX})
INDEX_JSON=$(jq --null-input --compact-output '. |= [inputs]' <<< ${INDEX_LIST})
echo json=${INDEX_JSON} >> $GITHUB_OUTPUT
echo test_list_array=$(echo ${TEST_LIST} | jq -c '[_nwise(${{ env.TEST_SPLIT_NUMBER }})]') >> $GITHUB_OUTPUT
test-vitest:
name: 'Test Runner #${{ matrix.runner-index }} - Vitest'
needs: [install, codecov-startup, runner-indexes-vitest]
runs-on: ubuntu-latest
strategy:
matrix:
runner-index: ${{ fromjson(needs.runner-indexes-vitest.outputs.json) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-gazebo-node-modules
with:
path: |
node_modules
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Run tests
run: |
TESTS=$(echo $TEST_LIST | jq -cr 'join(" ")')
yarn test:ci:vite --minWorkers=1 --maxWorkers=2 $TESTS
env:
ENABLE_TEST_REPORTER: true
TEST_LIST: ${{ tojson(fromjson(needs.runner-indexes-vitest.outputs.test_list_array)[matrix.runner-index]) }}
- name: Upload test results to Codecov
uses: codecov/test-results-action@v1
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov'}}
with:
token: ${{ secrets.CODECOV_ORG_TOKEN }}
url: ${{ secrets.CODECOV_URL }}
- name: Upload test results to Codecov staging
uses: codecov/test-results-action@v1
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov'}}
with:
token: ${{ secrets.CODECOV_ORG_TOKEN_STAGING }}
url: ${{ secrets.CODECOV_STAGING_URL }}
- name: Upload test results to Codecov QA
uses: codecov/test-results-action@v1
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov'}}
with:
token: ${{ secrets.CODECOV_QA_TOKEN }}
url: ${{ secrets.CODECOV_QA_URL }}
- name: Upload test results to Codecov public QA
uses: codecov/test-results-action@v1
if: ${{ !cancelled() && !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov'}}
with:
token: ${{ secrets.CODECOV_PUBLIC_QA_TOKEN }}
url: ${{ secrets.CODECOV_PUBLIC_QA_URL }}
- name: Install CLI
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
run: |
make test_env.install_cli
## Don't upload on forks for now.
- name: Upload coverage to Production
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
run: |
codecovcli -u ${{ secrets.CODECOV_URL }} do-upload -t ${{ secrets.CODECOV_ORG_TOKEN }} --fail-on-error --name "VITEST-${{ matrix.runner-index }}"
- name: Upload coverage to Staging
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
run: |
codecovcli -u ${{ secrets.CODECOV_STAGING_URL }} do-upload -t ${{ secrets.CODECOV_ORG_TOKEN_STAGING }} --fail-on-error
- name: Upload coverage to QA
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
run: |
codecovcli -u ${{ secrets.CODECOV_QA_URL }} do-upload -t ${{ secrets.CODECOV_QA_TOKEN }} --fail-on-error
- name: Upload coverage to Public QA
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
run: |
codecovcli -u ${{ secrets.CODECOV_PUBLIC_QA_URL }} do-upload -t ${{ secrets.CODECOV_PUBLIC_QA_TOKEN }} --fail-on-error
upload-bundle-stats-to-prod:
name: Upload Bundle Stats - Production
runs-on: ubuntu-latest
needs: install
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-gazebo-node-modules
with:
path: |
node_modules
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Build and upload stats
run: |
yarn build:stats
env:
CODECOV_API_URL: ${{ secrets.CODECOV_API_URL }}
CODECOV_ORG_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}
CODECOV_BUNDLE_NAME: 'gazebo-production'
upload-bundle-stats-to-staging:
name: Upload Bundle Stats - Staging
runs-on: ubuntu-latest
needs: install
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-gazebo-node-modules
with:
path: |
node_modules
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Build and upload stats
run: |
yarn build:stats
env:
CODECOV_API_URL: ${{ secrets.CODECOV_STAGING_API_URL }}
CODECOV_ORG_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN_STAGING }}
CODECOV_BUNDLE_NAME: 'gazebo-staging'
storybook:
name: Run storybook
runs-on: ubuntu-latest
needs: install
if: ${{ !github.event.pull_request.head.repo.fork && !startsWith(github.ref, 'refs/heads/dependabot') && github.repository_owner == 'codecov' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-gazebo-node-modules
with:
path: |
node_modules
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Deploy to Chromatic
run: |
yarn chromatic
env:
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
fossa:
name: Run Fossa
runs-on: ubuntu-latest
needs: install
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Run Fossa
uses: fossas/[email protected]
with:
api-key: ${{secrets.FOSSA_API_KEY}}
build:
name: Build App
runs-on: ubuntu-latest
needs: [install, test-craco]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v4
env:
cache-name: cache-gazebo-node-modules
with:
path: |
node_modules
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- name: Build React App
run: |
yarn build
build-self-hosted:
name: Build Self Hosted Image
secrets: inherit
if: ${{ !github.event.pull_request.head.repo.fork && github.repository_owner == 'codecov' }}
uses: codecov/gha-workflows/.github/workflows/[email protected]
with:
repo: ${{ vars.CODECOV_IMAGE_V2 || 'codecov/self-hosted-frontend' }}
cache_requirements: false
self-hosted:
name: Push Self Hosted Image
needs: [build-self-hosted, test-craco]
secrets: inherit
if: ${{ github.event_name == 'push' && github.event.ref == 'refs/heads/main' && github.repository_owner == 'codecov' }}
uses: codecov/gha-workflows/.github/workflows/[email protected]
with:
push_rolling: true
repo: ${{ vars.CODECOV_IMAGE_V2 || 'codecov/self-hosted-frontend' }}
cache_requirements: false