name: CI

on:
  push:
  pull_request:

jobs:
  
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3

    - name: Set up Go
      uses: actions/setup-go@v3
      with:
        go-version: 1.18

    - name: Run tests
      run: go test -cover -v .


  build:
    needs: test
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3

    - name: Set up Go
      uses: actions/setup-go@v3
      with:
        go-version: 1.18

    - name: Build
      run: go build -v .

    - name: Upload binary to artifacts
      uses: actions/upload-artifact@v3
      with:
        name: gordle-bin
        path: ./gordle

  release:
    if: startsWith(github.ref, 'refs/tags/')
    needs: build
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3

    - name: Download binary from artifacts
      uses: actions/download-artifact@v3
      with:
        name: gordle-bin

    - name: Release
      uses: softprops/action-gh-release@v1
      if: startsWith(github.ref, 'refs/tags/')
      with:
        files: gordle
        generate_release_notes: true

