Skip to content

Commit 38cb016

Browse files
committed
[code-infra] Create re-usable code-infra orb
1 parent 9826956 commit 38cb016

File tree

6 files changed

+263
-61
lines changed

6 files changed

+263
-61
lines changed

.circleci/config.yml

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
version: 2.1
22

3+
orbs:
4+
code-infra: https://raw.githubusercontent.com/mui/mui-public/refs/heads/ci-orb/.circleci/orbs/code-infra.yml
5+
36
parameters:
47
workflow:
58
description: The name of the workflow to run
@@ -8,75 +11,34 @@ parameters:
811

912
default-job: &default-job
1013
working_directory: /tmp/mui
11-
docker:
12-
- image: cimg/node:22.18
13-
environment:
14-
DANGER_DISABLE_TRANSPILATION: 'true'
14+
executor: code-infra/mui-node
1515

1616
default-context: &default-context
1717
context:
1818
- org-global
1919

20-
commands:
21-
install_js:
22-
steps:
23-
- run:
24-
name: Install corepack
25-
# See https://stackoverflow.com/a/73411601
26-
command: corepack enable --install-directory ~/bin
27-
- run:
28-
name: View install environment
29-
command: |
30-
node --version
31-
- run:
32-
name: Install js dependencies
33-
command: pnpm install
34-
3520
jobs:
3621
checkout:
3722
<<: *default-job
3823
steps:
3924
- checkout
40-
- install_js
25+
- code-infra/install-deps
4126
- run:
4227
name: Should not have any git not staged
4328
command: git add -A && git diff --exit-code --staged
44-
- run:
45-
name: '`pnpm dedupe` was run?'
46-
command: |
47-
# #default-branch-switch
48-
if [[ $(git diff --name-status master | grep -E 'pnpm-workspace\.yaml|pnpm-lock.yaml|package\.json') == "" ]];
49-
then
50-
echo "no changes to dependencies detected, skipping..."
51-
else
52-
pnpm dedupe --check
53-
fi
5429
test_lint:
5530
<<: *default-job
5631
steps:
5732
- checkout
58-
- install_js
59-
- run:
60-
name: ESLint
61-
command: pnpm eslint:ci
62-
- run:
63-
name: TypeScript
64-
command: pnpm typescript
33+
- code-infra/install-deps
34+
- code-infra/run-linters:
35+
valelint: false
6536
test_static:
6637
<<: *default-job
6738
steps:
6839
- checkout
69-
- install_js
70-
- run:
71-
name: '`pnpm prettier` changes committed?'
72-
command: |
73-
# #target-branch-reference
74-
if [[ $(git diff --name-status master | grep pnpm-lock) == "" ]];
75-
then
76-
pnpm prettier --check
77-
else
78-
pnpm exec prettier --check . --ignore-path .lintignore
79-
fi
40+
- code-infra/install-deps
41+
- code-infra/check-static-changes
8042
- run:
8143
# make sure the netlify ignore command has the correct dependencies
8244
name: '`pnpm update-netlify-ignore` changes committed?'
@@ -87,25 +49,19 @@ jobs:
8749
<<: *default-job
8850
steps:
8951
- checkout
90-
- install_js
52+
- code-infra/install-deps
9153
- run:
9254
name: 'Run tests'
9355
command: pnpm test
9456
test_package:
9557
<<: *default-job
9658
steps:
9759
- checkout
98-
- install_js
60+
- code-infra/install-deps
9961
- run:
10062
name: Build packages
10163
command: pnpm release:build
102-
- run:
103-
name: create and upload a size snapshot
104-
command: |
105-
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID_ARTIFACTS
106-
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY_ARTIFACTS
107-
export AWS_REGION=$AWS_REGION_ARTIFACTS
108-
pnpm size:snapshot
64+
- code-infra/upload-size-snapshot
10965

11066
workflows:
11167
version: 2

