From b372f31809419ed2aa29aa17cb6be295876333e2 Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Sat, 17 Feb 2024 12:30:28 -0500 Subject: [PATCH] Adding ruby CI --- .github/workflows/rspec.yml | 119 ++++++++++++++++++++++++++++++++++++ .github/workflows/ruby.yml | 54 ++++++++++++++++ .ruby-version | 2 +- 3 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/rspec.yml create mode 100644 .github/workflows/ruby.yml diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml new file mode 100644 index 00000000..c6ddd1ff --- /dev/null +++ b/.github/workflows/rspec.yml @@ -0,0 +1,119 @@ +# .github/workflows/main.yaml +name: Main + +on: [push] + +jobs: + vm-job: + name: CI + runs-on: ubuntu-latest + + # If you need DB like MySQL then define service below. + # Example for PostgreSQL and Redis can be found here: + # https://github.com/actions/example-services/tree/master/.github/workflows + services: + # How to use MySQL + mysql: + image: mysql:5.7 + env: + MYSQL_ROOT_PASSWORD: root + ports: + - 3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + # How to use Redis + redis: + image: redis + ports: + - 6379/tcp + # How to use Elasticsearch + elasticsearch: + image: elasticsearch:6.8.3 + ports: + - 9200/tcp + options: -e="discovery.type=single-node" --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=10s --health-timeout=5s --health-retries=10 + + # https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix + strategy: + fail-fast: false + matrix: + # Set N number of parallel jobs you want to run tests on. + # Use higher number if you have slow tests to split them on more parallel jobs. + # Remember to update ci_node_index below to 0..N-1 + ci_node_total: [5] + # set N-1 indexes for parallel jobs + # When you run 2 parallel jobs then first job will have index 0, the second job will have index 1 etc + ci_node_index: [0, 1, 2, 3, 4] + + steps: + - name: Checkout + uses: actions/checkout@v1 + with: + fetch-depth: 1 + + - name: Set up Ruby 2.6 + uses: actions/setup-ruby@v1 + with: + ruby-version: 2.6.5 + + - uses: actions/cache@v1 + with: + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems- + - name: Verify MySQL connection from host + run: | + sudo apt-get install -y mysql-client libmysqlclient-dev + mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports[3306] }} -uroot -proot -e "SHOW GRANTS FOR 'root'@'localhost'" + mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports[3306] }} -uroot -proot mysql + - name: Verify Elasticsearch connection from host + env: + ELASTIC_SEARCH_URL: http://localhost:${{ job.services.elasticsearch.ports[9200] }} + run: | + echo $ELASTIC_SEARCH_URL + curl -fsSL "$ELASTIC_SEARCH_URL/_cat/health?h=status" + - name: Bundle Install and Create DB + env: + RAILS_ENV: test + DB_PASSWORD: root + # tell Rails to use proper port for MySQL + DB_PORT: ${{ job.services.mysql.ports[3306] }} + run: | + cp .env.sample .env + cp config/database.yml.ci config/database.yml + gem install bundler --version 1.17.3 --no-ri --no-rdoc + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 --path vendor/bundle + # create DB for Rails 5.x + bin/rails db:setup + # create DB for Rails 6.x + bin/rails db:prepare + - name: Run tests + env: + DB_PASSWORD: root + DB_PORT: ${{ job.services.mysql.ports[3306] }} # get randomly assigned published port + REDIS_PORT: ${{ job.services.redis.ports[6379] }} + ELASTIC_SEARCH_URL: http://localhost:${{ job.services.elasticsearch.ports[9200] }} + RAILS_ENV: test + # You need to set API tokens in GitHub repository Settings -> Secrets + KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }} + KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER }} + KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST }} + KNAPSACK_PRO_TEST_SUITE_TEST_UNIT: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT }} + KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH }} + KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }} + KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }} + # if you use Knapsack Pro Queue Mode you must set below env variable + # to be able to retry CI build and run previously recorded tests + KNAPSACK_PRO_FIXED_QUEUE_SPLIT: true + run: | + # run tests in Knapsack Pro Regular Mode + bundle exec rake knapsack_pro:rspec + bundle exec rake knapsack_pro:cucumber + bundle exec rake knapsack_pro:minitest + bundle exec rake knapsack_pro:test_unit + bundle exec rake knapsack_pro:spinach + # you can use Knapsack Pro in Queue Mode once recorded first CI build with Regular Mode + bundle exec rake knapsack_pro:queue:rspec + bundle exec rake knapsack_pro:queue:cucumber + bundle exec rake knapsack_pro:queue:minitest diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 00000000..dac03857 --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,54 @@ +name: TicketBooth CI +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + # Label of the container job + container-job: + # Containers must run in Linux based operating systems + runs-on: ubuntu-latest + # Docker Hub image that `container-job` executes in + container: ruby:3.2 + + # Service containers to run with `container-job` + services: + postgres: + # Docker Hub image + image: postgres:16 + # Provide the password for postgres + env: + POSTGRES_PASSWORD: postgres + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + redis: + # Docker Hub image + image: redis + # Set health checks to wait until redis has started + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - uses: niden/actions-memcached@v7 + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1 + with: + ruby-version: '3.2.3' # Not needed with a .ruby-version file + - run: bundle install -j 12 + - run: | + bin/rails db:create + bin/rails db:migrate + bin/rails db:test:prepare + - run: bundle exec rspec --format documentation + - run: bundle exec rubocop + diff --git a/.ruby-version b/.ruby-version index be94e6f5..b347b11e 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.2.2 +3.2.3