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

[core] Create Circle CI config #4

Merged
merged 17 commits into from
Apr 15, 2024
Merged
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
394 changes: 394 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,394 @@
version: 2.1
orbs:
aws-cli: circleci/aws-cli@4.1
aws-s3: circleci/aws-s3@4.0

parameters:
browserstack-force:
description: Whether to force browserstack usage. We have limited resources on browserstack so the pipeline might decide to skip browserstack if this parameter isn't set to true.
type: boolean
default: false
react-version:
description: The version of react to be used
type: string
default: stable
workflow:
description: The name of the workflow to run
type: string
default: pipeline
e2e-base-url:
description: The base url for running end-to-end test
type: string
default: ''

default-job: &default-job
parameters:
react-version:
description: The version of react to be used
type: string
default: << pipeline.parameters.react-version >>
test-gate:
description: A particular type of tests that should be run
type: string
default: undefined
e2e-base-url:
description: The base url for running end-to-end test
type: string
default: << pipeline.parameters.e2e-base-url >>
environment:
# Keep in sync with "Save playwright cache"
PLAYWRIGHT_BROWSERS_PATH: /tmp/pw-browsers
# expose it globally otherwise we have to thread it from each job to the install command
BROWSERSTACK_FORCE: << pipeline.parameters.browserstack-force >>
REACT_VERSION: << parameters.react-version >>
TEST_GATE: << parameters.test-gate >>
AWS_REGION_ARTIFACTS: eu-central-1
working_directory: /tmp/material-ui
docker:
- image: cimg/node:18.19

default-context: &default-context
context:
- org-global

# CircleCI has disabled the cache across forks for security reasons.
# Following their official statement, it was a quick solution, they
# are working on providing this feature back with appropriate security measures.
# https://discuss.circleci.com/t/saving-cache-stopped-working-warning-skipping-this-step-disabled-in-configuration/24423/21
#
# restore_repo: &restore_repo
# restore_cache:
# key: v1-repo-{{ .Branch }}-{{ .Revision }}

commands:
install_js:
parameters:
browsers:
type: boolean
default: false
description: 'Set to true if you intend to any browser (for example with playwright).'

steps:
- run:
name: Resolve React version
command: |
node scripts/useReactVersion.mjs
# log a patch for maintainers who want to check out this change
git --no-pager diff HEAD
- when:
condition: << parameters.browsers >>
steps:
- run:
name: Install pnpm package manager
command: |
corepack enable
corepack prepare pnpm@latest-8 --activate
- run:
name: Prepare playwright hash
command: pnpm list --json --filter playwright > /tmp/playwright_info.json
- store_artifacts:
name: Debug playwright hash
path: /tmp/playwright_info.json
- restore_cache:
name: Restore playwright cache
keys:
- v6-playwright-{{ arch }}-{{ checksum "/tmp/playwright_info.json" }}
- run:
name: View install environment
command: |
node --version
pnpm --version
- run:
name: Install js dependencies
command: pnpm install
- when:
condition: << parameters.browsers >>
steps:
- run:
name: Install playwright browsers
command: pnpm playwright install --with-deps
- save_cache:
name: Save playwright cache
key: v6-playwright-{{ arch }}-{{ checksum "/tmp/playwright_info.json" }}
paths:
# Keep path in sync with "PLAYWRIGHT_BROWSERS_PATH"
# Can't use environment variables for `save_cache` paths (tested in https://app.circleci.com/pipelines/github/mui/material-ui/37813/workflows/5b1e207f-ac8b-44e7-9ba4-d0f9a01f5c55/jobs/223370)
- /tmp/pw-browsers

