sue445/index_shotgun

View on GitHub
.github/workflows/test.yml

Summary

Maintainability
Test Coverage
name: test

on:
  push:
    branches:
      - master
  pull_request:
    types:
      - opened
      - synchronize
      - reopened
  schedule:
    - cron: "0 20 * * 5" # JST 5:00 (Sat)

env:
  CI: "true"

jobs:
  sqlite3:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false

      matrix:
        ruby:
          - 2.3
          - 2.4
          - 2.5
          - 2.6
          - 2.7
        gemfile:
          - activerecord_5_0
          - activerecord_5_1
          - activerecord_5_2
          - activerecord_6_0
        exclude:
          # Rails 6.0 requires Ruby 2.5+
          - ruby:    2.3
            gemfile: activerecord_6_0
          - ruby:    2.4
            gemfile: activerecord_6_0

    env:
      BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
      DATABASE: sqlite3

    steps:
      - uses: actions/checkout@v2

      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ matrix.ruby }}

      - name: Cache vendor/bundle
        uses: actions/cache@v1
        id: cache_gem
        with:
          path: vendor/bundle
          key: v1-gem-${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ env.DATABASE }}-${{ github.sha }}
          restore-keys: |
            v1-gem-${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ env.DATABASE }}-
            v1-gem-${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.gemfile }}-

      - name: Install
        run: |
          set -xe
          ./ci/install.sh

      - name: Setup Code Climate Test Reporter
        uses: aktions/codeclimate-test-reporter@v1
        with:
          codeclimate-test-reporter-id: ${{ secrets.CC_TEST_REPORTER_ID }}
          command: before-build
        continue-on-error: true

      - name: Run test
        run: |
          set -xe
          ./ci/build.sh

      - name: Teardown Code Climate Test Reporter
        uses: aktions/codeclimate-test-reporter@v1
        with:
          codeclimate-test-reporter-id: ${{ secrets.CC_TEST_REPORTER_ID }}
          command: after-build
        if: always()
        continue-on-error: true

      - name: Slack Notification (not success)
        uses: homoluctus/slatify@master
        if: "! success()"
        continue-on-error: true
        with:
          job_name: ${{ format('*build* ({0}, {1}, {2})', matrix.ruby, matrix.gemfile, env.DATABASE) }}
          type: ${{ job.status }}
          icon_emoji: ":octocat:"
          url: ${{ secrets.SLACK_WEBHOOK }}
          token: ${{ secrets.GITHUB_TOKEN }}

  mysql:
    runs-on: ${{ matrix.runner }}

    strategy:
      fail-fast: false

      matrix:
        ruby:
          - 2.3
          - 2.4
          - 2.5
          - 2.6
          - 2.7
        gemfile:
          - activerecord_5_0
          - activerecord_5_1
          - activerecord_5_2
          - activerecord_6_0
        include:
          # FIXME: SEGV on Ruby 2.3 + MySQL
          # https://github.com/sue445/index_shotgun/runs/433443396?check_suite_focus=true
          - ruby: 2.3
            runner: ubuntu-16.04
          - ruby: 2.4
            runner: ubuntu-latest
          - ruby: 2.5
            runner: ubuntu-latest
          - ruby: 2.6
            runner: ubuntu-latest
          - ruby: 2.7
            runner: ubuntu-latest
        exclude:
          # Rails 6.0 requires Ruby 2.5+
          - ruby:    2.3
            gemfile: activerecord_6_0
          - ruby:    2.4
            gemfile: activerecord_6_0

    env:
      BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
      DATABASE: mysql

    services:
      mysql:
        image: mysql:8
        ports:
          - 3306
        env:
          MYSQL_ROOT_PASSWORD: root

    steps:
      - uses: actions/checkout@v2

      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ matrix.ruby }}

      - name: Cache vendor/bundle
        uses: actions/cache@v1
        id: cache_gem
        with:
          path: vendor/bundle
          key: v1-gem-${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ env.DATABASE }}-${{ github.sha }}
          restore-keys: |
            v1-gem-${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ env.DATABASE }}-
            v1-gem-${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.gemfile }}-

      - name: Install
        run: |
          set -xe
          ./ci/install.sh

      - name: Setup Code Climate Test Reporter
        uses: aktions/codeclimate-test-reporter@v1
        with:
          codeclimate-test-reporter-id: ${{ secrets.CC_TEST_REPORTER_ID }}
          command: before-build
        continue-on-error: true

      # c.f. https://github.blog/changelog/2020-02-21-github-actions-breaking-change-ubuntu-virtual-environments-will-no-longer-start-the-mysql-service-automatically/
      - run: sudo /etc/init.d/mysql start

      - name: Run test
        run: |
          set -xe
          ./ci/build.sh
        env:
          MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }}

      - name: Teardown Code Climate Test Reporter
        uses: aktions/codeclimate-test-reporter@v1
        with:
          codeclimate-test-reporter-id: ${{ secrets.CC_TEST_REPORTER_ID }}
          command: after-build
        if: always()
        continue-on-error: true

      - name: Slack Notification (not success)
        uses: homoluctus/slatify@master
        if: "! success()"
        continue-on-error: true
        with:
          job_name: ${{ format('*build* ({0}, {1}, {2})', matrix.ruby, matrix.gemfile, env.DATABASE) }}
          type: ${{ job.status }}
          icon_emoji: ":octocat:"
          url: ${{ secrets.SLACK_WEBHOOK }}
          token: ${{ secrets.GITHUB_TOKEN }}

  postgresql:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false

      matrix:
        ruby:
          - 2.3
          - 2.4
          - 2.5
          - 2.6
          - 2.7
        gemfile:
          - activerecord_5_0
          - activerecord_5_1
          - activerecord_5_2
          - activerecord_6_0
        exclude:
          # Rails 6.0 requires Ruby 2.5+
          - ruby:    2.3
            gemfile: activerecord_6_0
          - ruby:    2.4
            gemfile: activerecord_6_0

    env:
      BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
      DATABASE: postgresql

    services:
      postgresql:
        image: postgres:10-alpine
        ports:
          - 5432
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
      - uses: actions/checkout@v2

      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ matrix.ruby }}

      - name: Cache vendor/bundle
        uses: actions/cache@v1
        id: cache_gem
        with:
          path: vendor/bundle
          key: v1-gem-${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ env.DATABASE }}-${{ github.sha }}
          restore-keys: |
            v1-gem-${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ env.DATABASE }}-
            v1-gem-${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.gemfile }}-

      - name: Install
        run: |
          set -xe
          ./ci/install.sh

      - name: Setup Code Climate Test Reporter
        uses: aktions/codeclimate-test-reporter@v1
        with:
          codeclimate-test-reporter-id: ${{ secrets.CC_TEST_REPORTER_ID }}
          command: before-build
        continue-on-error: true

      - name: Run test
        run: |
          set -xe
          ./ci/build.sh
        env:
          POSTGRESQL_PORT: ${{ job.services.postgresql.ports['5432'] }}

      - name: Teardown Code Climate Test Reporter
        uses: aktions/codeclimate-test-reporter@v1
        with:
          codeclimate-test-reporter-id: ${{ secrets.CC_TEST_REPORTER_ID }}
          command: after-build
        if: always()
        continue-on-error: true

      - name: Slack Notification (not success)
        uses: homoluctus/slatify@master
        if: "! success()"
        continue-on-error: true
        with:
          job_name: ${{ format('*build* ({0}, {1}, {2})', matrix.ruby, matrix.gemfile, env.DATABASE) }}
          type: ${{ job.status }}
          icon_emoji: ":octocat:"
          url: ${{ secrets.SLACK_WEBHOOK }}
          token: ${{ secrets.GITHUB_TOKEN }}

  oracle:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false

      matrix:
        ruby:
          - 2.3
          - 2.4
          - 2.5
          - 2.6
          - 2.7
        gemfile:
          - activerecord_5_0
          - activerecord_5_1
          - activerecord_5_2
          - activerecord_6_0
        exclude:
          # Rails 6.0 requires Ruby 2.5+
          - ruby:    2.3
            gemfile: activerecord_6_0
          - ruby:    2.4
            gemfile: activerecord_6_0

    env:
      BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
      DATABASE: oracle
      LD_LIBRARY_PATH: /opt/oracle/instantclient_19_3
      NLS_LANG: AMERICAN_AMERICA.UTF8
      ORACLE_SYSTEM_PASSWORD: oracle

    services:
      oracle:
        image: deepdiver/docker-oracle-xe-11g
        ports:
          - 1521
        env:
          ORACLE_SYSTEM_PASSWORD: oracle

    steps:
      - uses: actions/checkout@v2

      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ matrix.ruby }}

      - name: Cache vendor/bundle
        uses: actions/cache@v1
        id: cache_gem
        with:
          path: vendor/bundle
          key: v1-gem-${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ env.DATABASE }}-${{ github.sha }}
          restore-keys: |
            v1-gem-${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.gemfile }}-${{ env.DATABASE }}-
            v1-gem-${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.gemfile }}-

      - name: Install
        run: |
          set -xe
          ./ci/install.sh

      - name: Setup Code Climate Test Reporter
        uses: aktions/codeclimate-test-reporter@v1
        with:
          codeclimate-test-reporter-id: ${{ secrets.CC_TEST_REPORTER_ID }}
          command: before-build
        continue-on-error: true

      - name: Run test
        run: |
          set -xe
          ./ci/build.sh
        env:
          ORACLE_PORT: ${{ job.services.oracle.ports['1521'] }}

      - name: Teardown Code Climate Test Reporter
        uses: aktions/codeclimate-test-reporter@v1
        with:
          codeclimate-test-reporter-id: ${{ secrets.CC_TEST_REPORTER_ID }}
          command: after-build
        if: always()
        continue-on-error: true

      - name: Slack Notification (not success)
        uses: homoluctus/slatify@master
        if: "! success()"
        continue-on-error: true
        with:
          job_name: ${{ format('*build* ({0}, {1}, {2})', matrix.ruby, matrix.gemfile, env.DATABASE) }}
          type: ${{ job.status }}
          icon_emoji: ":octocat:"
          url: ${{ secrets.SLACK_WEBHOOK }}
          token: ${{ secrets.GITHUB_TOKEN }}

  rubocop:
    runs-on: ubuntu-latest

    env:
      RUBY_VERSION: 2.3

    steps:
      - uses: actions/checkout@v1

      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ env.RUBY_VERSION }}

      - name: Cache vendor/bundle
        uses: actions/cache@v1
        id: cache_gem_rubocop
        with:
          path: vendor/bundle
          key: v1-gem-rubocop-${{ runner.os }}-${{ env.RUBY_VERSION }}-${{ github.sha }}
          restore-keys: |
            v1-gem-rubocop-${{ runner.os }}-${{ env.RUBY_VERSION }}-

      - name: Install
        run: |
          set -xe
          ./ci/install.sh

      - name: Run rubocop
        run: |
          set -xe
          bundle exec rubocop

      - name: Slack Notification (not success)
        uses: homoluctus/slatify@master
        if: "! success()"
        continue-on-error: true
        with:
          job_name: '*rubocop*'
          type: ${{ job.status }}
          icon_emoji: ":octocat:"
          url: ${{ secrets.SLACK_WEBHOOK }}
          token: ${{ secrets.GITHUB_TOKEN }}

  notify:
    needs:
      - sqlite3
      - mysql
      - postgresql
      - oracle
      - rubocop

    runs-on: ubuntu-latest

    steps:
      - name: Slack Notification (success)
        uses: homoluctus/slatify@master
        if: always()
        continue-on-error: true
        with:
          job_name: '*build*'
          type: ${{ job.status }}
          icon_emoji: ":octocat:"
          url: ${{ secrets.SLACK_WEBHOOK }}
          token: ${{ secrets.GITHUB_TOKEN }}