name: Release

on:
  push:
    tags:
      - v[0-9]+.[0-9]+*

env:
  GO_VERSION: '1.20'

jobs:

  release:
    name: Create a release
    runs-on: ubuntu-latest

    steps:
      - name: Set up Go ${{ env.GO_VERSION }}
        uses: actions/setup-go@v2
        with:
          go-version: ${{ env.GO_VERSION }}

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

      - name: Cache Go modules
        uses: actions/cache@v3
        with:
          path: ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-

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