Skip to content

Commit

Permalink
Merge pull request #8866 from Fryguy/github_actions_cypress
Browse files Browse the repository at this point in the history
Add Cypress to GitHub Actions
  • Loading branch information
GilbertCherrie authored Jul 21, 2023
2 parents fa1620f + f20b28d commit a76986e
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 9 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/cypress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
name: Cypress
on:
workflow_dispatch:
schedule:
- cron: 0 0 * * 0
jobs:
cypress:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby-version:
- '3.0'
node-version:
- 18
cypress-browser:
- chrome
- firefox
- edge
services:
postgres:
image: manageiq/postgresql:13
env:
POSTGRESQL_USER: root
POSTGRESQL_PASSWORD: smartvm
POSTGRESQL_DATABASE: vmdb_development
options: "--health-cmd pg_isready --health-interval 2s --health-timeout 5s
--health-retries 5"
ports:
- 5432:5432
memcached:
image: manageiq/memcached:1.5
ports:
- 11211:11211
env:
TEST_SUITE: spec:cypress
CYPRESS_BROWSER: ${{ matrix.cypress-browser }}
PGHOST: localhost
PGPASSWORD: smartvm
steps:
- uses: actions/checkout@v3
- name: Install Edge
uses: browser-actions/setup-edge@v1
if: ${{ matrix.cypress-browser == 'edge' }}
- name: Set up system
run: bin/before_install
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "${{ matrix.ruby-version }}"
bundler-cache: true
timeout-minutes: 30
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: "${{ matrix.node-version }}"
cache: yarn
- name: Prepare tests
run: bin/setup
env: # We will be using the development database, so no need for the test database
SKIP_TEST_RESET: "true"
SKIP_DATABASE_RESET: "false"
- name: Run tests
run: bundle exec rake
- name: Save artifacts
uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-${{ matrix.cypress-browser }}
path: |
cypress/screenshots/
cypress/videos/
spec/manageiq/log/
51 changes: 44 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ namespace :spec do
exit $CHILD_STATUS.exitstatus
end

namespace :jest do
desc 'Run Jest tests with node debugger'
task :debug do
puts
puts "open your chrome://inspect/#devices on your chrome based browser (see https://facebook.github.io/jest/docs/en/troubleshooting.html for more details)"
puts
system('node --inspect-brk node_modules/.bin/jest --runInBand')
end
end

desc "Run Debride"
task :debride do
system('bash bin/ci/dead_method_check.sh')
Expand All @@ -72,13 +82,40 @@ namespace :spec do
desc "Run security specs from core"
task :security => ["app:test:security"]

namespace :jest do
desc 'Run Jest tests with node debugger'
task :debug do
puts
puts "open your chrome://inspect/#devices on your chrome based browser (see https://facebook.github.io/jest/docs/en/troubleshooting.html for more details)"
puts
system('node --inspect-brk node_modules/.bin/jest --runInBand')
desc "Run cypress specs (starts a Rails server)"
task :cypress => "cypress:run_with_rails"

namespace :cypress do
task :run_with_rails do
# Set the rate limit to a large number to avoid 429: Too Many Requests errors
# which can occur as cypress very quickly hits a lots of endpoints.
puts "\n== Removing rate limit =="
exit $?.exitstatus unless system("bundle exec rails runner 'MiqServer.my_server.add_settings_for_resource(:server => {:rate_limiting => {:request => {:limit => 99999}}})'")

puts "\n== Starting Rails server =="
rails_pid = Bundler.with_original_env do
spawn("bin/rails s", [:out, :err] => "/dev/null")
end
puts "== Rails server started with PID #{rails_pid} =="

Rake::Task["spec:cypress:run"].invoke
ensure
if rails_pid
puts "\n== Killing Rails server with PID #{rails_pid} =="
Process.kill("INT", rails_pid)
end
end

desc "Run cypress specs (with a running Rails server)"
task :run do
ENV["CYPRESS_BROWSER"] ||= "chrome"

puts "\n== Cypress tests started for #{ENV["CYPRESS_BROWSER"]} browser =="
system("yarn cypress:run:#{ENV["CYPRESS_BROWSER"]}")
exit_status = $?.exitstatus
puts "== Cypress tests for #{ENV["CYPRESS_BROWSER"]} browser completed =="

exit exit_status
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion bin/before_install
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ -n "$CI" ]; then
echo
fi

if [ -n "$CI" -a \( "$TEST_SUITE" = "spec:javascript" -o "$TEST_SUITE" = "spec:jest" \) ]; then
if [ -n "$CI" -a \( "$TEST_SUITE" = "spec:cypress" -o "$TEST_SUITE" = "spec:javascript" -o "$TEST_SUITE" = "spec:jest" \) ]; then
# Install google-chrome-beta
wget -q -O - https://dl-ssl.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'
Expand Down
2 changes: 1 addition & 1 deletion bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ system(gem_root.join("bin/before_install").to_s)
require gem_root.join("spec/manageiq/lib/manageiq/environment")
ManageIQ::Environment.manageiq_plugin_setup(gem_root)

if %w[spec:compile spec:javascript spec:jest].include?(ENV["TEST_SUITE"])
if %w[spec:compile spec:cypress spec:javascript spec:jest].include?(ENV["TEST_SUITE"])
puts "\n== Updating UI assets =="
exit $?.exitstatus unless system("bundle exec rake update:ui")
end

0 comments on commit a76986e

Please sign in to comment.