|
| 1 | +version: 2 |
| 2 | + |
| 3 | +# Monorepo CircleCI config for React on Rails Pro package |
| 4 | +# Updated to work from root directory with pro package in react_on_rails_pro/ |
| 5 | + |
| 6 | +aliases: |
| 7 | + # Print critical data and executables versions. |
| 8 | + - &print-system-info |
| 9 | + name: Print system information |
| 10 | + command: | |
| 11 | + echo "Linux release: "; cat /etc/issue |
| 12 | + echo "Current user: "; whoami |
| 13 | + echo "Current directory: "; pwd |
| 14 | + echo "Ruby version: "; ruby -v |
| 15 | + echo "Node version: "; node -v |
| 16 | + echo "Yarn version: "; yarn --version |
| 17 | + echo "Bundler version: "; bundle --version |
| 18 | + - &lint-js |
| 19 | + name: Linting of JS (Pro package only) |
| 20 | + working_directory: react_on_rails_pro |
| 21 | + command: yarn run nps eslint |
| 22 | + |
| 23 | + - &lint-ruby |
| 24 | + name: Linting of Ruby (Pro package only) |
| 25 | + working_directory: react_on_rails_pro |
| 26 | + command: bundle exec rubocop |
| 27 | + |
| 28 | + - &format |
| 29 | + name: Check formatting (Pro package only) |
| 30 | + working_directory: react_on_rails_pro |
| 31 | + command: yarn run nps format.listDifferent |
| 32 | + |
| 33 | + - &typescript-check |
| 34 | + name: Check TypeScript (Pro package only) |
| 35 | + working_directory: react_on_rails_pro |
| 36 | + command: yarn run nps check-typescript |
| 37 | + |
| 38 | + # Install/update Node modules for renderer package unless existing set of modules is satisfying Yarn. |
| 39 | + - &install-package-node-modules |
| 40 | + name: Install Node modules with Yarn for pro renderer package |
| 41 | + working_directory: react_on_rails_pro |
| 42 | + command: | |
| 43 | + sudo yarn global add yalc |
| 44 | + yarn install --frozen-lockfile --no-progress --no-emoji |
| 45 | +
|
| 46 | + # Install/update Node modules for dummy app unless existing set of modules is satisfying Yarn. |
| 47 | + - &install-dummy-app-node-modules |
| 48 | + name: Install Node modules with Yarn for pro dummy app |
| 49 | + working_directory: react_on_rails_pro |
| 50 | + command: | |
| 51 | + cd spec/dummy |
| 52 | + yarn install --frozen-lockfile --no-progress --no-emoji |
| 53 | +
|
| 54 | + # Install ruby gems unless existing set of gems is satisfying bundler. |
| 55 | + - &install-dummy-app-ruby-gems |
| 56 | + name: Install Ruby Gems for pro dummy app |
| 57 | + working_directory: react_on_rails_pro |
| 58 | + command: | |
| 59 | + gem install bundler -v "2.5.4" |
| 60 | + echo "Bundler version: "; bundle --version |
| 61 | + bundle config set --local path 'vendor/bundle' |
| 62 | + bundle config set --local disable_checksum_validation true |
| 63 | + cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle _2.5.4_ check || bundle _2.5.4_ install --jobs=4 --retry=3 |
| 64 | +
|
| 65 | + - &generate-dummy-app-packs |
| 66 | + name: Generate file-system based entrypoints (Pro) |
| 67 | + working_directory: react_on_rails_pro |
| 68 | + command: | |
| 69 | + cd spec/dummy |
| 70 | + bundle exec rake react_on_rails:generate_packs |
| 71 | +
|
| 72 | + # Install ruby gems unless existing set of gems is satisfying bundler. |
| 73 | + - &install-package-ruby-gems |
| 74 | + name: Install Ruby Gems for pro package |
| 75 | + working_directory: react_on_rails_pro |
| 76 | + command: | |
| 77 | + gem install bundler -v "2.5.4" |
| 78 | + echo "Bundler version: "; bundle --version |
| 79 | + bundle config set --local path 'vendor/bundle' |
| 80 | + bundle config set --local disable_checksum_validation true |
| 81 | + bundle _2.5.4_ check || bundle _2.5.4_ install --jobs=4 --retry=3 |
| 82 | +
|
| 83 | + # Restore node_modules dir from cache using yarn.lock checksum as a key. |
| 84 | + - &restore-package-node-modules-cache |
| 85 | + name: Restore cached node_modules directory (Pro) |
| 86 | + keys: |
| 87 | + - v4-pro-package-node-modules-cache-{{ checksum "react_on_rails_pro/yarn.lock" }} |
| 88 | + |
| 89 | + # Restore spec/dummy/node_modules dir from cache using yarn.lock checksum as a key. |
| 90 | + - &restore-dummy-app-node-modules-cache |
| 91 | + name: Restore cached spec/dummy/node_modules directory (Pro) |
| 92 | + keys: |
| 93 | + - v4-pro-dummy-app-node-modules-cache-{{ checksum "react_on_rails_pro/spec/dummy/yarn.lock" }} |
| 94 | + |
| 95 | + # Restore vendor/bundle dir from cache using Gemfile.lock checksum as a key. |
| 96 | + - &restore-dummy-app-gem-cache |
| 97 | + name: Restore cached Ruby Gems for pro dummy app |
| 98 | + keys: |
| 99 | + - v4-pro-dummy-app-gem-cache-{{ checksum "react_on_rails_pro/spec/dummy/Gemfile.lock" }} |
| 100 | + |
| 101 | + # Restore vendor/bundle dir from cache using react_on_rails_pro.gemspec checksum as a key. |
| 102 | + - &restore-package-gem-cache |
| 103 | + name: Restore cached Ruby Gems for pro package |
| 104 | + keys: |
| 105 | + - v4-pro-package-app-gem-cache-{{ checksum "react_on_rails_pro/react_on_rails_pro.gemspec" }} |
| 106 | + |
| 107 | + # Restore webpack bundles for dummy app from cache |
| 108 | + - &restore-dummy-app-webpack-bundle-cache |
| 109 | + name: Restore cached webpack bundles for pro dummy app |
| 110 | + key: v4-pro-dummy-app-webpack-bundle-{{ .Revision }} |
| 111 | + |
| 112 | + # NOTE: Sometimes CI generated docker images are not updated in time to keep up with the minimum required |
| 113 | + # by chromedriver versions of Chrome. Just bump here Chrome version if chromedriver raises errors |
| 114 | + - &install-latest-chrome |
| 115 | + name: Ensure minimum required Chrome version |
| 116 | + command: | |
| 117 | + echo -e "Installed $(google-chrome --version)\n" |
| 118 | + MINIMUM_REQUIRED_CHROME_VERSION=75 |
| 119 | + INSTALLED_CHROME_MAJOR_VERSION="$(google-chrome --version | tr ' .' '\t' | cut -f3)" |
| 120 | + if [[ $INSTALLED_CHROME_MAJOR_VERSION < $MINIMUM_REQUIRED_CHROME_VERSION ]]; then |
| 121 | + wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add - |
| 122 | + sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' |
| 123 | + sudo apt-get update |
| 124 | + sudo apt-get install google-chrome-stable |
| 125 | + echo -e "\nInstalled $(google-chrome --version)" |
| 126 | + fi |
| 127 | +
|
| 128 | +jobs: |
| 129 | + # Lint all |
| 130 | + lint-js-and-ruby: |
| 131 | + docker: |
| 132 | + - image: &docker_image cimg/ruby:3.3.7-browsers |
| 133 | + steps: |
| 134 | + - checkout |
| 135 | + - run: *print-system-info |
| 136 | + - restore_cache: *restore-package-node-modules-cache |
| 137 | + - restore_cache: *restore-package-gem-cache |
| 138 | + - restore_cache: *restore-dummy-app-node-modules-cache |
| 139 | + - run: *install-package-ruby-gems |
| 140 | + - run: *install-package-node-modules |
| 141 | + - run: *install-dummy-app-ruby-gems |
| 142 | + - run: *install-dummy-app-node-modules |
| 143 | + - run: |
| 144 | + name: Install Node modules with Yarn for ExecJS dummy app (Pro) |
| 145 | + working_directory: react_on_rails_pro |
| 146 | + command: | |
| 147 | + cd spec/execjs-compatible-dummy |
| 148 | + yarn install --frozen-lockfile --no-progress --no-emoji |
| 149 | + - run: *generate-dummy-app-packs |
| 150 | + - run: *lint-ruby |
| 151 | + - run: *lint-js |
| 152 | + - run: *format |
| 153 | + - run: *typescript-check |
| 154 | + |
| 155 | + # Install Node modules for Renderer package with Yarn and save them to cache. |
| 156 | + install-package-node-packages: |
| 157 | + docker: |
| 158 | + - image: *docker_image |
| 159 | + steps: |
| 160 | + - checkout |
| 161 | + - run: *print-system-info |
| 162 | + - restore_cache: *restore-package-node-modules-cache |
| 163 | + - run: *install-package-node-modules |
| 164 | + - save_cache: |
| 165 | + name: Save pro root node_modules to cache |
| 166 | + key: v4-pro-package-node-modules-cache-{{ checksum "react_on_rails_pro/yarn.lock" }} |
| 167 | + paths: |
| 168 | + - react_on_rails_pro/node_modules |
| 169 | + |
| 170 | + # Install Node modules for dummy app with Yarn and save them to cache. |
| 171 | + install-dummy-app-node-packages: |
| 172 | + docker: |
| 173 | + - image: *docker_image |
| 174 | + steps: |
| 175 | + - checkout |
| 176 | + - run: *print-system-info |
| 177 | + - restore_cache: *restore-dummy-app-node-modules-cache |
| 178 | + - run: *install-package-node-modules |
| 179 | + - run: *install-dummy-app-node-modules |
| 180 | + - save_cache: |
| 181 | + name: Save pro spec/dummy/node_modules to cache |
| 182 | + key: v4-pro-dummy-app-node-modules-cache-{{ checksum "react_on_rails_pro/spec/dummy/yarn.lock" }} |
| 183 | + paths: |
| 184 | + - react_on_rails_pro/spec/dummy/node_modules |
| 185 | + |
| 186 | + # Install Ruby gems for package with Bundler and save them to cache. |
| 187 | + install-package-ruby-gems: |
| 188 | + docker: |
| 189 | + - image: *docker_image |
| 190 | + steps: |
| 191 | + - checkout |
| 192 | + - run: *print-system-info |
| 193 | + - restore_cache: *restore-package-gem-cache |
| 194 | + - run: *install-package-ruby-gems |
| 195 | + - save_cache: |
| 196 | + name: Save pro package ruby gems to cache |
| 197 | + key: v4-pro-package-app-gem-cache-{{ checksum "react_on_rails_pro/react_on_rails_pro.gemspec" }} |
| 198 | + paths: |
| 199 | + - react_on_rails_pro/vendor/bundle |
| 200 | + |
| 201 | + # Install Ruby gems for dummy app with Bundler and save them to cache. |
| 202 | + install-dummy-app-ruby-gems: |
| 203 | + docker: |
| 204 | + - image: *docker_image |
| 205 | + steps: |
| 206 | + - checkout |
| 207 | + - run: *print-system-info |
| 208 | + - restore_cache: *restore-dummy-app-gem-cache |
| 209 | + - run: *install-dummy-app-ruby-gems |
| 210 | + - save_cache: |
| 211 | + name: Save pro dummy app ruby gems to cache |
| 212 | + key: v4-pro-dummy-app-gem-cache-{{ checksum "react_on_rails_pro/spec/dummy/Gemfile.lock" }} |
| 213 | + paths: |
| 214 | + - react_on_rails_pro/spec/dummy/vendor/bundle |
| 215 | + |
| 216 | + # Build client and server bundles for dummy app with Webpack and save them to cache. |
| 217 | + # NOTE: keeping around this cache in case we have multiple rspec suites in the future to tests |
| 218 | + # different node renderers. |
| 219 | + build-dummy-app-webpack-test-bundles: |
| 220 | + docker: |
| 221 | + - image: *docker_image |
| 222 | + steps: |
| 223 | + - checkout |
| 224 | + - run: *print-system-info |
| 225 | + - restore_cache: *restore-package-node-modules-cache |
| 226 | + - restore_cache: *restore-dummy-app-node-modules-cache |
| 227 | + - restore_cache: *restore-dummy-app-gem-cache |
| 228 | + - run: *install-package-node-modules |
| 229 | + - run: *install-dummy-app-node-modules |
| 230 | + - run: *install-dummy-app-ruby-gems |
| 231 | + - run: *generate-dummy-app-packs |
| 232 | + - run: |
| 233 | + name: Build test bundles for pro dummy app |
| 234 | + working_directory: react_on_rails_pro |
| 235 | + command: cd spec/dummy && yarn run build:test |
| 236 | + - save_cache: |
| 237 | + name: Save test webpack bundles to cache (for build number checksum used by rspec job) |
| 238 | + key: v4-pro-dummy-app-webpack-bundle-{{ .Revision }} |
| 239 | + paths: |
| 240 | + - react_on_rails_pro/spec/dummy/public/webpack/test |
| 241 | + - react_on_rails_pro/spec/dummy/ssr-generated |
| 242 | + |
| 243 | + # Run JS unit tests for Renderer package. |
| 244 | + package-js-tests: |
| 245 | + docker: |
| 246 | + - image: *docker_image |
| 247 | + steps: |
| 248 | + - checkout |
| 249 | + - run: *print-system-info |
| 250 | + - restore_cache: *restore-package-node-modules-cache |
| 251 | + - run: rm -rf react_on_rails_pro/spec/dummy/public/webpack |
| 252 | + - run: rm -rf react_on_rails_pro/spec/dummy/ssr-generated |
| 253 | + - restore_cache: *restore-dummy-app-webpack-bundle-cache |
| 254 | + - run: *install-package-node-modules |
| 255 | + # https://circleci.com/docs/collect-test-data/#jest |
| 256 | + - run: |
| 257 | + name: Run JS unit tests for Pro Renderer package |
| 258 | + working_directory: react_on_rails_pro |
| 259 | + command: yarn run nps test.ci |
| 260 | + environment: |
| 261 | + JEST_JUNIT_OUTPUT_DIR: ./jest |
| 262 | + JEST_JUNIT_ADD_FILE_ATTRIBUTE: "true" |
| 263 | + - store_test_results: |
| 264 | + path: ./jest |
| 265 | + |
| 266 | + rspec-package-specs: |
| 267 | + docker: |
| 268 | + - image: *docker_image |
| 269 | + steps: |
| 270 | + - checkout |
| 271 | + - run: *print-system-info |
| 272 | + - restore_cache: *restore-package-gem-cache |
| 273 | + - run: *install-package-ruby-gems |
| 274 | + - run: |
| 275 | + name: Run rspec tests (Pro package) |
| 276 | + working_directory: react_on_rails_pro |
| 277 | + command: | |
| 278 | + bundle exec rspec spec/react_on_rails_pro |
| 279 | + - store_test_results: |
| 280 | + path: ~/rspec |
| 281 | + - store_artifacts: |
| 282 | + path: react_on_rails_pro/log/test.log |
| 283 | + |
| 284 | + # Start Renderer and run RSpec test suite for dummy app. |
| 285 | + # NOTES: |
| 286 | + # Seems that we cannot use symlinks (yarn link) with caches for the main renderer package |
| 287 | + # react-on-rails-pro-node-renderer. Consequently, we just reinstall the top level, renderer, node packages |
| 288 | + # as well as the |
| 289 | + rspec-dummy-app-node-renderer: |
| 290 | + docker: |
| 291 | + - image: *docker_image |
| 292 | + steps: |
| 293 | + - checkout |
| 294 | + - run: *print-system-info |
| 295 | + - restore_cache: *restore-package-gem-cache |
| 296 | + - restore_cache: *restore-package-node-modules-cache |
| 297 | + - restore_cache: *restore-dummy-app-node-modules-cache |
| 298 | + - restore_cache: *restore-dummy-app-gem-cache |
| 299 | + - run: rm -rf react_on_rails_pro/spec/dummy/public/webpack |
| 300 | + - run: rm -rf react_on_rails_pro/spec/dummy/ssr-generated |
| 301 | + - restore_cache: *restore-dummy-app-webpack-bundle-cache |
| 302 | + - run: *install-dummy-app-ruby-gems |
| 303 | + - run: *install-package-node-modules |
| 304 | + - run: *install-latest-chrome |
| 305 | + - run: *install-dummy-app-node-modules |
| 306 | + - run: |
| 307 | + name: Generate file-system based entrypoints (Pro) |
| 308 | + working_directory: react_on_rails_pro |
| 309 | + command: cd spec/dummy && bundle exec rake react_on_rails:generate_packs |
| 310 | + - run: |
| 311 | + name: Run Pro Node renderer in a background |
| 312 | + working_directory: react_on_rails_pro |
| 313 | + command: cd spec/dummy && yarn run node-renderer |
| 314 | + background: true |
| 315 | + - run: |
| 316 | + name: run rails server in background (Pro dummy app) |
| 317 | + working_directory: react_on_rails_pro |
| 318 | + command: cd spec/dummy && RAILS_ENV=test rails server |
| 319 | + background: true |
| 320 | + - run: |
| 321 | + name: wait for rails server to start |
| 322 | + command: | |
| 323 | + while ! curl -s http://localhost:3000 > /dev/null; do sleep 1; done |
| 324 | + - run: |
| 325 | + name: Run rspec tests (Pro dummy app) |
| 326 | + working_directory: react_on_rails_pro/spec/dummy |
| 327 | + command: | |
| 328 | + circleci tests glob "spec/**/*_spec.rb" | |
| 329 | + circleci tests run --command="xargs bundle exec rspec \ |
| 330 | + --profile 10 \ |
| 331 | + --format progress \ |
| 332 | + --format RspecJunitFormatter \ |
| 333 | + --out ~/rspec/rspec.xml \ |
| 334 | + --format documentation" \ |
| 335 | + --verbose \ |
| 336 | + --split-by=timings |
| 337 | + - store_test_results: |
| 338 | + path: ~/rspec |
| 339 | + - store_artifacts: |
| 340 | + path: react_on_rails_pro/spec/dummy/tmp/screenshots |
| 341 | + - store_artifacts: |
| 342 | + path: react_on_rails_pro/spec/dummy/log/test.log |
| 343 | + - store_artifacts: |
| 344 | + path: react_on_rails_pro/spec/dummy/yarn-error.log |
| 345 | + |
| 346 | +workflows: |
| 347 | + version: 2 |
| 348 | + build-and-test: |
| 349 | + jobs: |
| 350 | + - install-package-node-packages |
| 351 | + - install-package-ruby-gems |
| 352 | + - install-dummy-app-node-packages: |
| 353 | + requires: |
| 354 | + - install-package-node-packages |
| 355 | + - install-dummy-app-ruby-gems |
| 356 | + - lint-js-and-ruby: |
| 357 | + requires: |
| 358 | + - install-package-node-packages |
| 359 | + - install-package-ruby-gems |
| 360 | + - install-dummy-app-node-packages |
| 361 | + - build-dummy-app-webpack-test-bundles: |
| 362 | + requires: |
| 363 | + - install-package-node-packages |
| 364 | + - install-dummy-app-node-packages |
| 365 | + - install-dummy-app-ruby-gems |
| 366 | + - package-js-tests: |
| 367 | + requires: |
| 368 | + - install-package-node-packages |
| 369 | + - build-dummy-app-webpack-test-bundles |
| 370 | + - rspec-package-specs: |
| 371 | + requires: |
| 372 | + - install-package-ruby-gems |
| 373 | + - rspec-dummy-app-node-renderer: |
| 374 | + requires: |
| 375 | + - install-package-ruby-gems |
| 376 | + - build-dummy-app-webpack-test-bundles |
0 commit comments