From ec78519af734e3aeff161e8eae0bb6d14d01b250 Mon Sep 17 00:00:00 2001 From: yassa Date: Fri, 28 Jul 2023 09:33:45 +0300 Subject: [PATCH 1/3] Separate tests workflows (#530) This commit create a separate workflow for each test: * rspec tests * lint * js_tests --- .github/workflows/js_test.yml | 76 ++++++++++++++++++++++++++++++++ .github/workflows/lint_test.yml | 51 +++++++++++++++++++++ .github/workflows/rspec_test.yml | 76 ++++++++++++++++++++++++++++++++ lib/tasks/ci.rake | 24 ++++++++++ 4 files changed, 227 insertions(+) create mode 100644 .github/workflows/js_test.yml create mode 100644 .github/workflows/lint_test.yml create mode 100644 .github/workflows/rspec_test.yml diff --git a/.github/workflows/js_test.yml b/.github/workflows/js_test.yml new file mode 100644 index 00000000..84b2f577 --- /dev/null +++ b/.github/workflows/js_test.yml @@ -0,0 +1,76 @@ +# This workflow uses actions that are not certified by GitHub. They are +# provided by a third-party and are governed by separate terms of service, +# privacy policy, and support documentation. +# +# This workflow will install a prebuilt Ruby version, install dependencies, and +# run js tests. +name: "JS CI" +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + services: + postgres: + image: postgres:11-alpine + ports: + - "5432:5432" + env: + POSTGRES_DB: rails_test + POSTGRES_USER: rails + POSTGRES_PASSWORD: password + env: + RAILS_ENV: test + NODE_ENV: test + DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test" + DRIVER: selenium_chrome + CHROME_BIN: /usr/bin/google-chrome + USE_COVERALLS: true + steps: + - name: Install Chrome + uses: browser-actions/setup-chrome@latest + + - name: Check Chrome version + run: chrome --version + + - name: Check Chrome version + run: google-chrome --version + + - name: Set Display environment variable + run: "export DISPLAY=:99" + + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Ruby and gems + uses: ruby/setup-ruby@0a29871fe2b0200a17a4497bae54fe5df0d973aa # v1.115.3 + with: + bundler-cache: true + + - name: Use Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: 18.x + - name: Install Node Packages + run: npm install --legacy-peer-deps + + - name: Set up database schema + run: bin/rails db:schema:load + + - name: Build i18n libraries + run: bundle exec rake react_on_rails:locale + + - name: Build shakapacker chunks + run: NODE_ENV=development bundle exec bin/shakapacker + + - name: Run js tests with xvfb + uses: GabrielBB/xvfb-action@v1 + with: + run: bundle exec rake ci_js_tests + working-directory: ./ #optional + options: ":99 -ac -screen scn 1600x1200x16" diff --git a/.github/workflows/lint_test.yml b/.github/workflows/lint_test.yml new file mode 100644 index 00000000..863a6429 --- /dev/null +++ b/.github/workflows/lint_test.yml @@ -0,0 +1,51 @@ +# This workflow uses actions that are not certified by GitHub. They are +# provided by a third-party and are governed by separate terms of service, +# privacy policy, and support documentation. +# +# This workflow will install a prebuilt Ruby version, install dependencies, and +# run rspec tests. +name: "Lint CI" +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + env: + RAILS_ENV: test + NODE_ENV: test + steps: + - name: Set Display environment variable + run: "export DISPLAY=:99" + + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Ruby and gems + uses: ruby/setup-ruby@0a29871fe2b0200a17a4497bae54fe5df0d973aa # v1.115.3 + with: + bundler-cache: true + + - name: Use Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: 18.x + - name: Install Node Packages + run: npm install --legacy-peer-deps + + - name: Build i18n libraries + run: bundle exec rake react_on_rails:locale + + - name: Build shakapacker chunks + run: NODE_ENV=development bundle exec bin/shakapacker + + - name: Run lint tests with xvfb + uses: GabrielBB/xvfb-action@v1 + with: + run: bundle exec rake lint + working-directory: ./ #optional + options: ":99 -ac -screen scn 1600x1200x16" diff --git a/.github/workflows/rspec_test.yml b/.github/workflows/rspec_test.yml new file mode 100644 index 00000000..baac73ad --- /dev/null +++ b/.github/workflows/rspec_test.yml @@ -0,0 +1,76 @@ +# This workflow uses actions that are not certified by GitHub. They are +# provided by a third-party and are governed by separate terms of service, +# privacy policy, and support documentation. +# +# This workflow will install a prebuilt Ruby version, install dependencies, and +# run rspec tests. +name: "rspec CI" +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + services: + postgres: + image: postgres:11-alpine + ports: + - "5432:5432" + env: + POSTGRES_DB: rails_test + POSTGRES_USER: rails + POSTGRES_PASSWORD: password + env: + RAILS_ENV: test + NODE_ENV: test + DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test" + DRIVER: selenium_chrome + CHROME_BIN: /usr/bin/google-chrome + USE_COVERALLS: true + steps: + - name: Install Chrome + uses: browser-actions/setup-chrome@latest + + - name: Check Chrome version + run: chrome --version + + - name: Check Chrome version + run: google-chrome --version + + - name: Set Display environment variable + run: "export DISPLAY=:99" + + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Ruby and gems + uses: ruby/setup-ruby@0a29871fe2b0200a17a4497bae54fe5df0d973aa # v1.115.3 + with: + bundler-cache: true + + - name: Use Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: 18.x + - name: Install Node Packages + run: npm install --legacy-peer-deps + + - name: Set up database schema + run: bin/rails db:schema:load + + - name: Build i18n libraries + run: bundle exec rake react_on_rails:locale + + - name: Build shakapacker chunks + run: NODE_ENV=development bundle exec bin/shakapacker + + - name: Run rspec tests with xvfb + uses: GabrielBB/xvfb-action@v1 + with: + run: bundle exec rake ci_rspec_tests + working-directory: ./ #optional + options: ":99 -ac -screen scn 1600x1200x16" diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 79d5808b..36f4574b 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -13,6 +13,30 @@ if Rails.env.development? || Rails.env.test? sh "rspec" end + desc "Run CI rspec tests" + task ci_rspec_tests: %i[environment rspec_tests] do + puts "CI rspec tests" + puts Rainbow("PASSED").green + puts "" + rescue StandardError => e + puts e.to_s + puts Rainbow("FAILED").red + puts "" + raise(e) + end + + desc "Run CI js_tests" + task ci_js_tests: %i[environment js_tests] do + puts "CI js_tests" + puts Rainbow("PASSED").green + puts "" + rescue StandardError => e + puts e.to_s + puts Rainbow("FAILED").red + puts "" + raise(e) + end + namespace :ci do desc "Run all audits and tests" # rspec_tests must be before lint and js_tests to build the locale files From c9b6918336638ce0bebf872b988fd4617178d539 Mon Sep 17 00:00:00 2001 From: yassa Date: Tue, 1 Aug 2023 09:15:30 +0300 Subject: [PATCH 2/3] Move ci tasks to ci namespace --- .github/workflows/js_test.yml | 2 +- .github/workflows/rspec_test.yml | 76 -------------------------------- .rubocop.yml | 1 + lib/tasks/ci.rake | 48 ++++++++++---------- 4 files changed, 26 insertions(+), 101 deletions(-) delete mode 100644 .github/workflows/rspec_test.yml diff --git a/.github/workflows/js_test.yml b/.github/workflows/js_test.yml index 84b2f577..bfb7f6e2 100644 --- a/.github/workflows/js_test.yml +++ b/.github/workflows/js_test.yml @@ -71,6 +71,6 @@ jobs: - name: Run js tests with xvfb uses: GabrielBB/xvfb-action@v1 with: - run: bundle exec rake ci_js_tests + run: bundle exec rake ci:js working-directory: ./ #optional options: ":99 -ac -screen scn 1600x1200x16" diff --git a/.github/workflows/rspec_test.yml b/.github/workflows/rspec_test.yml deleted file mode 100644 index baac73ad..00000000 --- a/.github/workflows/rspec_test.yml +++ /dev/null @@ -1,76 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. They are -# provided by a third-party and are governed by separate terms of service, -# privacy policy, and support documentation. -# -# This workflow will install a prebuilt Ruby version, install dependencies, and -# run rspec tests. -name: "rspec CI" -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] -jobs: - test: - runs-on: ubuntu-latest - strategy: - fail-fast: false - services: - postgres: - image: postgres:11-alpine - ports: - - "5432:5432" - env: - POSTGRES_DB: rails_test - POSTGRES_USER: rails - POSTGRES_PASSWORD: password - env: - RAILS_ENV: test - NODE_ENV: test - DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test" - DRIVER: selenium_chrome - CHROME_BIN: /usr/bin/google-chrome - USE_COVERALLS: true - steps: - - name: Install Chrome - uses: browser-actions/setup-chrome@latest - - - name: Check Chrome version - run: chrome --version - - - name: Check Chrome version - run: google-chrome --version - - - name: Set Display environment variable - run: "export DISPLAY=:99" - - - name: Checkout code - uses: actions/checkout@v3 - - - name: Install Ruby and gems - uses: ruby/setup-ruby@0a29871fe2b0200a17a4497bae54fe5df0d973aa # v1.115.3 - with: - bundler-cache: true - - - name: Use Node.js 18.x - uses: actions/setup-node@v3 - with: - node-version: 18.x - - name: Install Node Packages - run: npm install --legacy-peer-deps - - - name: Set up database schema - run: bin/rails db:schema:load - - - name: Build i18n libraries - run: bundle exec rake react_on_rails:locale - - - name: Build shakapacker chunks - run: NODE_ENV=development bundle exec bin/shakapacker - - - name: Run rspec tests with xvfb - uses: GabrielBB/xvfb-action@v1 - with: - run: bundle exec rake ci_rspec_tests - working-directory: ./ #optional - options: ":99 -ac -screen scn 1600x1200x16" diff --git a/.rubocop.yml b/.rubocop.yml index 8c6368e1..588860c6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -72,6 +72,7 @@ Metrics/BlockLength: - 'spec/rails_helper.rb' - 'spec/system/add_new_comment_spec.rb' - 'spec/system/react_router_demo_spec.rb' + - 'lib/tasks/ci.rake' Metrics/ParameterLists: Max: 5 diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 36f4574b..dcea8e00 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -13,30 +13,6 @@ if Rails.env.development? || Rails.env.test? sh "rspec" end - desc "Run CI rspec tests" - task ci_rspec_tests: %i[environment rspec_tests] do - puts "CI rspec tests" - puts Rainbow("PASSED").green - puts "" - rescue StandardError => e - puts e.to_s - puts Rainbow("FAILED").red - puts "" - raise(e) - end - - desc "Run CI js_tests" - task ci_js_tests: %i[environment js_tests] do - puts "CI js_tests" - puts Rainbow("PASSED").green - puts "" - rescue StandardError => e - puts e.to_s - puts Rainbow("FAILED").red - puts "" - raise(e) - end - namespace :ci do desc "Run all audits and tests" # rspec_tests must be before lint and js_tests to build the locale files @@ -50,6 +26,30 @@ if Rails.env.development? || Rails.env.test? puts "" raise(e) end + + desc "Run CI rspec tests" + task rspec: %i[environment rspec_tests] do + puts "CI rspec tests" + puts Rainbow("PASSED").green + puts "" + rescue StandardError => e + puts e.to_s + puts Rainbow("FAILED").red + puts "" + raise(e) + end + + desc "Run CI js_tests" + task js: %i[environment js_tests] do + puts "CI js_tests" + puts Rainbow("PASSED").green + puts "" + rescue StandardError => e + puts e.to_s + puts Rainbow("FAILED").red + puts "" + raise(e) + end end task ci: "ci:all" From ef28e36939260f37d2d4b0a70bdc1e20eada6fe4 Mon Sep 17 00:00:00 2001 From: yassa Date: Tue, 1 Aug 2023 09:18:26 +0300 Subject: [PATCH 3/3] Rename test workflow to rspec_test --- .github/workflows/{test.yml => rspec_test.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{test.yml => rspec_test.yml} (98%) diff --git a/.github/workflows/test.yml b/.github/workflows/rspec_test.yml similarity index 98% rename from .github/workflows/test.yml rename to .github/workflows/rspec_test.yml index de3e281e..41feb125 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/rspec_test.yml @@ -71,6 +71,6 @@ jobs: - name: Run tests with xvfb uses: GabrielBB/xvfb-action@v1 with: - run: bundle exec rake + run: bundle exec rake ci:rspec working-directory: ./ #optional options: ":99 -ac -screen scn 1600x1200x16"