name: CI
# This workflow is triggered on pushes & pull requests
on: [push, pull_request]

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    container: karalabe/xgo-1.13.x
    env:
      PROJECT_PATH: /go/src/github.com/analogj/scrutiny
      CGO_ENABLED: 1
    steps:
      - name: Git
        run: |
          apt-get update && apt-get install -y software-properties-common
          add-apt-repository ppa:git-core/ppa && apt-get update && apt-get install -y git
          git --version
      - name: Checkout
        uses: actions/checkout@v2
      - name: Test
        run: |
          mkdir -p $(dirname "$PROJECT_PATH")
          cp -a $GITHUB_WORKSPACE $PROJECT_PATH
          cd $PROJECT_PATH

          go mod vendor
          go test -race -coverprofile=coverage.txt -covermode=atomic -v -tags "static" $(go list ./... | grep -v /vendor/)
      - name: Build Binaries
        run: |

          cd $PROJECT_PATH
          make all

      - name: Archive
        uses: actions/upload-artifact@v2
        with:
          name: binaries.zip
          path: |
            /build/scrutiny-web-linux-amd64
            /build/scrutiny-collector-metrics-linux-amd64
            /build/scrutiny-web-linux-arm64
            /build/scrutiny-collector-metrics-linux-arm64
            /build/scrutiny-web-linux-arm-5
            /build/scrutiny-collector-metrics-linux-arm-5
            /build/scrutiny-web-linux-arm-6
            /build/scrutiny-collector-metrics-linux-arm-6
            /build/scrutiny-web-linux-arm-7
            /build/scrutiny-collector-metrics-linux-arm-7
            /build/scrutiny-web-windows-4.0-amd64.exe
            /build/scrutiny-collector-metrics-windows-4.0-amd64.exe
#            /build/scrutiny-web-freebsd-amd64
#            /build/scrutiny-collector-metrics-freebsd-amd64
      - uses: codecov/codecov-action@v1
        with:
          file: ${{ env.PROJECT_PATH }}/coverage.txt
          flags: unittests
          fail_ci_if_error: false
