skyderby/skyderby

View on GitHub
.github/workflows/ci.yml

Summary

Maintainability
Test Coverage
name: CI

on:
  push:
    branches:
    - dev
    - next
  pull_request:
    branches:
    - dev
    - next

concurrency:
  group: ${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  rubocop:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Ruby 3.2.3
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.2.3
      - name: Cache gems
        uses: actions/cache@v4
        with:
          path: vendor/bundle
          key: "${{ runner.os }}-ruby-${{ hashFiles('./Gemfile.lock') }}"
          restore-keys: |
            ${{ runner.os }}-ruby-
      - name: Install gems
        run: |
          bundle config path vendor/bundle
          bundle install --jobs 4 --retry 3
      - name: Run RuboCop
        run: bundle exec rubocop --parallel

  eslint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Nodejs
        uses: actions/setup-node@v4
        with:
          node-version: 16.16.0
      - name: Cache node modules
        uses: actions/cache@v4
        with:
          path: node_modules
          key: "${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}"
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install packages
        run: yarn install
      - name: Run Eslint and Prettier
        run: yarn lint-code

  stylelint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Nodejs
        uses: actions/setup-node@v4
        with:
          node-version: 16.16.0
      - name: Cache node modules
        uses: actions/cache@v4
        with:
          path: node_modules
          key: "${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}"
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install packages
        run: yarn install
      - name: Run Stylelint
        run: yarn lint-styles

  typescript-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Nodejs
        uses: actions/setup-node@v4
        with:
          node-version: 16.16.0
      - name: Cache node modules
        uses: actions/cache@v4
        with:
          path: node_modules
          key: "${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}"
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install packages
        run: yarn install
      - name: Run TypeScript Check
        run: yarn tsc

  unit-test:
    runs-on: ubuntu-latest
    needs:
      - rubocop
      - eslint
    env:
      DATABASE_URL: postgres://skyderby:test-password@localhost/skyderby_test
      TRACK_SCANNER_URL: http://localhost:8000
      RAILS_ENV: test
    services:
      postgres:
        image: postgres:14
        env:
          POSTGRES_USER: skyderby
          POSTGRES_PASSWORD: test-password
          POSTGRES_DB: skyderby_test
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 5s
          --health-timeout 5s
          --health-retries 5
      track-scanner:
        image: skyderby/track-scanner
        ports:
          - 8000:80
    steps:
      - uses: actions/checkout@v4
      - name: Setup Ruby 3.2.3
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.2.3
      - name: Set up Nodejs
        uses: actions/setup-node@v4
        with:
          node-version: 16.16.0
      - name: Cache gems
        uses: actions/cache@v4
        with:
          path: vendor/bundle
          key: "${{ runner.os }}-ruby-${{ hashFiles('./Gemfile.lock') }}"
          restore-keys: |
            ${{ runner.os }}-ruby-
      - name: Cache node modules
        uses: actions/cache@v4
        with:
          path: node_modules
          key: "${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}"
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install libeccodes-dev
        run: sudo apt-get update && sudo apt-get install -y libeccodes-dev
      - name: Install gems
        run: |
          bundle config path vendor/bundle
          bundle install --jobs 4 --retry 3
      - name: Install packages
        run: yarn install
      - run: bundle exec rails webpacker:compile
      - run: bundle exec rails db:test:prepare
      - run: bundle exec rspec spec --tag ~type:system

  unit-test-js:
    runs-on: ubuntu-latest
    needs:
      - rubocop
      - eslint
    steps:
      - uses: actions/checkout@v4
      - name: Set up Nodejs
        uses: actions/setup-node@v4
        with:
          node-version: 16.16.0
      - name: Cache node modules
        uses: actions/cache@v4
        with:
          path: node_modules
          key: "${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}"
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install packages
        run: yarn install
      - name: Run Jest
        run: yarn test --maxWorkers=2

  system-test:
    runs-on: ubuntu-latest
    needs:
      - rubocop
      - eslint
    env:
      DATABASE_URL: postgres://skyderby:test-password@localhost/skyderby_test
      TRACK_SCANNER_URL: http://localhost:8000
      RAILS_ENV: test
      SELENIUM_HEADLESS_CHROME: 'true'
    services:
      postgres:
        image: postgres:14
        env:
          POSTGRES_USER: skyderby
          POSTGRES_PASSWORD: test-password
          POSTGRES_DB: skyderby_test
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 5s
          --health-timeout 5s
          --health-retries 5
      track-scanner:
        image: skyderby/track-scanner
        ports:
          - 8000:80
    steps:
      - uses: actions/checkout@v4
      - name: Setup Ruby 3.2.3
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.2.3
      - name: Set up Nodejs
        uses: actions/setup-node@v4
        with:
          node-version: 16.16.0
      - name: Cache gems
        uses: actions/cache@v4
        with:
          path: vendor/bundle
          key: "${{ runner.os }}-ruby-${{ hashFiles('./Gemfile.lock') }}"
          restore-keys: |
            ${{ runner.os }}-ruby-
      - name: Cache node modules
        uses: actions/cache@v4
        with:
          path: node_modules
          key: "${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}"
          restore-keys: |
            ${{ runner.os }}-yarn-
      - name: Install libeccodes-dev
        run: sudo apt-get update && sudo apt-get install -y libeccodes-dev
      - name: Install gems
        run: |
          bundle config path vendor/bundle
          bundle install --jobs 4 --retry 3
      - name: Install packages
        run: yarn install
      - run: bundle exec rails webpacker:compile
      - run: bundle exec rails db:test:prepare
      - run: bundle exec rspec spec --tag type:system
      - name: Upload Artifacts
        uses: actions/upload-artifact@v3
        if: failure()
        with:
          name: Failure screenshots
          path: tmp/capybara

  publish-docker-image:
    runs-on: ubuntu-latest
    needs:
      - unit-test
      - unit-test-js
      - system-test
    if: ${{ contains('dev next', github.ref_name) && github.event_name == 'push' }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
      - name: Cache Docker layers
        uses: actions/cache@v4
        with:
          path: /tmp/.buildx-cache
          key: "${{ runner.os }}-buildx-${{ github.sha }}"
          restore-keys: |
            ${{ runner.os }}-buildx-
      - name: Login to Github Container Registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ github.token }}
      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: .
          push: true
          tags: ghcr.io/skyderby/app:${{ (github.ref_name == 'next' && 'next') || 'latest' }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache-new
      - name: Move cache
        run: |
          rm -rf /tmp/.buildx-cache
          mv /tmp/.buildx-cache-new /tmp/.buildx-cache