name: Build LegendsBrowser

on:
  push:
    branches: [ master ]
    tags: [ '**' ]
  pull_request:
    branches: [ master ]
  workflow_dispatch:

jobs:

  build:
    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: cd backend && go build -v ./...

  release:
    runs-on: ubuntu-latest
    needs: [ build ]
    if: ${{ startsWith(github.ref, 'refs/tags/') }}
    steps:
      - uses: actions/checkout@v2

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

      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v2
        with:
          version: latest
          workdir: backend
          args: release --rm-dist
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}