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

name: "Release: Make release candidate"
jobs:
  draft_release:
    name: draft release
    runs-on: ubuntu-latest
    permissions:
      packages: write
      contents: write
      pull-requests: write
    steps:

    - name: Set up QEMU
      uses: docker/setup-qemu-action@v3

    - name: Checkout repo
      uses: actions/checkout@v4
      with:
        fetch-depth: 0
# Why "fetch-depth: 0"?  To generate the release notes, we need the
# full git history.  A shallow checkout would make release notes going
# back one commit.

    - name: Login to Docker Hub
      uses: docker/login-action@v3
      with:
        username: ${{ secrets.DOCKERHUB_USERNAME }}
        password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

    - name: Login to GitHub Container Registry
      uses: docker/login-action@v3
      with:
        registry: ghcr.io
        username: ${{ github.repository_owner }}
        password: ${{ secrets.GITHUB_TOKEN }}

    - name: Set up Go
      uses: actions/setup-go@v5
      with:
        go-version: ^1.22

# Stringer is needed because .goreleaser includes "go generate ./..."
    - name: Install stringer
      run: |
        go install golang.org/x/tools/cmd/stringer@latest

    -
      id: release
      name: Goreleaser release
      uses: goreleaser/goreleaser-action@v6
      with:
        distribution: goreleaser
        version: latest
        args: release
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
