name: Package bygfoot

on:
  push:
    tags:
      - '*'
    branches:
      - unofficial-trunk
  pull_request:

env:
  BYGFOOT_VERSION: "2.3.3-unofficial-git-${{ github.sha }}"

jobs:
  package-linux:
    runs-on:
      - ubuntu-16.04
    strategy:
      fail-fast: false
      matrix:
        build-type:
          - full
          - minimal
        include:
          - build-type: full
            extra-deps: libjson-c-dev
            build-suffix: ""
          - build-type: minimal
            extra-deps: ""
            build-suffix: -minimal

    steps:
      - name: Checkout sources
        uses: actions/checkout@v2

      - name: Install dependencies
        run: sudo apt-get install libglib2.0-dev libgtk2.0-dev libpango1.0-dev libatk1.0-dev libfreetype6-dev ninja-build

      - name: Install extra dependencies
        if: ${{ matrix.extra-deps != '' }}
        run: sudo apt-get install ${{ matrix.extra-deps }}

      - name: Package Bygfoot
        run: ./scripts/package.sh .

      - name: Upload artifact
        uses: actions/upload-artifact@v2
        with:
          name: "bygfoot-${{ env.BYGFOOT_VERSION }}-linux${{ matrix.build-suffix }}"
          path: "*.bz2"

  test-linux:
    needs:
      - package-linux
    runs-on:
      - ubuntu-16.04
    steps:
      - uses: actions/checkout@v2

      - uses: actions/download-artifact@v2
        with:
          name: "bygfoot-${{ env.BYGFOOT_VERSION }}-linux"

      - name: Unpack binary package
        run: |
          ls
          tar -xjf bygfoot-${{ env.BYGFOOT_VERSION }}.tar.bz2

      - name: Run Tests
        run: |
          bash ./test/test-load-save.sh ./bygfoot-${{ env.BYGFOOT_VERSION }}/bygfoot
          bash ./test/test-country-defs.sh ./bygfoot-${{ env.BYGFOOT_VERSION }}/bygfoot || true


  package-windows:
    runs-on:
      - windows-2016
    steps:
      - name: Checkout sources
        uses: actions/checkout@v2

      - name: Install ninja
        run: pip install ninja

      - name: Download dependencies
        run: |
          curl -O -L https://download.gnome.org/binaries/win64/gtk+/2.22/gtk+-bundle_2.22.1-20101229_win64.zip
          unzip gtk+-bundle_2.22.1-20101229_win64.zip

        shell: bash

      - name: Copy dependencies intall package directory
        shell: bash
        run: |
          mkdir -p bygfoot-$BYGFOOT_VERSION
          cp bin/*.dll bygfoot-$BYGFOOT_VERSION
          cp ./share/doc/gtk+-2.22.1/COPYING bygfoot-$BYGFOOT_VERSION/COPYING.gtk+
          cp ./share/doc/glib-2.26.1/COPYING bygfoot-$BYGFOOT_VERSION/COPYING.glib

      - name: Package Bygfoot
        env:
          CC: gcc
          CXX: g++
          PkgConfig_DIR: ./
        run: |
          export PKG_CONFIG=`pwd`/bin/pkg-config.exe
          # Add gtk+ directory to PATH so that cmake can find the correct zlib
          # library.
          export PATH=`pwd`/bin:$PATH
          ./scripts/package.sh .
        shell: bash

      - name: Upload artifact
        uses: actions/upload-artifact@v2
        with:
          name: "bygfoot-${{ env.BYGFOOT_VERSION }}-win64"
          path: "*.bz2"
