diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 0b641949c0..0000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,432 +0,0 @@ -version: 2 - -# Monorepo CircleCI config for React on Rails Pro package -# Updated to work from root directory with pro package in react_on_rails_pro/ - -aliases: - # Print critical data and executables versions. - - &print-system-info - name: Print system information - command: | - echo "Linux release: "; cat /etc/issue - echo "Current user: "; whoami - echo "Current directory: "; pwd - echo "Ruby version: "; ruby -v - echo "Node version: "; node -v - echo "Yarn version: "; yarn --version - echo "Bundler version: "; bundle --version - - &lint-js - name: Linting of JS (Pro package only) - working_directory: react_on_rails_pro - command: yarn run nps eslint - - - &lint-ruby - name: Linting of Ruby (Pro package only) - working_directory: react_on_rails_pro - command: bundle exec rubocop - - - &format - name: Check formatting (Pro package only) - working_directory: react_on_rails_pro - command: yarn run nps format.listDifferent - - - &typescript-check - name: Check TypeScript (Pro package only) - working_directory: react_on_rails_pro - command: yarn run nps check-typescript - - # Install/update Node modules for renderer package unless existing set of modules is satisfying Yarn. - - &install-package-node-modules - name: Install Node modules with Yarn for pro renderer package - working_directory: react_on_rails_pro - command: | - sudo yarn global add yalc - yarn install --frozen-lockfile --no-progress --no-emoji - - # Install/update Node modules for dummy app unless existing set of modules is satisfying Yarn. - - &install-dummy-app-node-modules - name: Install Node modules with Yarn for pro dummy app - working_directory: react_on_rails_pro - command: | - cd spec/dummy - yarn install --frozen-lockfile --no-progress --no-emoji - - # Install ruby gems unless existing set of gems is satisfying bundler. - - &install-dummy-app-ruby-gems - name: Install Ruby Gems for pro dummy app - working_directory: react_on_rails_pro - command: | - gem install bundler -v "2.5.4" - echo "Bundler version: "; bundle --version - bundle config set --local path 'vendor/bundle' - bundle config set --local disable_checksum_validation true - cd spec/dummy && bundle lock --add-platform 'x86_64-linux' && bundle _2.5.4_ check || bundle _2.5.4_ install --jobs=4 --retry=3 - - - &generate-dummy-app-packs - name: Generate file-system based entrypoints (Pro) - working_directory: react_on_rails_pro - command: | - cd spec/dummy - bundle exec rake react_on_rails:generate_packs - - # Install ruby gems unless existing set of gems is satisfying bundler. - - &install-package-ruby-gems - name: Install Ruby Gems for pro package - working_directory: react_on_rails_pro - command: | - gem install bundler -v "2.5.4" - echo "Bundler version: "; bundle --version - bundle config set --local path 'vendor/bundle' - bundle config set --local disable_checksum_validation true - bundle _2.5.4_ check || bundle _2.5.4_ install --jobs=4 --retry=3 - - # Restore node_modules dir from cache using yarn.lock checksum as a key. - - &restore-package-node-modules-cache - name: Restore cached node_modules directory (Pro) - keys: - - v4-pro-package-node-modules-cache-{{ checksum "react_on_rails_pro/yarn.lock" }} - - # Restore spec/dummy/node_modules dir from cache using yarn.lock checksum as a key. - - &restore-dummy-app-node-modules-cache - name: Restore cached spec/dummy/node_modules directory (Pro) - keys: - - v4-pro-dummy-app-node-modules-cache-{{ checksum "react_on_rails_pro/spec/dummy/yarn.lock" }} - - # Restore vendor/bundle dir from cache using Gemfile.lock checksum as a key. - - &restore-dummy-app-gem-cache - name: Restore cached Ruby Gems for pro dummy app - keys: - - v4-pro-dummy-app-gem-cache-{{ checksum "react_on_rails_pro/spec/dummy/Gemfile.lock" }} - - # Restore vendor/bundle dir from cache using react_on_rails_pro.gemspec checksum as a key. - - &restore-package-gem-cache - name: Restore cached Ruby Gems for pro package - keys: - - v4-pro-package-app-gem-cache-{{ checksum "react_on_rails_pro/react_on_rails_pro.gemspec" }} - - # Restore webpack bundles for dummy app from cache - - &restore-dummy-app-webpack-bundle-cache - name: Restore cached webpack bundles for pro dummy app - key: v4-pro-dummy-app-webpack-bundle-{{ .Revision }} - - # NOTE: Sometimes CI generated docker images are not updated in time to keep up with the minimum required - # by chromedriver versions of Chrome. Just bump here Chrome version if chromedriver raises errors - - &install-latest-chrome - name: Ensure minimum required Chrome version - command: | - echo -e "Installed $(google-chrome --version)\n" - MINIMUM_REQUIRED_CHROME_VERSION=75 - INSTALLED_CHROME_MAJOR_VERSION="$(google-chrome --version | tr ' .' '\t' | cut -f3)" - if [[ $INSTALLED_CHROME_MAJOR_VERSION < $MINIMUM_REQUIRED_CHROME_VERSION ]]; then - wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add - - sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' - sudo apt-get update - sudo apt-get install google-chrome-stable - echo -e "\nInstalled $(google-chrome --version)" - fi - -jobs: - # Lint all - lint-js-and-ruby: - docker: - - image: &docker_image cimg/ruby:3.3.7-browsers - steps: - - checkout - - run: *print-system-info - - restore_cache: *restore-package-node-modules-cache - - restore_cache: *restore-package-gem-cache - - restore_cache: *restore-dummy-app-node-modules-cache - - run: *install-package-ruby-gems - - run: *install-package-node-modules - - run: *install-dummy-app-ruby-gems - - run: *install-dummy-app-node-modules - - run: - name: Install Node modules with Yarn for ExecJS dummy app (Pro) - working_directory: react_on_rails_pro - command: | - cd spec/execjs-compatible-dummy - yarn install --frozen-lockfile --no-progress --no-emoji - - run: *generate-dummy-app-packs - - run: *lint-ruby - - run: *lint-js - - run: *format - - run: *typescript-check - - # Install Node modules for Renderer package with Yarn and save them to cache. - install-package-node-packages: - docker: - - image: *docker_image - steps: - - checkout - - run: *print-system-info - - restore_cache: *restore-package-node-modules-cache - - run: *install-package-node-modules - - save_cache: - name: Save pro root node_modules to cache - key: v4-pro-package-node-modules-cache-{{ checksum "react_on_rails_pro/yarn.lock" }} - paths: - - react_on_rails_pro/node_modules - - # Install Node modules for dummy app with Yarn and save them to cache. - install-dummy-app-node-packages: - docker: - - image: *docker_image - steps: - - checkout - - run: *print-system-info - - restore_cache: *restore-dummy-app-node-modules-cache - - run: *install-package-node-modules - - run: *install-dummy-app-node-modules - - save_cache: - name: Save pro spec/dummy/node_modules to cache - key: v4-pro-dummy-app-node-modules-cache-{{ checksum "react_on_rails_pro/spec/dummy/yarn.lock" }} - paths: - - react_on_rails_pro/spec/dummy/node_modules - - # Install Ruby gems for package with Bundler and save them to cache. - install-package-ruby-gems: - docker: - - image: *docker_image - steps: - - checkout - - run: *print-system-info - - restore_cache: *restore-package-gem-cache - - run: *install-package-ruby-gems - - save_cache: - name: Save pro package ruby gems to cache - key: v4-pro-package-app-gem-cache-{{ checksum "react_on_rails_pro/react_on_rails_pro.gemspec" }} - paths: - - react_on_rails_pro/vendor/bundle - - # Install Ruby gems for dummy app with Bundler and save them to cache. - install-dummy-app-ruby-gems: - docker: - - image: *docker_image - steps: - - checkout - - run: *print-system-info - - restore_cache: *restore-dummy-app-gem-cache - - run: *install-dummy-app-ruby-gems - - save_cache: - name: Save pro dummy app ruby gems to cache - key: v4-pro-dummy-app-gem-cache-{{ checksum "react_on_rails_pro/spec/dummy/Gemfile.lock" }} - paths: - - react_on_rails_pro/spec/dummy/vendor/bundle - - # Build client and server bundles for dummy app with Webpack and save them to cache. - # NOTE: keeping around this cache in case we have multiple rspec suites in the future to tests - # different node renderers. - build-dummy-app-webpack-test-bundles: - docker: - - image: *docker_image - steps: - - checkout - - run: *print-system-info - - restore_cache: *restore-package-node-modules-cache - - restore_cache: *restore-dummy-app-node-modules-cache - - restore_cache: *restore-dummy-app-gem-cache - - run: *install-package-node-modules - - run: *install-dummy-app-node-modules - - run: *install-dummy-app-ruby-gems - - run: *generate-dummy-app-packs - - run: - name: Build test bundles for pro dummy app - working_directory: react_on_rails_pro - command: cd spec/dummy && yarn run build:test - - save_cache: - name: Save test webpack bundles to cache (for build number checksum used by rspec job) - key: v4-pro-dummy-app-webpack-bundle-{{ .Revision }} - paths: - - react_on_rails_pro/spec/dummy/public/webpack/test - - react_on_rails_pro/spec/dummy/ssr-generated - - # Run JS unit tests for Renderer package. - package-js-tests: - docker: - - image: *docker_image - steps: - - checkout - - run: *print-system-info - - restore_cache: *restore-package-node-modules-cache - - run: rm -rf react_on_rails_pro/spec/dummy/public/webpack - - run: rm -rf react_on_rails_pro/spec/dummy/ssr-generated - - restore_cache: *restore-dummy-app-webpack-bundle-cache - - run: *install-package-node-modules - # https://circleci.com/docs/collect-test-data/#jest - - run: - name: Run JS unit tests for Pro Renderer package - working_directory: react_on_rails_pro - command: yarn run nps test.ci - environment: - JEST_JUNIT_OUTPUT_DIR: ./jest - JEST_JUNIT_ADD_FILE_ATTRIBUTE: "true" - - store_test_results: - path: ./jest - - rspec-package-specs: - docker: - - image: *docker_image - steps: - - checkout - - run: *print-system-info - - restore_cache: *restore-package-gem-cache - - run: *install-package-ruby-gems - - run: - name: Run rspec tests (Pro package) - working_directory: react_on_rails_pro - command: | - bundle exec rspec spec/react_on_rails_pro - - store_test_results: - path: ~/rspec - - store_artifacts: - path: react_on_rails_pro/log/test.log - - # Start Renderer and run RSpec test suite for dummy app. - # NOTES: - # Seems that we cannot use symlinks (yarn link) with caches for the main renderer package - # react-on-rails-pro-node-renderer. Consequently, we just reinstall the top level, renderer, node packages - # as well as the - rspec-dummy-app-node-renderer: - docker: - - image: *docker_image - steps: - - checkout - - run: *print-system-info - - restore_cache: *restore-package-gem-cache - - restore_cache: *restore-package-node-modules-cache - - restore_cache: *restore-dummy-app-node-modules-cache - - restore_cache: *restore-dummy-app-gem-cache - - run: rm -rf react_on_rails_pro/spec/dummy/public/webpack - - run: rm -rf react_on_rails_pro/spec/dummy/ssr-generated - - restore_cache: *restore-dummy-app-webpack-bundle-cache - - run: *install-dummy-app-ruby-gems - - run: *install-package-node-modules - - run: *install-latest-chrome - - run: *install-dummy-app-node-modules - - run: - name: Generate file-system based entrypoints (Pro) - working_directory: react_on_rails_pro - command: cd spec/dummy && bundle exec rake react_on_rails:generate_packs - - run: - name: Run Pro Node renderer in a background - working_directory: react_on_rails_pro - command: cd spec/dummy && yarn run node-renderer - background: true - - run: - name: run rails server in background (Pro dummy app) - working_directory: react_on_rails_pro - command: cd spec/dummy && RAILS_ENV=test rails server - background: true - - run: - name: wait for rails server to start - command: | - while ! curl -s http://localhost:3000 > /dev/null; do sleep 1; done - - run: - name: Run rspec tests (Pro dummy app) - working_directory: react_on_rails_pro/spec/dummy - command: | - circleci tests glob "spec/**/*_spec.rb" | - circleci tests run --command="xargs bundle exec rspec \ - --profile 10 \ - --format progress \ - --format RspecJunitFormatter \ - --out ~/rspec/rspec.xml \ - --format documentation" \ - --verbose \ - --split-by=timings - - store_test_results: - path: ~/rspec - - store_artifacts: - path: react_on_rails_pro/spec/dummy/tmp/screenshots - - store_artifacts: - path: react_on_rails_pro/spec/dummy/tmp/capybara - - store_artifacts: - path: react_on_rails_pro/spec/dummy/log/test.log - - store_artifacts: - path: react_on_rails_pro/spec/dummy/yarn-error.log - - # TODO: DRY with previous job - dummy-app-node-renderer-e2-tests: - docker: - - image: *docker_image - - image: cimg/redis:6.2.6 - steps: - - checkout - - run: *print-system-info - - restore_cache: *restore-package-gem-cache - - restore_cache: *restore-package-node-modules-cache - - restore_cache: *restore-dummy-app-node-modules-cache - - restore_cache: *restore-dummy-app-gem-cache - - run: rm -rf react_on_rails_pro/spec/dummy/public/webpack - - run: rm -rf react_on_rails_pro/spec/dummy/ssr-generated - - restore_cache: *restore-dummy-app-webpack-bundle-cache - - run: *install-dummy-app-ruby-gems - - run: *install-package-node-modules - - run: *install-latest-chrome - - run: *install-dummy-app-node-modules - - run: - name: Generate file-system based entrypoints (Pro) - working_directory: react_on_rails_pro - command: cd spec/dummy && bundle exec rake react_on_rails:generate_packs - - run: - name: Run Pro Node renderer in a background - working_directory: react_on_rails_pro - command: cd spec/dummy && yarn run node-renderer - background: true - - run: - name: run rails server in background (Pro dummy app) - working_directory: react_on_rails_pro - command: cd spec/dummy && RAILS_ENV=test rails server - background: true - - run: - name: wait for rails server to start - command: | - while ! curl -s http://localhost:3000 > /dev/null; do sleep 1; done - - run: - name: install playwright dependencies - working_directory: react_on_rails_pro/spec/dummy - command: yarn playwright install --with-deps - - run: - name: Run playwright tests (Pro dummy app) - working_directory: react_on_rails_pro/spec/dummy - command: yarn e2e-test - - store_test_results: - path: react_on_rails_pro/spec/dummy/test-results/results.xml - - store_artifacts: - path: react_on_rails_pro/spec/dummy/playwright-report - -workflows: - version: 2 - build-and-test: - jobs: - - install-package-node-packages - - install-package-ruby-gems - - install-dummy-app-node-packages: - requires: - - install-package-node-packages - - install-dummy-app-ruby-gems - - lint-js-and-ruby: - requires: - - install-package-node-packages - - install-package-ruby-gems - - install-dummy-app-node-packages - - build-dummy-app-webpack-test-bundles: - requires: - - install-package-node-packages - - install-dummy-app-node-packages - - install-dummy-app-ruby-gems - - package-js-tests: - requires: - - install-package-node-packages - - build-dummy-app-webpack-test-bundles - - rspec-package-specs: - requires: - - install-package-ruby-gems - - rspec-dummy-app-node-renderer: - requires: - - install-package-ruby-gems - - build-dummy-app-webpack-test-bundles - - dummy-app-node-renderer-e2-tests: - requires: - - install-package-ruby-gems - - build-dummy-app-webpack-test-bundles diff --git a/.github/workflows/pro-integration-tests.yml b/.github/workflows/pro-integration-tests.yml new file mode 100644 index 0000000000..b99ee3871c --- /dev/null +++ b/.github/workflows/pro-integration-tests.yml @@ -0,0 +1,429 @@ +name: React on Rails Pro - Integration Tests + +on: + push: + branches: + - 'master' + pull_request: + +defaults: + run: + working-directory: react_on_rails_pro + +jobs: + # Build webpack test bundles for dummy app + build-dummy-app-webpack-test-bundles: + runs-on: ubuntu-22.04 + env: + REACT_ON_RAILS_PRO_LICENSE: ${{ secrets.REACT_ON_RAILS_PRO_LICENSE }} + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.3.7 + bundler: 2.5.4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: yarn + cache-dependency-path: 'react_on_rails_pro/**/yarn.lock' + + - name: Print system information + run: | + echo "Linux release: "; cat /etc/issue + echo "Current user: "; whoami + echo "Current directory: "; pwd + echo "Ruby version: "; ruby -v + echo "Node version: "; node -v + echo "Yarn version: "; yarn --version + echo "Bundler version: "; bundle --version + + - name: Cache Pro package node modules + uses: actions/cache@v4 + with: + path: react_on_rails_pro/node_modules + key: v4-pro-package-node-modules-cache-${{ hashFiles('react_on_rails_pro/yarn.lock') }} + + - name: Cache Pro dummy app node modules + uses: actions/cache@v4 + with: + path: react_on_rails_pro/spec/dummy/node_modules + key: v4-pro-dummy-app-node-modules-cache-${{ hashFiles('react_on_rails_pro/spec/dummy/yarn.lock') }} + + - name: Cache Pro dummy app Ruby gems + uses: actions/cache@v4 + with: + path: react_on_rails_pro/spec/dummy/vendor/bundle + key: v4-pro-dummy-app-gem-cache-${{ hashFiles('react_on_rails_pro/spec/dummy/Gemfile.lock') }} + + - name: Install Node modules with Yarn for Pro package + run: | + sudo yarn global add yalc + yarn install --frozen-lockfile --no-progress --no-emoji + + - name: Install Node modules with Yarn for Pro dummy app + run: cd spec/dummy && yarn install --frozen-lockfile --no-progress --no-emoji + + - name: Install Ruby Gems for Pro dummy app + run: | + gem install bundler -v "2.5.4" + cd spec/dummy + bundle lock --add-platform 'x86_64-linux' + bundle _2.5.4_ check || bundle _2.5.4_ install --jobs=4 --retry=3 + + - name: Generate file-system based entrypoints + run: cd spec/dummy && bundle exec rake react_on_rails:generate_packs + + - name: Build test bundles for Pro dummy app + run: cd spec/dummy && yarn run build:test + + - id: get-sha + run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + + - name: Save test webpack bundles to cache + uses: actions/cache/save@v4 + with: + path: | + react_on_rails_pro/spec/dummy/public/webpack/test + react_on_rails_pro/spec/dummy/ssr-generated + key: v4-pro-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }} + + # RSpec integration tests with Node renderer + rspec-dummy-app-node-renderer: + needs: build-dummy-app-webpack-test-bundles + runs-on: ubuntu-22.04 + env: + REACT_ON_RAILS_PRO_LICENSE: ${{ secrets.REACT_ON_RAILS_PRO_LICENSE }} + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.3.7 + bundler: 2.5.4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: yarn + cache-dependency-path: 'react_on_rails_pro/**/yarn.lock' + + - name: Print system information + run: | + echo "Linux release: "; cat /etc/issue + echo "Current user: "; whoami + echo "Current directory: "; pwd + echo "Ruby version: "; ruby -v + echo "Node version: "; node -v + echo "Yarn version: "; yarn --version + echo "Bundler version: "; bundle --version + + - name: Cache Pro package Ruby gems + uses: actions/cache@v4 + with: + path: react_on_rails_pro/vendor/bundle + key: v4-pro-package-gem-cache-${{ hashFiles('react_on_rails_pro/react_on_rails_pro.gemspec') }} + + - name: Cache Pro package node modules + uses: actions/cache@v4 + with: + path: react_on_rails_pro/node_modules + key: v4-pro-package-node-modules-cache-${{ hashFiles('react_on_rails_pro/yarn.lock') }} + + - name: Cache Pro dummy app node modules + uses: actions/cache@v4 + with: + path: react_on_rails_pro/spec/dummy/node_modules + key: v4-pro-dummy-app-node-modules-cache-${{ hashFiles('react_on_rails_pro/spec/dummy/yarn.lock') }} + + - name: Cache Pro dummy app Ruby gems + uses: actions/cache@v4 + with: + path: react_on_rails_pro/spec/dummy/vendor/bundle + key: v4-pro-dummy-app-gem-cache-${{ hashFiles('react_on_rails_pro/spec/dummy/Gemfile.lock') }} + + - name: Remove old webpack bundles + run: | + rm -rf spec/dummy/public/webpack + rm -rf spec/dummy/ssr-generated + + - id: get-sha + run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + + - name: Restore test webpack bundles from cache + uses: actions/cache@v4 + with: + path: | + react_on_rails_pro/spec/dummy/public/webpack/test + react_on_rails_pro/spec/dummy/ssr-generated + key: v4-pro-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }} + + - name: Install Ruby Gems for Pro dummy app + run: | + gem install bundler -v "2.5.4" + cd spec/dummy + bundle lock --add-platform 'x86_64-linux' + bundle _2.5.4_ check || bundle _2.5.4_ install --jobs=4 --retry=3 + + - name: Install Node modules with Yarn for Pro package + run: | + sudo yarn global add yalc + yarn install --frozen-lockfile --no-progress --no-emoji + + - name: Install Node modules with Yarn for Pro dummy app + run: cd spec/dummy && yarn install --frozen-lockfile --no-progress --no-emoji + + - name: Ensure minimum required Chrome version + run: | + echo -e "Installed $(google-chrome --version)\n" + MINIMUM_REQUIRED_CHROME_VERSION=75 + INSTALLED_CHROME_MAJOR_VERSION="$(google-chrome --version | tr ' .' '\t' | cut -f3)" + if [[ $INSTALLED_CHROME_MAJOR_VERSION -lt $MINIMUM_REQUIRED_CHROME_VERSION ]]; then + wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add - + sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' + sudo apt-get update + sudo apt-get install google-chrome-stable + echo -e "\nInstalled $(google-chrome --version)" + fi + + - name: Generate file-system based entrypoints + run: cd spec/dummy && bundle exec rake react_on_rails:generate_packs + + - name: Run Pro Node renderer in background + run: | + cd spec/dummy + yarn run node-renderer & + + - name: Run Rails server in background + run: | + cd spec/dummy + RAILS_ENV=test rails server & + + - name: Wait for Rails server to start + run: | + timeout=60 + elapsed=0 + while ! curl -s http://localhost:3000 > /dev/null; do + sleep 1 + elapsed=$((elapsed + 1)) + if [ $elapsed -ge $timeout ]; then + echo "Timeout waiting for Rails server to start after ${timeout}s" + exit 1 + fi + done + echo "Rails server started after ${elapsed}s" + + - name: Run RSpec tests for Pro dummy app + run: | + cd spec/dummy + bundle exec rspec \ + --profile 10 \ + --format progress \ + --format RspecJunitFormatter \ + --out ~/rspec/rspec.xml \ + --format documentation + + - name: Store test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: pro-rspec-integration-results + path: ~/rspec + + - name: Store screenshots + uses: actions/upload-artifact@v4 + if: always() + with: + name: pro-rspec-screenshots + path: react_on_rails_pro/spec/dummy/tmp/screenshots + + - name: Store Capybara artifacts + uses: actions/upload-artifact@v4 + if: always() + with: + name: pro-rspec-capybara + path: react_on_rails_pro/spec/dummy/tmp/capybara + + - name: Store test log + uses: actions/upload-artifact@v4 + if: always() + with: + name: pro-rspec-test-log + path: react_on_rails_pro/spec/dummy/log/test.log + + - name: Store yarn error log + uses: actions/upload-artifact@v4 + if: failure() + with: + name: pro-rspec-yarn-error-log + path: react_on_rails_pro/spec/dummy/yarn-error.log + + # Playwright E2E tests with Redis service + dummy-app-node-renderer-e2e-tests: + needs: build-dummy-app-webpack-test-bundles + runs-on: ubuntu-22.04 + env: + REACT_ON_RAILS_PRO_LICENSE: ${{ secrets.REACT_ON_RAILS_PRO_LICENSE }} + # Redis service container + services: + redis: + image: cimg/redis:6.2.6 + ports: + - 6379:6379 + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.3.7 + bundler: 2.5.4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: yarn + cache-dependency-path: 'react_on_rails_pro/**/yarn.lock' + + - name: Print system information + run: | + echo "Linux release: "; cat /etc/issue + echo "Current user: "; whoami + echo "Current directory: "; pwd + echo "Ruby version: "; ruby -v + echo "Node version: "; node -v + echo "Yarn version: "; yarn --version + echo "Bundler version: "; bundle --version + + - name: Cache Pro package Ruby gems + uses: actions/cache@v4 + with: + path: react_on_rails_pro/vendor/bundle + key: v4-pro-package-gem-cache-${{ hashFiles('react_on_rails_pro/react_on_rails_pro.gemspec') }} + + - name: Cache Pro package node modules + uses: actions/cache@v4 + with: + path: react_on_rails_pro/node_modules + key: v4-pro-package-node-modules-cache-${{ hashFiles('react_on_rails_pro/yarn.lock') }} + + - name: Cache Pro dummy app node modules + uses: actions/cache@v4 + with: + path: react_on_rails_pro/spec/dummy/node_modules + key: v4-pro-dummy-app-node-modules-cache-${{ hashFiles('react_on_rails_pro/spec/dummy/yarn.lock') }} + + - name: Cache Pro dummy app Ruby gems + uses: actions/cache@v4 + with: + path: react_on_rails_pro/spec/dummy/vendor/bundle + key: v4-pro-dummy-app-gem-cache-${{ hashFiles('react_on_rails_pro/spec/dummy/Gemfile.lock') }} + + - name: Remove old webpack bundles + run: | + rm -rf spec/dummy/public/webpack + rm -rf spec/dummy/ssr-generated + + - id: get-sha + run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + + - name: Restore test webpack bundles from cache + uses: actions/cache@v4 + with: + path: | + react_on_rails_pro/spec/dummy/public/webpack/test + react_on_rails_pro/spec/dummy/ssr-generated + key: v4-pro-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }} + + - name: Install Ruby Gems for Pro dummy app + run: | + gem install bundler -v "2.5.4" + cd spec/dummy + bundle lock --add-platform 'x86_64-linux' + bundle _2.5.4_ check || bundle _2.5.4_ install --jobs=4 --retry=3 + + - name: Install Node modules with Yarn for Pro package + run: | + sudo yarn global add yalc + yarn install --frozen-lockfile --no-progress --no-emoji + + - name: Install Node modules with Yarn for Pro dummy app + run: cd spec/dummy && yarn install --frozen-lockfile --no-progress --no-emoji + + - name: Ensure minimum required Chrome version + run: | + echo -e "Installed $(google-chrome --version)\n" + MINIMUM_REQUIRED_CHROME_VERSION=75 + INSTALLED_CHROME_MAJOR_VERSION="$(google-chrome --version | tr ' .' '\t' | cut -f3)" + if [[ $INSTALLED_CHROME_MAJOR_VERSION -lt $MINIMUM_REQUIRED_CHROME_VERSION ]]; then + wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add - + sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' + sudo apt-get update + sudo apt-get install google-chrome-stable + echo -e "\nInstalled $(google-chrome --version)" + fi + + - name: Generate file-system based entrypoints + run: cd spec/dummy && bundle exec rake react_on_rails:generate_packs + + - name: Run Pro Node renderer in background + run: | + cd spec/dummy + yarn run node-renderer & + + - name: Run Rails server in background + run: | + cd spec/dummy + RAILS_ENV=test rails server & + + - name: Wait for Rails server to start + run: | + timeout=300 + elapsed=0 + while ! curl -s http://localhost:3000 > /dev/null; do + sleep 1 + elapsed=$((elapsed + 1)) + if [ $elapsed -ge $timeout ]; then + echo "Timeout waiting for Rails server to start after ${timeout}s" + exit 1 + fi + done + echo "Rails server started after ${elapsed}s" + + - name: Install Playwright dependencies + run: cd spec/dummy && yarn playwright install --with-deps + + - name: Run Playwright E2E tests for Pro dummy app + run: cd spec/dummy && yarn e2e-test + + - name: Store test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: pro-playwright-test-results + path: react_on_rails_pro/spec/dummy/test-results/results.xml + + - name: Store Playwright report + uses: actions/upload-artifact@v4 + if: always() + with: + name: pro-playwright-report + path: react_on_rails_pro/spec/dummy/playwright-report diff --git a/.github/workflows/pro-lint.yml b/.github/workflows/pro-lint.yml new file mode 100644 index 0000000000..822651b992 --- /dev/null +++ b/.github/workflows/pro-lint.yml @@ -0,0 +1,108 @@ +name: React on Rails Pro - Lint + +on: + push: + branches: + - 'master' + pull_request: + +defaults: + run: + working-directory: react_on_rails_pro + +jobs: + lint-js-and-ruby: + runs-on: ubuntu-22.04 + env: + REACT_ON_RAILS_PRO_LICENSE: ${{ secrets.REACT_ON_RAILS_PRO_LICENSE }} + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.3.7 + bundler: 2.5.4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: yarn + cache-dependency-path: 'react_on_rails_pro/**/yarn.lock' + + - name: Print system information + run: | + echo "Linux release: "; cat /etc/issue + echo "Current user: "; whoami + echo "Current directory: "; pwd + echo "Ruby version: "; ruby -v + echo "Node version: "; node -v + echo "Yarn version: "; yarn --version + echo "Bundler version: "; bundle --version + + - name: Cache Pro package node modules + uses: actions/cache@v4 + with: + path: react_on_rails_pro/node_modules + key: v4-pro-package-node-modules-cache-${{ hashFiles('react_on_rails_pro/yarn.lock') }} + + - name: Cache Pro package Ruby gems + uses: actions/cache@v4 + with: + path: react_on_rails_pro/vendor/bundle + key: v4-pro-package-gem-cache-${{ hashFiles('react_on_rails_pro/react_on_rails_pro.gemspec') }} + + - name: Cache Pro dummy app node modules + uses: actions/cache@v4 + with: + path: react_on_rails_pro/spec/dummy/node_modules + key: v4-pro-dummy-app-node-modules-cache-${{ hashFiles('react_on_rails_pro/spec/dummy/yarn.lock') }} + + - name: Cache Pro dummy app Ruby gems + uses: actions/cache@v4 + with: + path: react_on_rails_pro/spec/dummy/vendor/bundle + key: v4-pro-dummy-app-gem-cache-${{ hashFiles('react_on_rails_pro/spec/dummy/Gemfile.lock') }} + + - name: Install Ruby Gems for Pro package + run: | + gem install bundler -v "2.5.4" + echo "Bundler version: "; bundle --version + bundle config set --local path 'vendor/bundle' + bundle config set --local disable_checksum_validation true + bundle _2.5.4_ check || bundle _2.5.4_ install --jobs=4 --retry=3 + + - name: Install Node modules with Yarn for Pro package + run: | + sudo yarn global add yalc + yarn install --frozen-lockfile --no-progress --no-emoji + + - name: Install Ruby Gems for Pro dummy app + run: | + cd spec/dummy + bundle lock --add-platform 'x86_64-linux' + bundle _2.5.4_ check || bundle _2.5.4_ install --jobs=4 --retry=3 + + - name: Install Node modules with Yarn for Pro dummy app + run: cd spec/dummy && yarn install --frozen-lockfile --no-progress --no-emoji + + - name: Install Node modules with Yarn for ExecJS dummy app + run: cd spec/execjs-compatible-dummy && yarn install --frozen-lockfile --no-progress --no-emoji + + - name: Generate file-system based entrypoints + run: cd spec/dummy && bundle exec rake react_on_rails:generate_packs + + - name: Lint Ruby + run: bundle exec rubocop + + - name: Lint JS + run: yarn run nps eslint + + - name: Check formatting + run: yarn run nps format.listDifferent + + - name: Check TypeScript + run: yarn run nps check-typescript diff --git a/.github/workflows/pro-package-tests.yml b/.github/workflows/pro-package-tests.yml new file mode 100644 index 0000000000..720166085b --- /dev/null +++ b/.github/workflows/pro-package-tests.yml @@ -0,0 +1,219 @@ +name: React on Rails Pro - Package Tests + +on: + push: + branches: + - 'master' + pull_request: + +defaults: + run: + working-directory: react_on_rails_pro + +jobs: + # Build webpack test bundles for dummy app + build-dummy-app-webpack-test-bundles: + runs-on: ubuntu-22.04 + env: + REACT_ON_RAILS_PRO_LICENSE: ${{ secrets.REACT_ON_RAILS_PRO_LICENSE }} + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.3.7 + bundler: 2.5.4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: yarn + cache-dependency-path: 'react_on_rails_pro/**/yarn.lock' + + - name: Print system information + run: | + echo "Linux release: "; cat /etc/issue + echo "Current user: "; whoami + echo "Current directory: "; pwd + echo "Ruby version: "; ruby -v + echo "Node version: "; node -v + echo "Yarn version: "; yarn --version + echo "Bundler version: "; bundle --version + + - name: Cache Pro package node modules + uses: actions/cache@v4 + with: + path: react_on_rails_pro/node_modules + key: v4-pro-package-node-modules-cache-${{ hashFiles('react_on_rails_pro/yarn.lock') }} + + - name: Cache Pro dummy app node modules + uses: actions/cache@v4 + with: + path: react_on_rails_pro/spec/dummy/node_modules + key: v4-pro-dummy-app-node-modules-cache-${{ hashFiles('react_on_rails_pro/spec/dummy/yarn.lock') }} + + - name: Cache Pro dummy app Ruby gems + uses: actions/cache@v4 + with: + path: react_on_rails_pro/spec/dummy/vendor/bundle + key: v4-pro-dummy-app-gem-cache-${{ hashFiles('react_on_rails_pro/spec/dummy/Gemfile.lock') }} + + - name: Install Node modules with Yarn for Pro package + run: | + sudo yarn global add yalc + yarn install --frozen-lockfile --no-progress --no-emoji + + - name: Install Node modules with Yarn for Pro dummy app + run: cd spec/dummy && yarn install --frozen-lockfile --no-progress --no-emoji + + - name: Install Ruby Gems for Pro dummy app + run: | + gem install bundler -v "2.5.4" + cd spec/dummy + bundle lock --add-platform 'x86_64-linux' + bundle _2.5.4_ check || bundle _2.5.4_ install --jobs=4 --retry=3 + + - name: Generate file-system based entrypoints + run: cd spec/dummy && bundle exec rake react_on_rails:generate_packs + + - name: Build test bundles for Pro dummy app + run: cd spec/dummy && yarn run build:test + + - id: get-sha + run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + + - name: Save test webpack bundles to cache + uses: actions/cache/save@v4 + with: + path: | + react_on_rails_pro/spec/dummy/public/webpack/test + react_on_rails_pro/spec/dummy/ssr-generated + key: v4-pro-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }} + + # Jest unit tests for Pro package + package-js-tests: + needs: build-dummy-app-webpack-test-bundles + runs-on: ubuntu-22.04 + env: + REACT_ON_RAILS_PRO_LICENSE: ${{ secrets.REACT_ON_RAILS_PRO_LICENSE }} + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: yarn + cache-dependency-path: 'react_on_rails_pro/**/yarn.lock' + + - name: Print system information + run: | + echo "Linux release: "; cat /etc/issue + echo "Current user: "; whoami + echo "Current directory: "; pwd + echo "Node version: "; node -v + echo "Yarn version: "; yarn --version + + - name: Cache Pro package node modules + uses: actions/cache@v4 + with: + path: react_on_rails_pro/node_modules + key: v4-pro-package-node-modules-cache-${{ hashFiles('react_on_rails_pro/yarn.lock') }} + + - name: Remove old webpack bundles + run: | + rm -rf spec/dummy/public/webpack + rm -rf spec/dummy/ssr-generated + + - id: get-sha + run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + + - name: Restore test webpack bundles from cache + uses: actions/cache@v4 + with: + path: | + react_on_rails_pro/spec/dummy/public/webpack/test + react_on_rails_pro/spec/dummy/ssr-generated + key: v4-pro-dummy-app-webpack-bundle-${{ steps.get-sha.outputs.sha }} + + - name: Install Node modules with Yarn for Pro package + run: | + sudo yarn global add yalc + yarn install --frozen-lockfile --no-progress --no-emoji + + - name: Run JS unit tests for Pro package + run: yarn run nps test.ci + env: + JEST_JUNIT_OUTPUT_DIR: ./jest + JEST_JUNIT_ADD_FILE_ATTRIBUTE: "true" + + - name: Store test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: pro-jest-results + path: react_on_rails_pro/jest + + # RSpec tests for Pro package + rspec-package-specs: + strategy: + matrix: + ruby-version: ['3.3.7'] + runs-on: ubuntu-22.04 + env: + REACT_ON_RAILS_PRO_LICENSE: ${{ secrets.REACT_ON_RAILS_PRO_LICENSE }} + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler: 2.5.4 + + - name: Print system information + run: | + echo "Linux release: "; cat /etc/issue + echo "Current user: "; whoami + echo "Current directory: "; pwd + echo "Ruby version: "; ruby -v + echo "Bundler version: "; bundle --version + + - name: Cache Pro package Ruby gems + uses: actions/cache@v4 + with: + path: react_on_rails_pro/vendor/bundle + key: v4-pro-package-gem-cache-ruby${{ matrix.ruby-version }}-${{ hashFiles('react_on_rails_pro/react_on_rails_pro.gemspec') }} + + - name: Install Ruby Gems for Pro package + run: | + gem install bundler -v "2.5.4" + echo "Bundler version: "; bundle --version + bundle config set --local path 'vendor/bundle' + bundle config set --local disable_checksum_validation true + bundle _2.5.4_ check || bundle _2.5.4_ install --jobs=4 --retry=3 + + - name: Run RSpec tests for Pro package + run: bundle exec rspec spec/react_on_rails_pro + + - name: Store test results + uses: actions/upload-artifact@v4 + if: always() + with: + name: pro-rspec-package-results-ruby${{ matrix.ruby-version }} + path: ~/rspec + + - name: Store test log + uses: actions/upload-artifact@v4 + if: always() + with: + name: pro-rspec-package-log-ruby${{ matrix.ruby-version }} + path: react_on_rails_pro/log/test.log diff --git a/knip.ts b/knip.ts index ca342d404e..82692470c7 100644 --- a/knip.ts +++ b/knip.ts @@ -11,6 +11,9 @@ const config: KnipConfig = { // Has to be installed globally 'yalc', 'nps', + // Pro package binaries used in Pro workflows + 'playwright', + 'e2e-test', ], ignore: ['react_on_rails_pro/**'], ignoreDependencies: [ diff --git a/react_on_rails_pro/packages/node-renderer/tests/htmlStreaming.test.js b/react_on_rails_pro/packages/node-renderer/tests/htmlStreaming.test.js index ec7e1b7ccb..b09046de38 100644 --- a/react_on_rails_pro/packages/node-renderer/tests/htmlStreaming.test.js +++ b/react_on_rails_pro/packages/node-renderer/tests/htmlStreaming.test.js @@ -72,8 +72,8 @@ const createForm = ({ project = 'spec-dummy', commit = '', props = {}, throwJsEr const makeRequest = async (options = {}) => { const startTime = Date.now(); const form = createForm(options); - const { address, port } = app.server.address(); - const client = http2.connect(`http://${address}:${port}`); + const { port } = app.server.address(); + const client = http2.connect(`http://localhost:${port}`); const request = client.request({ ':method': 'POST', ':path': `/bundles/${SERVER_BUNDLE_TIMESTAMP}/render/454a82526211afdb215352755d36032c`, diff --git a/react_on_rails_pro/spec/dummy/playwright.config.ts b/react_on_rails_pro/spec/dummy/playwright.config.ts index 10e3eaa084..2196d4a3c6 100644 --- a/react_on_rails_pro/spec/dummy/playwright.config.ts +++ b/react_on_rails_pro/spec/dummy/playwright.config.ts @@ -38,42 +38,49 @@ export default defineConfig({ }, /* Configure projects for major browsers */ - projects: [ - { - name: 'chromium', - use: { ...devices['Desktop Chrome'] }, - }, + projects: process.env.CI + ? [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + ] + : [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, - { - name: 'firefox', - use: { ...devices['Desktop Firefox'] }, - }, + { + name: 'firefox', + use: { ...devices['Desktop Firefox'] }, + }, - { - name: 'webkit', - use: { ...devices['Desktop Safari'] }, - }, + { + name: 'webkit', + use: { ...devices['Desktop Safari'] }, + }, - /* Test against mobile viewports. */ - // { - // name: 'Mobile Chrome', - // use: { ...devices['Pixel 5'] }, - // }, - // { - // name: 'Mobile Safari', - // use: { ...devices['iPhone 12'] }, - // }, + /* Test against mobile viewports. */ + // { + // name: 'Mobile Chrome', + // use: { ...devices['Pixel 5'] }, + // }, + // { + // name: 'Mobile Safari', + // use: { ...devices['iPhone 12'] }, + // }, - /* Test against branded browsers. */ - // { - // name: 'Microsoft Edge', - // use: { ...devices['Desktop Edge'], channel: 'msedge' }, - // }, - // { - // name: 'Google Chrome', - // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, - // }, - ], + /* Test against branded browsers. */ + // { + // name: 'Microsoft Edge', + // use: { ...devices['Desktop Edge'], channel: 'msedge' }, + // }, + // { + // name: 'Google Chrome', + // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, + // }, + ], /* Run your local dev server before starting the tests */ // webServer: {