.circleci/orbs/code-infra.yml

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
version: 2.1
2+
3+
commands:
4+
install-deps:
5+
description: 'Installs JavaScript dependencies using pnpm'
6+
parameters:
7+
browsers:
8+
type: boolean
9+
default: false
10+
description: 'Set to true if you intend to install any browser (for example with playwright).'
11+
package-overrides:
12+
description: 'A space separated list of package@version to override during installation'
13+
type: string
14+
default: ''
15+
ignore-workspace:
16+
description: 'Set to true to ignore the pnpm workspace (useful for single-package repositories)'
17+
type: boolean
18+
default: false
19+
steps:
20+
- run:
21+
name: Set npm registry public signing keys
22+
command: |
23+
echo "export COREPACK_INTEGRITY_KEYS='$(curl https://registry.npmjs.org/-/npm/v1/keys | jq -c '{npm: .keys}')'" >> $BASH_ENV
24+
- when:
25+
condition: << parameters.browsers >>
26+
steps:
27+
- run:
28+
name: Install pnpm package manager
29+
command: corepack enable
30+
- when:
31+
condition:
32+
not: << parameters.browsers >>
33+
steps:
34+
- run:
35+
name: Install pnpm package manager
36+
# See https://stackoverflow.com/a/73411601
37+
command: corepack enable --install-directory ~/bin
38+
- run:
39+
name: View install environment
40+
command: |
41+
node --version
42+
pnpm --version
43+
- when:
44+
condition: << parameters.ignore-workspace >>
45+
steps:
46+
- run:
47+
name: Initialize single-package repository
48+
command: pnpm install --ignore-workspace
49+
- when:
50+
condition:
51+
not: << parameters.ignore-workspace >>
52+
steps:
53+
- run:
54+
name: Install js dependencies
55+
command: |
56+
packages="<< parameters.package-overrides >>"
57+
58+
if [[ -z "$packages" ]]; then
59+
pnpm install
60+
exit 0
61+
fi
62+
63+
IFS=' '
64+
set -- $packages
65+
pkg_array=("$@")
66+
unset IFS
67+
68+
filtered=""
69+
for pkg in "${pkg_array[@]}"; do
70+
if [[ ! "$pkg" =~ @stable$ ]]; then
71+
if [[ "$pkg" == *"@"* ]]; then
72+
filtered="$filtered $pkg"
73+
fi
74+
fi
75+
done
76+
77+
args="${filtered# }"
78+
if [ -n "$args" ]; then
79+
pnpm dlx @mui/internal-code-infra@canary set-version-overrides --pkg $args
80+
else
81+
pnpm install
82+
fi
83+
eslint:
84+
description: 'Runs ESLint on the codebase'
85+
steps:
86+
- restore_cache:
87+
keys:
88+
- eslint-cache-{{ checksum "pnpm-lock.yaml" }}
89+
- eslint-cache-
90+
- run:
91+
name: ESLint
92+
command: pnpm exec eslint . --cache --cache-strategy content --report-unused-disable-directives --max-warnings 0
93+
- save_cache:
94+
key: eslint-cache-{{ checksum "pnpm-lock.yaml" }}
95+
paths:
96+
- .eslintcache
97+
98+
stylelint:
99+
description: 'Runs Stylelint on the codebase'
100+
steps:
101+
- run:
102+
name: Stylelint
103+
command: pnpm stylelint
104+
105+
markdownlint:
106+
description: 'Runs Markdownlint on the codebase'
107+
steps:
108+
- run:
109+
name: Lint Markdown
110+
command: pnpm exec markdownlint-cli2 "**/*.md"
111+
112+
valelint:
113+
description: 'Runs Vale linter on the codebase'
114+
steps:
115+
- run:
116+
name: Lint writing style
117+
command: pnpm valelint
118+
119+
upload-coverage:
120+
description: 'Uploads code coverage to Codecov'
121+
parameters:
122+
key:
123+
type: string
124+
default: 'jsdom'
125+
description: 'The Codecov upload key suffix.'
126+
steps:
127+
- run:
128+
name: Check if coverage report is generated
129+
command: |
130+
if ! [[ -s coverage/lcov.info ]]
131+
then
132+
exit 1
133+
fi
134+
- run:
135+
name: Upload coverage report to Codecov
136+
command: |
137+
curl -Os https://uploader.codecov.io/latest/linux/codecov
138+
chmod +x codecov
139+
./codecov -t ${CODECOV_TOKEN} -Z -F "<< parameters.key >>"
140+
141+
pnpm-dedupe:
142+
description: 'Runs pnpm dedupe to optimize dependencies'
143+
steps:
144+
- run:
145+
name: '`pnpm dedupe` was run?'
146+
command: |
147+
# #default-branch-switch
148+
if [[ $(git diff --name-status master | grep -E 'pnpm-workspace\.yaml|pnpm-lock.yaml|package\.json') == "" ]];
149+
then
150+
echo "No changes to dependencies detected. Skipping..."
151+
else
152+
pnpm dedupe --check
153+
fi
154+
155+
prettier:
156+
description: 'Checks code formatting using Prettier'
157+
steps:
158+
- run:
159+
name: '`pnpm prettier` changes committed?'
160+
command: |
161+
# #default-branch-switch
162+
if [[ $(git diff --name-status master | grep pnpm-lock) == "" ]];
163+
then
164+
pnpm prettier --check
165+
else
166+
pnpm exec prettier --check . --ignore-path .lintignore
167+
fi
168+
169+
run-linters:
170+
description: 'Runs all code linters'
171+
parameters:
172+
eslint:
173+
type: boolean
174+
default: true
175+
description: 'Set to true to run ESLint'
176+
stylelint:
177+
type: boolean
178+
default: true
179+
description: 'Set to true to run Stylelint'
180+
markdownlint:
181+
type: boolean
182+
default: true
183+
description: 'Set to true to run Markdownlint'
184+
valelint:
185+
type: boolean
186+
default: true
187+
description: 'Set to true to run Vale linter'
188+
steps:
189+
- when:
190+
condition: << parameters.eslint >>
191+
steps:
192+
- eslint
193+
- when:
194+
condition: << parameters.stylelint >>
195+
steps:
196+
- stylelint
197+
- when:
198+
condition: << parameters.markdownlint >>
199+
steps:
200+
- markdownlint
201+
- when:
202+
condition: << parameters.valelint >>
203+
steps:
204+
- valelint
205+
206+
check-static-changes:
207+
description: 'Checks code changes after running static analysis tools'
208+
steps:
209+
- pnpm-dedupe
210+
- prettier
211+
212+
upload-size-snapshot:
213+
description: 'Creates and uploads a size snapshot to S3'
214+
steps:
215+
- run:
216+
name: create and upload a size snapshot
217+
command: |
218+
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID_ARTIFACTS
219+
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY_ARTIFACTS
220+
export AWS_REGION=$AWS_REGION_ARTIFACTS
221+
pnpm size:snapshot
222+
223+
executors:
224+
# Can be used as a single source of truth for Node version across all code-infra jobs on CI
225+
mui-node:
226+
parameters:
227+
node-version:
228+
type: string
229+
default: '22.21.1'
230+
docker:
231+
- image: cimg/node:<< parameters.node-version >>

