manicmaniac/ApolloDeveloperKit

View on GitHub
.github/workflows/test.yml

Summary

Maintainability
Test Coverage
---
name: Test
on:
- push
defaults:
  run:
    shell: bash
env:
  BUNDLE_JOBS: 4
  BUNDLE_PATH: vendor/bundle
  BUNDLE_RETRY: 3
  BUNDLE_WITHOUT: documentation
  CC_TEST_REPORTER_ID: "${{ secrets.CC_TEST_REPORTER_ID }}"
  CC_TEST_REPORTER_URL: https://codeclimate.com/downloads/test-reporter/test-reporter-0.6.3-linux-amd64
  DEVELOPER_DIR: "/Applications/Xcode_12.4.app/Contents/Developer"
jobs:
  prepare-test:
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/cache@v2
      id: cache-cc-test-reporter
      with:
        path: cc-test-reporter
        key: "${{ env.CC_TEST_REPORTER_URL }}"
    - name: Install dependencies
      if: steps.cache-cc-test-reporter.outputs.cache-hit != 'true'
      run: |
        curl -LSso cc-test-reporter ${{ env.CC_TEST_REPORTER_URL }}
        chmod +x cc-test-reporter
    - name: Notify before build
      run: "./cc-test-reporter before-build"
  unit-test:
    needs: prepare-test
    runs-on: macOS-10.15
    env:
      DEVELOPER_DIR: "/Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer"
      RESULT_BUNDLE_BASE: "Test-ApolloDeveloperKit-${{ matrix.apollo }}-${{ matrix.sdk }}"
    strategy:
      fail-fast: false
      matrix:
        apollo:
        - 0.37.0
        - 0.36.0
        - 0.35.0
        - 0.34.1
        platform:
        - iOS
        - macOS
        include:
        - apollo: 0.37.0
          platform: iOS
          sdk: iphonesimulator
          xcode: '12'
          destination: platform=iOS Simulator,OS=14.0,name=iPhone 11
        - apollo: 0.36.0
          platform: iOS
          sdk: iphonesimulator
          xcode: '12'
          destination: platform=iOS Simulator,OS=14.0,name=iPhone 11
        - apollo: 0.35.0
          platform: iOS
          sdk: iphonesimulator
          xcode: '12'
          destination: platform=iOS Simulator,OS=14.0,name=iPhone 11
        - apollo: 0.34.1
          platform: iOS
          sdk: iphonesimulator
          xcode: '12'
          destination: platform=iOS Simulator,OS=14.0,name=iPhone 11
        - apollo: 0.37.0
          platform: macOS
          sdk: macosx
          xcode: '12'
          destination: platform=OS X,arch=x86_64
        - apollo: 0.36.0
          platform: macOS
          sdk: macosx
          xcode: '12'
          destination: platform=OS X,arch=x86_64
        - apollo: 0.35.0
          platform: macOS
          sdk: macosx
          xcode: '12'
          destination: platform=OS X,arch=x86_64
        - apollo: 0.34.1
          platform: macOS
          sdk: macosx
          xcode: '12'
          destination: platform=OS X,arch=x86_64
    steps:
    - uses: actions/checkout@v2
    - name: Modify Cartfile.resolved
      run: sed -i '' -E '/apollographql\/apollo-ios/s/"[0-9.]+"/"${{ matrix.apollo }}"/' Cartfile.resolved
    - uses: actions/cache@v2
      id: cache-bundler
      with:
        path: vendor/bundle
        key: "${{ hashFiles('Gemfile.lock') }}"
    - name: Install Ruby dependencies
      if: steps.cache-bundler.outputs.cache-hit != 'true'
      run: bundle install
    - uses: actions/cache@v2
      id: cache-carthage-build
      with:
        path: Carthage/Build
        key: "${{ matrix.platform }}-${{ hashFiles('Cartfile.resolved') }}"
    - name: Install Carthage dependencies
      if: steps.cache-carthage-build.outputs.cache-hit != 'true'
      run: |
        carthage checkout
        ( cd Carthage/Checkouts/apollo-ios && swift package resolve ) # Workaround for Carthage's timeout error while reading xcodeproj.
        carthage build --platform '${{ matrix.platform }}' --use-xcframeworks --no-use-binaries
    - name: Run unit tests
      run: xcodebuild test -project ApolloDeveloperKit.xcodeproj -scheme ApolloDeveloperKit -sdk '${{ matrix.sdk }}' -destination '${{ matrix.destination }}' -resultBundlePath '/tmp/${{ env.RESULT_BUNDLE_BASE }}' | xcpretty
    - uses: actions/upload-artifact@v2
      if: always()
      with:
        name: ${{ env.RESULT_BUNDLE_BASE }}.xcresult
        path: /tmp/${{ env.RESULT_BUNDLE_BASE }}.xcresult
    - name: Collect coverages
      run: |
        bundle exec slather coverage -x --scheme ApolloDeveloperKit ApolloDeveloperKit.xcodeproj
        mv cobertura.xml 'cobertura-${{ matrix.apollo }}-${{ matrix.sdk }}.xml'
    - uses: actions/upload-artifact@v2
      with:
        name: coverage
        path: cobertura-${{ matrix.apollo }}-${{ matrix.sdk }}.xml
  install-test:
    runs-on: macOS-10.15
    steps:
    - uses: actions/checkout@v2
    - name: Resolve dependencies
      run: |
        make -C InstallTests Cartfile.resolved
        fgrep -v .. InstallTests/Cartfile.resolved >InstallTests/Cartfile.private
    - uses: actions/cache@v2
      with:
        path: InstallTests/Carthage/Build
        key: "${{ hashFiles('InstallTests/Cartfile.private') }}"
    - name: Run install tests
      run: make -C InstallTests carthage
  swiftpm-test:
    runs-on: macOS-10.15
    steps:
    - uses: actions/checkout@v2
    - name: Run unit tests
      run: swift test
  lint-podspec:
    runs-on: macOS-10.15
    steps:
    - uses: actions/checkout@v2
    - uses: actions/cache@v2
      id: cache-bundler
      with:
        path: vendor/bundle
        key: "${{ hashFiles('Gemfile.lock') }}"
    - name: Install Ruby dependencies
      if: steps.cache-bundler.outputs.cache-hit != 'true'
      run: bundle install
    - name: Lint podspec
      run: bundle exec pod lib lint --verbose
  frontend-test:
    needs: prepare-test
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/checkout@v2
    - name: Install dependencies
      run: npm install
    - name: Run frontend tests
      run: npm test -- --coverage
    - uses: actions/upload-artifact@v2
      with:
        name: coverage
        path: coverage/clover.xml
  frontend-rebuild:
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/checkout@v2
    - name: Install dependencies
      run: npm install
    - name: Generate types
      run: npm run generate:type
    - name: Build bundle.js
      run: npm run build
    - name: Check differences
      run: git diff --exit-code .
  report-coverages:
    needs:
    - unit-test
    - frontend-test
    runs-on: ubuntu-18.04
    steps:
    - uses: actions/checkout@v2
    - uses: actions/cache@v2
      with:
        path: cc-test-reporter
        key: "${{ env.CC_TEST_REPORTER_URL }}"
    - uses: actions/download-artifact@v2
      with:
        name: coverage
        path: coverage
    - name: Sum coverages
      run: |
        for path in coverage/cobertura-*.xml; do ./cc-test-reporter format-coverage --input-type=cobertura --output="coverage/codeclimate-$(basename "$path" .xml).json" "$path"; done
        ./cc-test-reporter format-coverage --input-type=clover --output=coverage/codeclimate-frontend.json coverage/clover.xml
        ./cc-test-reporter sum-coverage coverage/codeclimate-*.json
    - name: Upload coverages
      run: "./cc-test-reporter upload-coverage"