mberlanda/cheidelacoriera

View on GitHub
.github/workflows/ruby.yml

Summary

Maintainability
Test Coverage
name: Application build
on: [push]
jobs:
  build:
    name: Linters and Security
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Install PostgreSQL client
        run: |
          sudo apt-get -yqq install libpq-dev
      - name: Setup Ruby and install gems
        uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
          ruby-version: 2.7.8
      - name: Bundle audit
        run: |
          bundle exec bundle-audit --update
      - name: Brakeman security checks
        run: |
          bundle exec brakeman
      - name: Rubocop linting
        run: |
          bundle exec rubocop
  tests:
    name: Unit tests
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:9.6
        env:
          POSTGRES_DB: cheidelacoriera_test
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
        ports:
          - 5432:5432
        # Set health checks to wait until postgres has started
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        # options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
    steps:
      - uses: actions/checkout@v1
      - name: Setup Code Climate test-reporter
        run: |
          curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
          chmod +x ./cc-test-reporter
          ./cc-test-reporter before-build
      - name: Setup Ruby and install gems
        uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
          ruby-version: 2.7.8
      - name: Setup Node
        uses: actions/setup-node@v1
        with:
          node-version: 16.10.0.0
      - name: Setup Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.9'
      - name: Find yarn cache location
        id: yarn-cache
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - name: JS package cache
        uses: actions/cache@v1
        with:
          path: ${{ steps.yarn-cache.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install packages
        run: |
          yarn install --pure-lockfile
      - name: Run ESLint
        run: yarn run lint
      - name: Run Jest tests
        env:
          NODE_ENV: test
        run: yarn run test app/javascript --coverage
      - name: Install PostgreSQL client
        run: |
          sudo apt-get -yqq install libpq-dev
      - name: Run RSpec tests
        env:
          PGHOST: localhost
          PGUSER: postgres
          PGPASSWORD: postgres
          RAILS_ENV: test
          NODE_ENV: test
        run: |
          bundle exec rails webpacker:compile
          bundle exec rake db:test:prepare
          COVERAGE=true bundle exec rspec spec
      - name: Publish code coverage
        run: |
          export GIT_BRANCH="${GITHUB_REF/refs\/heads\//}"
          ./cc-test-reporter format-coverage -t simplecov -o coverage/codeclimate.rspec.json
          wc -lc coverage/codeclimate.rspec.json 
          ./cc-test-reporter format-coverage -t lcov -o coverage/codeclimate.jest.json
          wc -lc coverage/codeclimate.jest.json
          ./cc-test-reporter sum-coverage coverage/codeclimate.*.json -p 2
          ls coverage
          ./cc-test-reporter upload-coverage -r ${{secrets.CC_TEST_REPORTER_ID}}
  docker-build:
    name: Docker build
    runs-on: ubuntu-latest
    steps:
      - name: Check Out Repo
        uses: actions/checkout@v2

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1

      - name: Build and push
        id: docker_build
        uses: docker/build-push-action@v2
        with:
          context: ./
          file: ./Dockerfile.web
          push: false