.github/copilot-instructions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Always reference these instructions first and fallback to search or bash command
5151

5252
### Repository Structure
5353

54-
```
54+
```txt
5555
packages/
5656
├── babel-plugin-display-name/ # Babel plugin for component display names
5757
├── babel-plugin-minify-errors/ # Babel plugin for error minification
@@ -139,8 +139,8 @@ Follow additional instructions when working in the `@mui/internal-docs-infra` (`
139139
### Code Architecture & Design
140140

141141
- **2.1** Avoid using Node.js native modules like `fs` or `path` or Browser only APIs (like `window` or `document`) when functionality can be achieved using isomorphic code that can also run in the browser and Node.js. When necessary, isolate platform specific code behind interfaces or abstractions so that it can later be replaced in browser environments.
142-
- **2.2** Ship the package as `0.x.0` releases so you can introduce breaking changes that improve the developer experience. Work toward a stable `1.0.0` by anticipating how todays APIs will evolve.
143-
- Each folders `index.ts` should re-export from `src/{functionName}/{functionName}.ts`.
142+
- **2.2** Ship the package as `0.x.0` releases so you can introduce breaking changes that improve the developer experience. Work toward a stable `1.0.0` by anticipating how today's APIs will evolve.
143+
- Each folder's `index.ts` should re-export from `src/{functionName}/{functionName}.ts`.
144144
- Category exports should re-export from `src/{category}/{functionName}/{functionName}.ts`.
145145
- **2.3** When functions within the main function file become large or complex, they should be split into separate files within the same folder. For example, if `src/useCode/useCode.ts` becomes large, a large function can be moved to `src/useCode/useFileNavigation.ts` where `useFileNavigation` is the helper function's name.
146146
- **2.4** Value progressive complexity for developers using the library. Start with straightforward defaults and layer optional extension points or advanced behavior that teams can opt into. Keep complex internals behind simple interfaces to enable incremental adoption, easier testing, and maintainable abstractions.

.markdownlint-cli2.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { createBaseConfig } from '@mui/internal-code-infra/markdownlint';
2+
3+
export default createBaseConfig();

packages/code-infra/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Scripts and configs to be used across MUI repos.
2222
4. Refresh the page to see the newly created workflow, and click it.
2323
5. The next screen shows "@username requested your review to deploy to npm-publish", click "Review deployments" and authorize your workflow run. **Never approve workflow runs you didn't initiaite.**
2424

25-
> [!IMPORTANT]
25+
> [!IMPORTANT]
2626
> Go through the below steps if there is an error that says `The following packages are new and need to be published manually first` in the publish flow.
2727
2828
### Adding and publishing new packages

0 commit comments

Comments
 (0)