name: Integration Test

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.18
      - name: Build
        run: |
         env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build main.go
         cd netclient
         env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go
         env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build main.go
         env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go
         env CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go
  linux-gui:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.18
      - name: Build
        run: |
         sudo apt-get install -y gcc libgl1-mesa-dev xorg-dev
         env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -tags=gui main.go
  mac-gui:
    runs-on: macos-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.18
      - name: Build mac
        run: |
          env CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -tags=gui main.go
  win-gui:
    runs-on: windows-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.18
      - name: Mysys2 setup
        uses: msys2/setup-msys2@v2
        with:
          install: >-
            git
            mingw-w64-x86_64-toolchain
      - name: Build win gui
        run: |
          env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -tags=gui main.go
  tests:
    env:
      DATABASE: sqlite
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup Go
        uses: actions/setup-go@v2
        with:
          go-version: 1.18
      - name: run tests
        run: |
            sudo apt-get install -y gcc libgl1-mesa-dev xorg-dev 
            go test -p 1 ./... -v
            go install honnef.co/go/tools/cmd/staticcheck@latest
            ~/go/bin/staticcheck ./...
        env:
          DATABASE: sqlite
          CLIENT_MODE: "off"