jobs:
checkout:
<<: *default-job
steps:
- checkout
- install_js
- when:
# Install can be "dirty" when running with non-default versions of React
condition:
equal: [<< parameters.react-version >>, stable]
steps:
- run:
name: Should not have any git not staged
command: git add -A && git diff --exit-code --staged
- run:
name: Check for duplicated packages
command: |
# #default-branch-switch
if [[ $(git diff --name-status next | grep -E 'pnpm-workspace\.yaml|pnpm-lock.yaml|package\.json') == "" ]];
then
echo "No changes to dependencies detected. Skipping..."
else
pnpm dedupe --check
fi
test_unit:
<<: *default-job
steps:
- checkout
- install_js
- run:
name: Tests fake browser
command: pnpm build && pnpm test:coverage:ci
- run:
name: Check coverage generated
command: |
if ! [[ -s coverage/lcov.info ]]
then
exit 1
fi
- run:
name: Coverage
command: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${CODECOV_TOKEN} -Z -F "$REACT_VERSION-jsdom"
test_lint:
<<: *default-job
steps:
- checkout
- install_js
- run:
name: Eslint
command: pnpm eslint:ci
- run:
name: Lint JSON
command: pnpm jsonlint
- run:
name: Lint Markdown
command: pnpm markdownlint
# Enable vale once we have a docs
# - run:
# # See https://circleci.com/developer/orbs/orb/circleci/vale as reference
# name: Install Vale
# command: |
# #!/bin/bash
# VALE_STR_CLI_VERSION=3.3.0
# mkdir /tmp/vale-extract
# cd /tmp/vale-extract
# GZIPPED_OUTPUT="vale.tar.gz"
# BINARY_URL=https://github.com/errata-ai/vale/releases/download/v${VALE_STR_CLI_VERSION}/vale_${VALE_STR_CLI_VERSION}_Linux_64-bit.tar.gz
# curl -sSL "$BINARY_URL" -o "${GZIPPED_OUTPUT}"
# if [ ! -s "${GZIPPED_OUTPUT}" ]; then
# echo "Downloaded file is empty"
# rm "${GZIPPED_OUTPUT}"
# exit 1
# fi
# tar -xzf "${GZIPPED_OUTPUT}"
# $SUDO mv vale /usr/local/bin
# rm "${GZIPPED_OUTPUT}"
# # validate installation
# if [[ -z "$(command -v vale)" ]]; then
# echo "vale installation failed"
# exit 1
# else
# echo "vale installation successful"
# vale --version
# exit 0
# fi
# - run:
# name: Lint writing style
# command: |
# vale sync
# pnpm run valelint
test_static:
<<: *default-job
steps:
- checkout
- install_js
- run:
name: '`pnpm prettier` changes committed?'
command: pnpm prettier --check
- run:
name: '`pnpm extract-error-codes` changes committed?'
command: |
pnpm extract-error-codes
git add -A && git diff --exit-code --staged
test_types:
<<: *default-job
resource_class: 'medium+'
steps:
- checkout
- install_js
- run:
name: Tests TypeScript definitions
command: pnpm typescript:ci
environment:
NODE_OPTIONS: --max-old-space-size=3072
test_types_next:
<<: *default-job
resource_class: 'medium+'
steps:
- checkout
- run:
name: Resolve typescript version
command: |
pnpm add typescript@next -d -w
# log a patch for maintainers who want to check out this change
git --no-pager diff HEAD
- install_js
- run:
name: Tests TypeScript definitions
command: |
# ignore build failures
# it's expected that typescript@next fails since the lines of the errors
# change frequently. This build is monitored regardless of its status
set +e
pnpm typescript:ci
exit 0
- restore_cache:
name: Restore generated declaration files
keys:
# We assume that the target branch is `next` and that declaration files are persisted in commit order.
# "If there are multiple matches, the most recently generated cache will be used."
- typescript-declaration-files-next
test_browser:
<<: *default-job
resource_class: 'medium+'
docker:
- image: mcr.microsoft.com/playwright:v1.43.0-focal
environment:
NODE_ENV: development # Needed if playwright is in `devDependencies`
steps:
- checkout
- install_js:
browsers: true
- run:
name: Tests real browsers
command: pnpm test:karma
- run:
name: Check coverage generated
command: |
if ! [[ -s coverage/lcov.info ]]
then
exit 1
fi
- run:
name: Coverage
command: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${CODECOV_TOKEN} -Z -F "$REACT_VERSION-browser"
- store_artifacts:
# hardcoded in karma-webpack
path: /tmp/_karma_webpack_
destination: artifact-file
test_profile:
<<: *default-job
docker:
- image: mcr.microsoft.com/playwright:v1.43.0-focal
environment:
NODE_ENV: development # Needed if playwright is in `devDependencies`
steps:
- checkout
- install_js:
browsers: true
- run:
name: Tests real browsers
# Run a couple of times for a better sample.
# TODO: hack something together where we can compile once and run multiple times e.g. by abusing watchmode.
command: |
# Running on chrome only since actual times are innaccurate anyway
# The other reason is that browserstack allows little concurrency so it's likely that we're starving other runs.
pnpm test:karma:profile --browsers chrome,chromeHeadless
pnpm test:karma:profile --browsers chrome,chromeHeadless
pnpm test:karma:profile --browsers chrome,chromeHeadless
pnpm test:karma:profile --browsers chrome,chromeHeadless
pnpm test:karma:profile --browsers chrome,chromeHeadless
# Persist reports for inspection in https://mui-dashboard.netlify.app/
- store_artifacts:
# see karma.conf.profile.js reactProfilerReporter.outputDir
path: tmp/react-profiler-report/karma
destination: react-profiler-report/karma
workflows:
version: 2
pipeline:
when:
equal: [pipeline, << pipeline.parameters.workflow >>]
jobs:
- checkout:
<<: *default-context
- test_unit:
<<: *default-context
requires:
- checkout
- test_lint:
<<: *default-context
requires:
- checkout
- test_static:
<<: *default-context
requires:
- checkout
- test_types:
<<: *default-context
requires:
- checkout
- test_browser:
<<: *default-context
requires:
- checkout
profile:
when:
equal: [profile, << pipeline.parameters.workflow >>]
jobs:
- test_profile:
<<: *default-context
react-17:
triggers:
- schedule:
cron: '0 0 * * *'
filters:
branches:
only:
- master
jobs:
- test_unit:
<<: *default-context
react-version: ^17.0.0
- test_browser:
<<: *default-context
react-version: ^17.0.0
react-next:
triggers:
- schedule:
cron: '0 0 * * *'
filters:
branches:
only:
- master
jobs:
- test_unit:
<<: *default-context
react-version: next
- test_browser:
<<: *default-context
react-version: next
typescript-next:
triggers:
- schedule:
cron: '0 0 * * *'
filters:
branches:
only:
- master
jobs:
- test_types_next:
<<: *default-context
Loading