on:
  push:
    branches:
      - master
  pull_request:
name: Test
jobs:
  security:
    name: Review security
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Run gosec
        uses: cedrickring/golang-action@1.6.0
        with:
          args: go get github.com/securego/gosec/cmd/gosec; (cd auth/fido2 && gosec ./...) && (cd auth/mock && gosec ./...) && (cd auth/rpc && gosec ./...) && (cd firestore && gosec ./...) && (cd http/api && gosec ./...) && (cd http/client && gosec ./...) && (cd http/server && gosec ./...) && (cd sdb && gosec ./...) && (cd service && gosec ./...) && (cd vault && gosec ./...) && (cd wormhole && gosec .) && (cd ws/api && gosec .) && (cd ws/client && gosec .) && (cd ws/server && gosec .)
  golangci-lint:
    name: Linter
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install dependencies
        run: |
          brew install keys-pub/tap/libfido2
      - name: Install golangci-lint
        run: |
          brew install golangci/tap/golangci-lint
      - name: Run golangci-lint
        run: |
          (cd auth/fido2 && golangci-lint run --timeout 10m)
          (cd auth/mock && golangci-lint run --timeout 10m)
          (cd auth/rpc && golangci-lint run --timeout 10m)
          (cd firestore && golangci-lint run --timeout 10m)
          (cd http/api && golangci-lint run --timeout 10m)
          (cd http/client && golangci-lint run --timeout 10m)
          (cd http/server && golangci-lint run --timeout 10m)
          (cd sdb && golangci-lint run --timeout 10m)
          (cd service && golangci-lint run --timeout 10m)
          (cd vault && golangci-lint run --timeout 10m)
          (cd wormhole && golangci-lint run --timeout 10m)
          (cd ws/api && golangci-lint run --timeout 10m)
          (cd ws/client && golangci-lint run --timeout 10m)
          (cd ws/server && golangci-lint run --timeout 10m)
  test:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Install dependencies (ubuntu)
        if: matrix.os == 'ubuntu-latest'
        run: |
          sudo apt install software-properties-common
          sudo apt-add-repository ppa:yubico/stable
          sudo apt update
          sudo apt install libfido2-dev
      - name: Install dependencies (macos)
        if: matrix.os == 'macos-latest'
        run: |
          brew install pkg-config
          brew install keys-pub/tap/libfido2
      - name: Install dependencies (windows)
        if: matrix.os == 'windows-latest'
        run: |
          Set-ExecutionPolicy RemoteSigned -scope CurrentUser
          Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
          scoop bucket add keys.pub https://github.com/keys-pub/scoop-bucket
          scoop install libfido2
          echo "$HOME/scoop/apps/libfido2/current" >> $GITHUB_PATH          
      - name: Install Go
        uses: actions/setup-go@v2
        with:
          go-version: "^1.15.0"
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Test
        shell: bash
        run: |
          (cd auth/fido2 && go test -v ./...)          
          (cd auth/mock && go test -v ./...)          
          (cd http/api && go test -v ./...)
          (cd http/client && go test -v ./...)
          (cd http/server && go test -v ./...)
          (cd sdb && go test -v ./...)
          (cd service && go test -v ./...)
          (cd vault && go test -v ./...)
          # (cd wormhole && go test -v ./...)
      - name: Test (macos)
        if: matrix.os == 'macos-latest'
        run: |
          (cd auth/rpc && go test -v ./...)
