sue445/index_shotgun

View on GitHub
.github/workflows/test.yml

Summary

Maintainability
Test Coverage
name: test

on:
  push:
    branches:
      - master
    paths-ignore:
      - ".github/workflows/pages.yml"
  pull_request:
    types:
      - opened
      - synchronize
      - reopened
    paths-ignore:
      - ".github/workflows/pages.yml"
  schedule:
    - cron: "0 20 * * 5" # JST 5:00 (Sat)

jobs:
  test:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false

      matrix:
        ruby:
          - "2.4"
          - "2.5"
          - "2.6"
          - "2.7"
          - "3.0"
          - "3.1"
          - "3.2"
          - "3.3"
        gemfile:
          - activerecord_5_0
          - activerecord_5_1
          - activerecord_5_2
          - activerecord_6_0
          - activerecord_6_1
          - activerecord_7_0
          - activerecord_7_1
        database:
          - sqlite3
          - mysql
          - postgresql
          - oracle
        exclude:
          # Rails 7.0+ requires Ruby 2.7+
          - ruby:    "2.4"
            gemfile: activerecord_7_0
          - ruby:    "2.5"
            gemfile: activerecord_7_0
          - ruby:    "2.6"
            gemfile: activerecord_7_0
          - ruby:    "2.4"
            gemfile: activerecord_7_1
          - ruby:    "2.5"
            gemfile: activerecord_7_1
          - ruby:    "2.6"
            gemfile: activerecord_7_1

          # Rails 6.0+ requires Ruby 2.5+
          - ruby:    "2.4"
            gemfile: activerecord_6_0
          - ruby:    "2.4"
            gemfile: activerecord_6_1

          # Rails 5.x doesn't works on Ruby 3.0+
          - ruby:    "3.0"
            gemfile: activerecord_5_0
          - ruby:    "3.0"
            gemfile: activerecord_5_1
          - ruby:    "3.0"
            gemfile: activerecord_5_2
          - ruby:    "3.1"
            gemfile: activerecord_5_0
          - ruby:    "3.1"
            gemfile: activerecord_5_1
          - ruby:    "3.1"
            gemfile: activerecord_5_2
          - ruby:    "3.2"
            gemfile: activerecord_5_0
          - ruby:    "3.2"
            gemfile: activerecord_5_1
          - ruby:    "3.2"
            gemfile: activerecord_5_2
          - ruby:    "3.3"
            gemfile: activerecord_5_0
          - ruby:    "3.3"
            gemfile: activerecord_5_1
          - ruby:    "3.3"
            gemfile: activerecord_5_2

          # TODO: latest activerecord-oracle_enhanced-adapter doesn't support activerecord 7.1
          - database: oracle
            gemfile: activerecord_7_1

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

      # for oracle
      LD_LIBRARY_PATH: /opt/oracle/instantclient_19_3
      NLS_LANG: AMERICAN_AMERICA.UTF8
      ORACLE_SYSTEM_PASSWORD: oracle

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

      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

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

    steps:
      - uses: actions/checkout@v4

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

      - name: Cache vendor/bundle
        uses: actions/cache@v4
        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.com/actions/virtual-environments/issues/4732#issuecomment-992614476
      - run: sudo systemctl start mysql

      - name: Run test
        run: |
          set -xe
          ./ci/build.sh
        env:
          MYSQL_PORT: ${{ job.services.mysql.ports['3306'] }}
          POSTGRESQL_PORT: ${{ job.services.postgresql.ports['5432'] }}
          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: lazy-actions/slatify@master
        if: "! success()"
        continue-on-error: true
        with:
          job_name: ${{ format('*build* ({0}, {1}, {2})', matrix.ruby, matrix.gemfile, matrix.database) }}
          type: ${{ job.status }}
          icon_emoji: ":octocat:"
          url: ${{ secrets.SLACK_WEBHOOK }}
          token: ${{ secrets.GITHUB_TOKEN }}

  rubocop:
    runs-on: ubuntu-latest

    env:
      RUBY_VERSION: 2.4
      BUNDLE_WITHOUT: mysql postgresql sqlite3 oracle

    steps:
      - uses: actions/checkout@v4

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

      - name: Cache vendor/bundle
        uses: actions/cache@v4
        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: lazy-actions/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:
      - test
      - rubocop

    runs-on: ubuntu-latest

    steps:
      - name: Slack Notification (success)
        uses: lazy-actions/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 }}