name: "CI"

on:
  push:
    branches:
      - "master"
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: elementary/docker:unstable
    steps:
      - uses: actions/checkout@v1
      - name: Install Dependencies
        run: |
          apt update
          apt install -y libarchive-dev valac meson appstream-util xvfb at-spi2-core git build-essential autoconf autoconf-archive autopoint automake pkg-config libtool m4 autoconf-archive gtk-doc-tools libxml2-utils gobject-introspection libgirepository1.0-dev libglib2.0-dev libjson-glib-dev gettext libcairo2-dev libgtk-3-dev
      - name: goocanvas-3.0 from source
        run: |
          git clone https://gitlab.gnome.org/GNOME/goocanvas
          cd goocanvas
          git checkout goocanvas-3.0
          git revert --no-commit 9103e2f
          mkdir build
          cd build
          ../autogen.sh
          ../configure --prefix /usr
          make
          make install
      - name: Build
        # env:
        #   DESTDIR: out
        run: |
          meson build
          ninja -C build
          ninja -C build install
          xvfb-run -a -s "-screen 0 1024x768x24" \
            dbus-run-session meson test -C build --no-rebuild -v --no-stdsplit --wrap catchsegv
      - name: cleanup xvfb
        run: |
          xvfb_pids=`ps aux | grep tmp/xvfb-run | grep -v grep | awk '{print $2}'`
          if [ "$xvfb_pids" != "" ]; then
            echo "Killing the following xvfb processes: $xvfb_pids"
            sudo kill $xvfb_pids
          else
            echo "No xvfb processes to kill"
          fi

  flatpak:
    name: "Flatpak"
    runs-on: ubuntu-latest
    container:
      image: bilelmoussaoui/flatpak-github-actions:elementary-juno
      options: --privileged
    steps:
      - uses: actions/checkout@v2
      - uses: bilelmoussaoui/flatpak-github-actions/flatpak-builder@master
        with:
          bundle: "akira-dev.flatpak"
          manifest-path: "build-aux/flatpak/com.github.akiraux.akira.json"
          cache-key: flatpak-builder-${{ github.sha }}
          run-tests: "true"
