name: release

on:
  push:
    tags:
      - v*.*.*

jobs:
  linux-release:
    name: Release assets for Linux
    strategy:
      matrix:
        go_version: [1.17]
    runs-on: ubuntu-latest
    steps:
      - name: Login to GitHub Container Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Set up Go ${{ matrix.go_version }} on Ubuntu
        uses: actions/setup-go@v2
        with:
          go-version: ${{ matrix.go_version }}

      - name: Install packages
        run: |
          sudo apt-get update
          sudo apt-get install sqlite3

      - name: Install aws-cli
        uses: isbang/setup-awscli@v0.1.0

      - name: Check out source code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Start databases
        run: |
          docker-compose up -d
          sleep 20s

      - name: Run tests
        run: make ci

      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v2
        with:
          distribution: goreleaser
          version: latest
          args: --config .goreleaser/linux.yml --rm-dist
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  windows-release:
    name: Release assets for Windows
    strategy:
      matrix:
        go_version: [1.17]
    runs-on: windows-latest
    steps:
      - name: Set up Go ${{ matrix.go_version }} on Windows
        uses: actions/setup-go@v2
        with:
          go-version: ${{ matrix.go_version }}

      - name: Install packages
        run: |
          choco install sqlite

      - name: Install aws-cli
        uses: isbang/setup-awscli@v0.1.0

      - name: Use LF
        run: |
          git config --global core.autocrlf false
          git config --global core.eol lf

      - name: Check out source code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Run tests
        run: |
          make ci_windows
          rm -f tbls.exe
        shell: bash

      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v2
        with:
          distribution: goreleaser
          version: latest
          args: --config .goreleaser/windows.yml --rm-dist
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
