version: 2
jobs:
  build:
    docker:
    - image: ubuntu:16.04
    steps:
    - checkout
    - run:
        name: Install dependencies
        command: |
          apt-get update
          apt-get install -y cmake xvfb valac libwebkit2gtk-4.0-dev libsoup-gnome2.4-dev libgcr-3-dev libpeas-dev libsqlite3-dev libjson-glib-dev libarchive-dev intltool libxml2-utils
    - run:
        name: Build
        command: |
          mkdir _build
          cd _build
          cmake -DCMAKE_INSTALL_PREFIX=/usr ..
          make
    - run:
        name: Virtual framebuffer
        command: Xvfb :99 -screen 0 1280x1024x24
        background: true
    - run:
        name: Run unit tests
        command: |
          cd _build
          make check
    - run:
        name: Install system-wide
        command: |
          cd _build
          make install
  snap:
    docker:
    - image: cibuilds/snapcraft:stable
    steps:
    - checkout
    - run:
        name: Refresh package cache
        command: |
          apt-get update
    - run:
        name: Build snap
        command: snapcraft
  android:
    docker:
    - image: circleci/android:api-28-alpha
    environment:
    - JVM_OPTS: -Xmx3200m
    steps:
    - checkout
    - restore_cache:
        key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
    - run:
        name: Download dependencies
        command: ./gradlew androidDependencies
    - save_cache:
        key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
        paths:
        - ~/.gradle
    - run:
        name: Run unit tests
        command: ./gradlew lint test
    - store_artifacts:
        path: app/build/reports
        destination: reports
    - store_test_results:
        path: app/build/test-results

workflows:
  version: 2
  ci:
    jobs:
    - build
    - snap
    - android
