|
| 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 >> |
0 commit comments