name: CI
on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main
jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        include:
          - { os: macos-11, ghc: 9.0.1, cabal: 3.6.2.0 }
          - { os: ubuntu-20.04, ghc: 9.0.1, cabal: 3.6.2.0 }
          - { os: windows-2019, ghc: 9.0.1, cabal: 3.6.2.0, ext: .exe }
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v2
      - run: mkdir artifact
      - run: mkdir artifact/${{ matrix.os }}
      - id: setup-haskell
        uses: haskell/actions/setup@v1
        with:
          ghc-version: ${{ matrix.ghc }}
          cabal-version: ${{ matrix.cabal }}
      - run: cabal configure --enable-tests --flags pedantic --jobs
      - run: cabal freeze
      - run: cat cabal.project.freeze
      - uses: actions/cache@v2
        with:
          path: ${{ steps.setup-haskell.outputs.cabal-store }}
          key: ${{ matrix.os }}-${{ matrix.ghc }}-${{ matrix.cabal }}-${{ hashFiles('cabal.project.freeze') }}
          restore-keys: |
            ${{ matrix.os }}-${{ matrix.ghc }}-${{ matrix.cabal }}-
            ${{ matrix.os }}-${{ matrix.ghc }}-
      - run: cabal build
      - run: cabal install --installdir artifact/${{ matrix.os }} --install-method copy
      - run: cabal test --test-show-details direct
      - run: cabal check
      - run: cabal sdist --output-dir artifact/${{ matrix.os }}
      - uses: svenstaro/upx-action@v2
        with:
          file: artifact/${{ matrix.os }}/brittany${{ matrix.ext }}
      - uses: actions/upload-artifact@v2
        with:
          path: artifact
          name: brittany-${{ github.sha }}