name: Go Unit Test

on:
  push:
    branches: [ master ]
  pull_request:
    types: [assigned, opened, synchronize, reopened]

jobs:

  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
    - name: Check out code into the Go module directory
      uses: actions/checkout@v3
      with:
        fetch-depth: 0
        submodules: 'recursive'

    - name: Set up Go 1.x
      uses: actions/setup-go@v4
      with:
        go-version: 'stable'
        cache: true

    - uses: dotnet/nbgv@master
      with:
        setAllVars: true

    - name: Test lib ssh
      run: go test -v -cover ./...
      working-directory: crypto/ssh

    - name: Test sshpiper
      run: go test -v -race -cover -tags full ./...

    - name: create release
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      if: github.ref == 'refs/heads/master'
      run: |
        gh release create -d --generate-notes v$NBGV_SimpleVersion
        gh release list | grep Draft | tail -n +3 | cut -f 1 | xargs -r -L 1 gh release delete --yes
