vol1ura/Sat_9am_5km

View on GitHub
.github/workflows/rubyonrails.yml

Summary

Maintainability
Test Coverage
name: "CI-CD"
on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]
jobs:
  security:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout code
        uses: actions/checkout@main
      - name: Install Ruby and gems
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.2.2
          bundler-cache: true
      - name: Security audit dependencies
        run: bundle exec bundler-audit --update
      - name: Security audit application code
        run: bundle exec brakeman -q -w2

  lint:
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout code
        uses: actions/checkout@main
      - name: Install Ruby and gems
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.2.2
      - name: Install packages
        run: |
          bundle config set --local only test
          bundle install
      - name: Lint Ruby files
        run: rubocop --fail-fast

  test:
    needs:
      - security
      - lint
    runs-on: ubuntu-22.04
    services:
      postgres:
        image: postgres:14.3-alpine
        ports:
          - "5432:5432"
        env:
          POSTGRES_DB: rails_test
          POSTGRES_USER: rails
          POSTGRES_PASSWORD: password
    env:
      CI: true
      RAILS_ENV: test
      DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test"
      TZ: "Europe/Moscow"
      COVERAGE: on
      BULLET_ENABLED: true
      APP_HOST: "test.ru"
      ADMIN_EMAIL: "admin@test.ru"
      INFO_EMAIL: "info@test.ru"
      BOT_TOKEN: "123456:test"
      VK_TOKEN: ${{ secrets.VK_TOKEN }}
      VK_ALBUM_ID: 300954831
      VK_GROUP_ID: 220002708
    steps:
      - name: Checkout code
        uses: actions/checkout@main
      - name: Install dependencies
        run: sudo apt-get update && sudo apt-get install -y libvips
      - name: Install Ruby and gems
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.2.2
          bundler-cache: true
      - name: Set up database schema
        run: bin/rails db:schema:load
      - name: Check database consistency
        run: bundle exec database_consistency
      - name: Rspec tests
        if: github.ref != 'refs/heads/master'
        run: bundle exec rspec
      - name: Test & publish code coverage
        if: github.ref == 'refs/heads/master'
        uses: paambaati/codeclimate-action@v9
        env:
          CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE }}
        with:
          coverageCommand: bundle exec rspec

  deploy:
    if: github.ref == 'refs/heads/master'
    needs:
      - test
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout code
        uses: actions/checkout@main
      - name: Install Ruby and gems
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.2.2
          bundler-cache: true
      - name: Deploy
        uses: miloserdow/capistrano-deploy@master
        with:
          target: production
          deploy_key: ${{ secrets.DEPLOY_ENC_KEY }}
        env:
          APP_NAME: ${{ secrets.APP_NAME }}
          APP_REPO: ${{ secrets.APP_REPO }}
          DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
          DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
          APP_DEPLOY_PATH: ${{ secrets.APP_DEPLOY_PATH }}