UNC-Libraries/hy-c

View on GitHub
.github/workflows/build.yml

Summary

Maintainability
Test Coverage
name: Build

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main, hyrax-4 ]

jobs:
  build:

    runs-on: ubuntu-latest

    env:
      CC_TEST_REPORTER_ID: ab9f6d96726a23c491c04cdad5cc4959551f10716196aaf2260bdf72ca1a3d0b
      ALLOW_NOTIFICATIONS: true
      CLAMD_TCP_HOST: 'localhost'
      CLAMD_TCP_PORT: '3310'
      DATABASE_AUTH: true
      DATABASE_URL: postgresql://localhost:5432
      DATACITE_PASSWORD: 'datacitepass'
      DATACITE_PREFIX: '10.5077'
      DATACITE_USER: 'test-datacite-user'
      DATACITE_USE_TEST_API: 'true'
      DATA_STORAGE: ./public
      TEMP_STORAGE: ./public
      DEFAULT_ADMIN_SET: 'default'
      DELETED_PEOPLE_FILE: ./tmp/deleted_people.txt
      DOI_PREFIX: '10.17615'
      EMAIL_FROM_ADDRESS: 'hyraxapp@example.com'
      EMAIL_GEONAMES_ERRORS_ADDRESS: 'hyraxapp@example.com'
      FEDORA_TEST_URL: http://localhost:8080/fcrepo/rest
      HYRAX_DATABASE_PASSWORD: 'password'
      HYRAX_HOST: 'https://example.com'
      NOKOGIRI_USE_SYSTEM_LIBRARIES: true
      RACK_ENV: test
      RAILS_ENV: test
      REDIS_HOST: localhost
      REDIS_URL: redis://redis
      SOLR_TEST_URL: http://127.0.0.1:8983/solr/hydra-test
      SSO_LOGIN_PATH: '/Shibboleth.sso/Login'
      SSO_LOGOUT_URL: 'https://shibboleth.example.com/idp/logout.jsp'
      IMAGE_PROCESSOR: 'graphicsmagick'
    services:
      fedora:
        image: cazzerson/fcrepo4:4.7.5
        ports:
          - 8080:8080
        env:
          CATALINA_OPTS: "-Djava.awt.headless=true -server -Xms1G -Xmx2G -XX:MaxNewSize=1G -XX:+HeapDumpOnOutOfMemoryError -Dfcrepo.modeshape.configuration=classpath:/config/file-simple/repository.json"
      redis:
        image: redis
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 6379:6379
      postgres:
        image: postgres
        env:
          POSTGRES_USER: hyrax
          POSTGRES_PASSWORD: password
        # Set health checks to wait until postgres has started
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
        ports: ["5432:5432"]
      solr:
        image: solr:8.11-slim
        ports:
          - 8983:8983
        options: >-
          --name solr_container
      clamavd:
        image: lokori/clamav-java
        ports:
          - 3310:3310
        volumes:
          - /tmp:/tmp

    strategy:
      matrix:
        ruby-version: ['2.7.4']

    steps:
    - uses: actions/checkout@v2
    - name: Set up Ruby
    # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
    # change this to (see https://github.com/ruby/setup-ruby#versioning):
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: ${{ matrix.ruby-version }}
        bundler-cache: true # runs 'bundle install' and caches installed gems automatically
    - name: Update rubygems
      run: |
        gem update --system 3.3.25
        gem install bundler:2.2.33

    # Run Rubocop as soon as gems are installed, so we fail early if there are issues
    - name: Run RuboCop
      run: bundle exec rubocop --parallel --config .rubocop.yml

    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8

    - name: Install OS packages
      run: |
        sudo apt-get update
        sudo apt-get install unzip ghostscript libpq-dev graphicsmagick libreoffice

    - name: Setup test database
      env:
        RAILS_ENV: test
        PGHOST: localhost
        PGUSER: hyrax
        # Variable needs to be PGPASSWORD so postgres cli can read it.
        # Variable is supposedly deprecated in postgres, but can't find the notice in postgres docs
        PGPASSWORD: password
      run: |
        psql -c 'create database hyrax_test with owner hyrax;'

    - name: Copy solr config into docker container
      run: docker cp solr/config solr_container:/tmp/solr_config

    - name: Create Solr core
      run: docker exec solr_container solr create -c hydra-test -d /tmp/solr_config

    - name: Run rspec tests
      run: bundle exec rspec
      env:
        REDIS_URL: redis://redis
        POSTGRES_USER: hyrax
        POSTGRES_PASSWORD: password
        TMPDIR: /tmp

    - uses: actions/upload-artifact@v2
      with:
        name: test-coverage
        path: coverage

    - uses: actions/upload-artifact@v2
      with:
        name: test-coverage-report
        path: coverage/coverage.json

    - name: Report to CodeClimate
      uses: paambaati/codeclimate-action@v3.0.0
      with:
        debug: false
        coverageLocations: |
          ${{github.workspace}}/coverage/coverage.json:simplecov