name: Release

on:
  push:
    branches:
      - master

permissions:
  contents: write # to create releases and upload assets
  pull-requests: read # to read pull request titles and labels for changelog
  id-token: write # to sign the release

jobs:
  goreleaser:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          # This is required to allow GoReleaser to fetch all tags
          # to determine the next version number.
          fetch-depth: 0

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: "1.24" # Match the Go version in go.mod

      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v5
        with:
          # GoReleaser will automatically use the latest version.
          # You can specify a specific version if needed.
          version: latest
          args: release --clean
        env:
          # This token is used to create the GitHub Release and upload assets.
          # It's automatically provided by GitHub Actions.
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          # This is a personal access token with 'repo' scope, used to push
          # the updated formula to homebrew-email-cli repository.
          HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
