# License: LGPL-3.0-or-later
name: Ruby test and build
on: 
  push:
    paths-ignore:
      - "**.[jt]sx?"
      - "**.es6"
      - "**.md"
      - "NOTICE-js"
      - "NOTICE-ruby"
      - "package.json"
      - "yarn.lock"
  pull_request:
    paths-ignore:
      - "**.[jt]sx?"
      - "**.es6"
      - "**.md"
      - "**.md"
      - "NOTICE-js"
      - "NOTICE-ruby"
      - "package.json"
      - "yarn.lock"
jobs:
  main_build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-20.04]
        node: [14.6.0]
        ruby: [2.7.2]
    steps:
      - uses: actions/checkout@v2
      - name: Setup PostgreSQL with PostgreSQL extensions and unprivileged user
        uses: Daniel-Marynicz/postgresql-action@0.1.0
        with:
          postgres_image_tag: 11-alpine
          postgres_user: houdini_user
          postgres_password: password
      - uses: actions/setup-node@v1.4.4
        with:
          node-version: ${{ matrix.node }}
      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - uses: actions/cache@v2
        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ matrix.os }}-yarn-${{ matrix.node }}-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ matrix.os }}-yarn-${{ matrix.node }}-
      - run: yarn install --frozen-lockfile
        if: steps.node-cache.outputs.cache-hit != 'true'
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ matrix.ruby }}
      - uses: actions/cache@v2
        name: Use Gem cache
        with:
          path: vendor/bundle
          key: bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/Gemfile.lock') }}
          restore-keys: |
            bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby }}-
      - name: install bess dependencies
        run: |
          cd gems/bess
          bundle install --jobs 3 --retry 3
      - name: run spec for bess
        run: |
          cd gems/bess
          bundle exec rake spec

      - run: |
          bundle config deployment true
          bundle config path vendor/bundle
          bundle install --jobs 4
      - run: bin/setup ci
      - name: rubocop
        run: bundle exec rubocop
      - name: run spec
        run: bin/rails spec